I need to write a simple parser to a sort of Domain Specific Language.
It needs to have basic arithmatics with proper operators evaluation order and a syntax to call functions of the underlying environment which can be overloaded.
What is the simplest way to write such a parser? Is there something I can adapt or use out of the box? I'm writing in C++.
Writing parsers can be challenging. The problem is simple to describe: convert an input string into a syntax tree. The same language can be parsed by many different algorithms, and all have different tradeoffs with regards to speed, memory usage, readability, and maintainability.
The basic workflow of a parser generator tool is quite simple: you write a grammar that defines the language, or document, and you run the tool to generate a parser usable from your Python code.
An LL(0) parser would mean that the parser could make a decision without knowing the next token in the stream. I would expect that if languages with that property exist, they're pretty darn rare. An LL(0) parser works on a grammar in which there are no decisions to make.
Take a look at Boost Spirit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With