Semantic Predicate / Guard Function

Card Puncher Data Processing

About

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

Example

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

Python

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

where:

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

Usage

  • 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