[antlr-interest] Print the actual code after building AST.
Meena Moktali
mmoktali at bphx.dk
Mon Mar 28 05:33:02 PST 2005
hi,
I have built a tree parser for a sample code.Thanks for your suggestions Bryan ,I have corrected the mistakes.I want to print the code after adding actions to it.
As shown in my parser class ,I am indenting the 'map statements' .Now I want to print the resultant code.
How do i do it?I saw the java.g ...but it does not print the whole inputstream after parsing.
The parser and tree walker are as shown below.
class MParser extends Parser;
options {
buildAST=true;
k=2;
}
block : (statement)* ;
statement: "if"^ expr (statement)+
("else" statement)?
"endif"
| m:"map"^ vfield "to" vfield {m.setColumn(m.getColumn()+2);} .....will I achieve indentation with this??
;
expr : vfield(COMPARE^ vfield)*;
vfield : IDENT(("in"|"of") IDENT)*;
class MTree extends TreeParser;
block : (statement)* ;
statement : #("if" expr (statement)+ ("else" statement)? "endif")|#("map" vfld "to" vfld);
expr : #(COMPARE vfld vfld);
vfld : IDENT(("in"|"of") IDENT)*;
class MLexer extends Lexer;
options { k=2;
testLiterals=true;
}
COMPARE : ('='|'<'|'>');
IDENT : ('a'..'z'|'A'..'Z'|'0'..'9'|'\''|'_')*;
WS : (' '
| '\r''\n'
| '\t'
| '\n'
| '\r')
{ _ttype = Token.SKIP; }
;
-------------------------------------------------------------------------------------------------------------
Sample code is as follows:
if PSTG_ISO4217_VAL of CURRENCY_EXCHANGE of ACCTG_TRANS_PD_WD
of ACCTG_TRANS_PD_W
= SUCCESS in STD_RTRN_CD
map CURRENCY_SPACE in KSPS4_MSG
to TEXT_CODE of STD_MSG_PARM_V of STD_MSG_CLIENT_SRV_I
map 'CURRENCY_EXCHANGE'
to VIEW_LONG_NAME of STD_MSG_CLIENT_SRV_I
map BUSINESS_ERROR in STD_RTRN_CD
to L_RTRN_CD
map 'PSTG_ISO4217_VAL'
to FIELD_LONG_NAME of STD_MSG_CLIENT_SRV_I
map 'AO6IMF'
to MESSAGE_SET_NAME of STD_MSG_PARM_V of STD_MSG_CLIENT_SRV_I
map CURRENCY_SPACE in KSPS4_MSG
to TEXT_CODE of STD_MSG_PARM_V of STD_MSG_CLIENT_SRV_I
else
map CURRENCY_SPACE in KSPS4_MSG
to TEXT_CODE of STD_MSG_PARM_V of STD_MSG_CLIENT_SRV_I
endif
Thanks,
Meena.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050328/6d7f7a33/attachment.html
More information about the antlr-interest
mailing list