lemonre2c

Is there a good working tutorial on re2c + lemon?


I've tried a couple. And there is only a couple of tutorials in Google for re2c+lemon.
Currently for all examples I get similar bunch of errors like:

In file included from main.cpp:2:0:
parser.y:44:5: error: ‘yygotominor’ was not declared in this scope
     A.int_value = B.int_value * C.int_value;
     ^
In file included from main.cpp:2:0:
parser.c:770:16: error: ‘YY_MAX_SHIFTREDUCE’ was not declared in this scope
   if( yyact <= YY_MAX_SHIFTREDUCE ){
                ^
parser.c:771:15: error: ‘YY_MAX_SHIFT’ was not declared in this scope
     if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
               ^

Where is it declared?

PS: don't post 10y old articles (even without code or if the code can't be compiled now). If you can - write an example here. If not - don't post links from Google.


Solution

  • This tutorial works for me:

    1. Get re2c (see re2c install page for details http://re2c.org/install/install.html).

    2. Get lemon: download tarball wget http://prdownloads.sourceforge.net/souptonuts/lemon_examples.tar.gz, extract and build (I had to add #include <stdlib.h> to many examples for malloc).

    3. Clone github repo https://github.com/tokuhirom/re2c-lemon-tutorial : git clone https://github.com/tokuhirom/re2c-lemon-tutorial.git

    4. Patch re2c-lemon-tutorial/Makefile to find lemon and re2c (if needed).

    5. make, ./mycalc and enjoy (hit Ctrl+D to stop and emit result).

    More re2c examples on re2c website: http://re2c.org, more lemon examples inside of lemon tarball.