What is a parser generator?
It is a program wich has a text file containing a description of a grammar as input. A grammar is a way to describe structure of some language. But i will not go into details because English is not my native language and there are far better explanations available on the internet.
Input file has a rather complicated syntax, and i don't have the time to explain it now :(
But looking at the example provided will get you started.
The example provided in the test subfolder of the zip file is in a file called translate-gram.lrgr and it is a grammar showing an example how to use this parser generator to create a translator from infix expressions to postfix expressions. The entire file is 75 lines long and shouldn't be to difficult to understand.
It starts with a {{ ... }} block that contains code that will be placed at the start of the generated parser file.
Afther that there are a few grammar rules.
Right side of the rule is between {{ and }}.
Nonterminal symbols are placed between < and > (without any spaces)
Terminal symbols are placed between “ and “ (no spaces)
Everything else is interpreted as D code
Be carefull when changin something not to have D-code that could be mistaken for something else. For example don't write “writefln( “hello” );” with spaces around “hello” because this is a terminal symbol. Write it together.
I use Derek Panell's great and usefull Build utillity to make things easier.
Extract the folder somewhere.
Build main.d -clean -full will compile the parser generator to main.exe
Move translate-gram.lrgr into the folder where main.exe is and run it like this:
main.exe -i translate-gram.lrgr +forseRecalc
This will generate two files:
translate-gram.lrgr.zLRtbl – a compressed parsing table used by parsing engine
translate-gram.d – D code for the parser
Build translate-gram.d -clean -full will build the example
Run the executable program with some expression as parameter
translate-gram.exe 1+sin(2)*cos(3)-1/(1+exp(1/cos(3.14159)))
and you will get the following outpu:
1 2 sin 3 cos * + 1 1 1 3.14159 cos / exp + / -
Better documentation
More examples
Nicer code (more checks)