Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Current »

This grammar allows "if if call call;" and "call if;".

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

identifier : KEY1 | KEY2 | ... | ID ;

which is a set comparison and should be faster.

  • No labels