How do you specify the "beginning-of-line" in the lexer? In lex, it is "^".

Terence Parr

Here is a simple DEFINE rule that is only matched if the semantic predicate is true.

DEFINE
    :   {getColumn()==1}? "#define" ID
    ;
Semantic predicates on the left-edge of single-alternative lexical rules get hoisted into the nextToken prediction mechanism. Adding the predicate to a rule makes it so that it is not a candidate for recognition until the predicate evaluates to true. In this case, the method for DEFINE would never be entered, even if the lookahead predicted #define, if the column > 1.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact