[antlr-interest] Troubleshooting the Token Rewrite

Cameron Palmer cameron.palmer at gmail.com
Thu Jul 19 03:16:30 PDT 2007


I have a token slipping through that should have be rewritten.

In the following input:
version 2.0.0
.data
.end
code main
        putr1 main.1
        forkep r1
        stop

Translates to:
-1 "2.0.0" ; version 2.0.0
-5 ; .data
code   -2 1024 ; code 1024
178 1036 ; putr1 1036
61 0 1 ; forkep 0 1
62 0 ; stop

The word code at the beginning of line 3 shouldn't be there.
Considering it was rewritten like this and CODE is an imaginary token:
codeBlock
        : 'code' a=codeLabel {
                if (labels.get($a.text) == null)
                        labels.put($a.text, new Integer(address));
        } EOL codeEl -> ^(CODE codeLabel codeEl)
        ;

codeLabel
        : ID
        ;

cameron palmer.


More information about the antlr-interest mailing list