[antlr-interest] help regarding string templates
atif azad
atif.azad at hotmail.com
Wed Sep 5 04:27:46 PDT 2007
Hi everyone
I am student new to antlr. Can any one please tell me how I can I use the
sting template , so that i dont have to use the print commands in my
grammer. I just have to print the operation code and operand for an assembly
language. I would be greatful.
The garmmer is as follows
grammar assemb;
program
: (stat)+
;
stat : t1=OPCODE operands { System.out.println("Found numeric:
"+t1.getText()); };
OPCODE :
'add'
|'store'
|'load'
|'call'
|'ret'
;
operands:
r9=REGISTER SEMI { System.out.println("Found numeric: "+r9.getText()); }
| r1=REGISTER COMMA r2=REGISTER SEMI { System.out.println("Found
numeric: "+r1.getText()); }
;
REGISTER :
'r1'
|'r2'
|'r3'
|'r4' ;
NUM : '[0-9]+' ;
ID : '[a-zA-Z]+' ;
WS
: (
| (' ' | '\t'| '\n')
) { $channel=HIDDEN; }
;
SEMI:
';'
;
COMMA:
','
;
Regards
Azad , Atif
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
More information about the antlr-interest
mailing list