lr-lalr parser generator

Introduction

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

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.

Example

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.

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.

Compiling the parser generator and the example

I use Derek Panell's great and usefull Build utillity to make things easier.

  1. Extract the folder somewhere.

  2. Build main.d -clean -full will compile the parser generator to main.exe

  3. Move translate-gram.lrgr into the folder where main.exe is and run it like this:

  4. main.exe -i translate-gram.lrgr +forseRecalc

  5. This will generate two files:

  6. Build translate-gram.d -clean -full will build the example

  7. Run the executable program with some expression as parameter

The Future