📄 t021hoist.g
字号:
/** Demonstrates how semantic predicates get hoisted out of the rule in * which they are found and used in other decisions. This grammar illustrates * how predicates can be used to distinguish between enum as a keyword and * an ID *dynamically*. :) * Run "java org.antlr.Tool -dfa t.g" to generate DOT (graphviz) files. See * the T_dec-1.dot file to see the predicates in action. */grammar t021hoist;options { language=Python;}/* With this true, enum is seen as a keyword. False, it's an identifier */@parser::init {self.enableEnum = False}stat returns [enumIs] : identifier {enumIs = "ID"} | enumAsKeyword {enumIs = "keyword"} ;identifier : ID | enumAsID ;enumAsKeyword : {self.enableEnum}? 'enum' ;enumAsID : {not self.enableEnum}? 'enum' ;ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;INT : ('0'..'9')+ ;WS : ( ' ' | '\t' | '\r' | '\n' )+ {$channel=HIDDEN} ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -