Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

No Format
grammar Pred;

prog: stat+ ;

stat: keyIF expr stat
    | keyCALL ID ';'
    | ';'
    ;

expr: ID
    ;

keyIF : {input.LT(1).getText().equals("if")}? ID ;

keyCALL : {input.LT(1).getText().equals("call")}? ID ;

ID : 'a'..'z'+ ;
WS : (' '|'\n')+ {$channel=HIDDEN;} ;

You can make those semantic predicates more efficient by intern'ing those strings so that you can do integer comparisons instead of string compares.

The other alternative is to do something like this

...