[antlr-interest] nested blocks of code problem
Bartlomiej Laczkowski
p05bl at astec.com.pl
Sun Jul 9 23:53:39 PDT 2006
Hello!
I have a little problems with parsing nested blocks of code. First I
will introduce on what the problem is based on.
I need to parse blocks of codes with greedy rules to omit the single
tokens inside the body but not other blocks of code. The most important
thing is to find start keyword of block and the ending keyword, so rule
can look like this:
someBlock
:
START_KEYWORD
(
(someBlock) => someBlock
|
(.) => (options {greedy = false} : .*)
)
END_KEYWORD
;
So if we have situation like this:
start_1
some, some,
start_2
some
end_2
end_1
then everythung will works properly, but if we won't give the end_2 of
block the greeder will eat the end_1 of outer block of code and other
blocks.
In my project I need to find the ending of first block even when the
programmer forgets about ending other inner blocks of code. So I wanted
to pass some arguments from outer block to rule someBlock, which would
tells me in which outer blocks parsing was started so I can stop the
greeder when I will
get the END_KEYWORD of outer block.:
someBlock[in_which_block_ending] returns[end]
:
START_KEYWORD
(
(someBlock) => end = someBlock[in_which_block_ending]
|
(.) => (options {greedy = false} : .*)
)
END_KEYWORD | (if possible???) in_which_block_ending
;
As for now i found it not possible, because i can only pass arguments
like Tokens or Java variables, but i can not pass the things like rules
from lexer like END_KEYWORD2 or something like that. Is it possible to
make something like this? Or maybe there is some other simple way to
make this problem clear?
--
Bart?omiej ?a;czkowski
Software Developer
*ASTEC Sp. z o.o.
*ul. Piaskowa 14, PL 65-209 Zielona Góra
Tel: +48(0) 68 32 980 00
Fax: +48(0) 68 32 980 03
B.Laczkowski at astec.com.pl
www.astec.com.pl
www.gis.astec.com.pl
www.mdt-project.com
www.dict.pl
www.dep.pl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060710/a076a39d/attachment.html
More information about the antlr-interest
mailing list