Possible to get more descriptive rule names than T__1, T__2, ...?

17 views
Skip to first unread message

Matti Viljamaa

unread,
May 5, 2017, 1:56:59 PM5/5/17
to antlr-discussion
So my generated parser gives me the following kind of rules:

EOF = Token.EOF
T__0=1
T__1=2
T__2=3
T__3=4
T__4=5
T__5=6
T__6=7
T__7=8
T__8=9
T__9=10
T__10=11
T__11=12
T__12=13
T__13=14
T__14=15
T__15=16
T__16=17
T__17=18
T__18=19
T__19=20
T__20=21
T__21=22
T__22=23
T__23=24
T__24=25
T__25=26
T__26=27
T__27=28
T__28=29
T__29=30
T__30=31
T__31=32
T__32=33
T__33=34
T__34=35
T__35=36
T__36=37
T__37=38
TYPE=39
ID=40
Integer=41
String=42
WS=43
NL=44

Is there any way to make these T__n rules more informative. I have no idea which one is which.

Matti Viljamaa

unread,
May 6, 2017, 9:38:42 AM5/6/17
to antlr-di...@googlegroups.com
Yes there is and that's by defining explicit token names.

E.g. if one has the rule

myrule : expr ' abcd ' expr;

Then ' abcd ' is given an implicit token name T__somenumber.

However, if one additionally creates the rule:

ABCDTK: ' abcd '

Then of course this will be matched by the grammar, when ' abcd ' is matched and thus ' abcd ' is given the token name ABCDTK.
This is called explicit definition of token names.
Reply all
Reply to author
Forward
0 new messages