Tuesday, December 22, 2015

Fixing Semantic LOOKAHEAD sample

Semantic LOOKAHEAD sample incorrectly states that the BC() choice must be made only when the next token is a "c", and the token following that is not a "c".  It actually should say that the BC() choice must be made only when the next token and the following tokens are “c”. To make the sample work the production should look like this:

void BC() :
{}
{
  "b"
  [ LOOKAHEAD( { getToken(1).kind == C && getToken(2).kind == C } )
    <C:"c">
  ]
}

The semantic lookahead is not really required here; the production can be simplified by using syntactic lookahead:

void BC() :
{}
{
  "b" [ LOOKAHEAD( "c" "c" ) "c" ]
}

No comments:

Post a Comment