Lemon and RE2c

Lemon is different than Bison

First things first

No embedded semantic actions

Attributes

vardecl ::= VAR IDENTIFIER(ID_NAME) EQUALS expression.
{
  avl->add(avl,ID_NAME,"");
} 

Attribute type declarations

%type   IDENTIFIER      {char *}

So, what if I need an embedded semantic action?

So, what if I need an embedded semantic action?

if_stmt ::= IF expr stmt_blk ELSE stmt_blk.

So, what if I need an embedded semantic action?

So, what if I need an embedded semantic action?

if_stmt ::= if expr stmt_blk ELSE stmt_blk.
if(JUMP_LABELS) ::= IF.
{
 // create two jump labels for the two cases
 JUMP_LABELS = create_two_jump_labels();
}

Handy debugging feature of Lemon

You can have the parser emit very useful information about the state of the parse by simply calling the function ParseTrace()

  ParseTrace(stderr, "PARSER SAYS: ");

Ending it all

  Parser(Parser,0,0);

RE2C

RE2C

RE2C, your code

    /*!re2c

      re2c:define:YYCTYPE = "char";
      re2c:define:YYLIMIT = last_char;
      re2c:define:YYCURSOR = current_char;

      [ ... ]

      "," { return(","); }

    */

RE2C, after being rewritten

#line 120 "lexer.c"
    {
        char yych;

        yych = *current_char;
        switch (yych) {
        case ',':   goto yy2;