[antlr-interest] Re: Skipping grammar

Ric Klaren klaren at cs.utwente.nl
Wed Oct 8 04:25:43 PDT 2003


On Wed, Oct 08, 2003 at 10:36:02AM -0000, pwolleba wrote:
> Packet name{
> Model name {
> Method{
> 	Expressiontext;
> 	If/else and so on
> };
> };
> };
> 
> As you can see the method is build up much like a method in both C++ 
> or Java. What makes it difficult is the fact that I don't want to 
> parse the method body text, I just want to consume it.
> 
> As you can see my Lex wont work, since it will react at both the 
> Packet bracket as well as Model bracket. If I somehow could just make 
> it start when it is a method I would be really happy.

Dropping in a bit... So if I understand correctly you want to ignore or
just store the contents of the method { .. } block?

Basically you need to do tokenstream multiplexing to do this. Basically you
have one outer lexer that recognizes the bits you want to deal with then
when you encounter the "method {" bit you switch to another (inner) lexer
that only counts braces (and maybe keeps track of comments). That lexer you
can use to just throw away the contents or to store it elsewhere. When the
inner lexer sees the last brace it tells the multiplexer object to switch
back to the outer lexer which continues where the inner lexer finished.

Something you don't want to try ever is to steer this process from the
parser (saw a remark about something like that somewhere in the thread)
this will always fail in the general case.

Have a look at the multiLexer example to see how this is done. Also check
the archive from the list for tokenstream multiplexing and the docs on it.

You will most likely fail if you try to do this from the parser side
(unless you implement the language inside the method as well).

HTH,

Ric
-- 
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
     "Never argue with an idiot, for they will bring you down to their
              level and beat you with experience." --- Unknown


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list