[antlr-interest] embedding Java codes to grammar problem
Panayiotis
panayk at gmail.com
Mon Jun 4 06:26:14 PDT 2007
Fırat KÜÇÜK wrote:
> no this is not what i want.
>
> i want to embed while statement to generated java code.
> i know what do "?+*" characters mean :)
>
Sorry, I misunderstood your level of familiarity with EBNF syntax :-)
> { while (true) { }
> tree_parser_rule
> { } }
>
Well the most generic rule I can think of is:
rule
: some_subrules_and_actions ({conditional}? {action1;} subrule
{action2;})* some_more_subrules_and_actions
;
This should:
parse_some_subrules_and_execute_some_actions;
while (conditional) {
execute_action_1;
parse_subrule;
execute_action_2;
}
parse_some_more_subrules_and_execute_some_more_actions.
And of course 'conditional', 'action1' and 'action2' can include just
about any valid Java code you like, including while-loops.
Hope this helps,
Panayiotis
More information about the antlr-interest
mailing list