开发者

How to interpret custom scripting language?

开发者 https://www.devze.com 2023-01-24 10:45 出处:网络
I was wondering what the easiest way to parse/interpret a custom language would be. Are there any libraries that could help me out?

I was wondering what the easiest way to parse/interpret a custom language would be. Are there any libraries that could help me out?

I essentially want the end-user to be able to write scripts using a custom syntax that I design (the syntax will probably be similar to c++) and I would need my C++ protogram to interpret the script, much like how there is a C++ library for 开发者_运维技巧parsing LUA.

Are there any libraries/examples to help me, or will I just have to do manual tokenizing, parsing and interpreting?


There are numerous frameworks to help, but remember that language design is not to be taken lightly - are you sure you're not better off just using Lua?

  • Boost-Spirit
  • ANTLR (in Java, but produces code for other languages)
  • Flex, Bison, Lemon


Use tools like Lex and Yacc to generate a scanner/parser for you


For defining your own parser, take a look at Boost Spirit.

But the practical way is to use an existing language that's been widely used for such things. E.g. JavaScript. Then Google's JavaScript binding is reportedly excellent.

Googling "Google's JavaScript binding" served up, as second hit, a link to Wikipedia's article on V8.

Cheers & hth.,

0

精彩评论

暂无评论...
验证码 换一张
取 消