Semantic Predicate / Guard Function

Card Puncher Data Processing


Semantic Predicate are boolean expressions that enable or disable the rule that follows.

They are written in the target language making the grammar language dependent


RegularExpressionLiteral : {isRegexPossible()}? '/' RegularExpressionBody '/' RegularExpressionFlags ;


TEXT : {self._input.LA(-1) == ord('[')}? ~[\])]+ ;


  • self._input.LA(-1) get the character before the current one


  • support different versions of the same language

Documentation / Reference

Discover More
Card Puncher Data Processing
Antlr - (Lexical) Rule

in Antlr. Antlr has two types of rule: Name Case Type Description Example from the getting started uppercase letter lexer rule (known as Token name, they defines the token that the lexer...

Share this page:
Follow us:
Task Runner