[antlr-interest] Skipping grammar
Arnar Birgisson
arnarb at oddi.is
Tue Oct 7 02:47:29 PDT 2003
I'm sorry, this obviously doesn't work. Change
if (++i > 0)
to
if (i++ > 0)
and it should.
Arnar
> -----Original Message-----
> From: Arnar Birgisson [mailto:arnarb at oddi.is]
> Sent: 7. október 2003 09:44
> To: antlr-interest at yahoogroups.com
> Subject: RE: [antlr-interest] Skipping grammar
>
>
> I haven't tried this, but you could have this in your lexer:
>
> class MyLexer extends Lexer
>
> tokens {
> INNER_LCURLY, INNER_RCURLY;
> }
>
> {
> private int nestingLevel = 0;
> }
>
> LCURLY
> : '{' { if (++i > 0) $setType(INNER_LCURLY); }
> ;
>
> RCURLY
> : '}' { if (i > 0) { i--; $setType(INNER_RCURLY); }
> ;
>
> which gives the parser seperate tokens for inner and outer
> curly-braces.
> This allows you to do this in the Parser
>
> method
> : "method" mName LCURLY ( ~RCURLY )* RCURLY
> ;
>
> Arnar
>
> > -----Original Message-----
> > From: pwolleba [mailto:pwolleba at yahoo.no]
> > Sent: 7. október 2003 07:19
> > To: antlr-interest at yahoogroups.com
> > Subject: [antlr-interest] Skipping grammar
> >
> >
> > I am pretty new to ANTLR so maybe this question is very trivial, if
> > so even better then maybe it is a simple solution to my problem.
> > Anyway I am struggling with writing a new parser in ANTLR
> to replace
> > and old implementation in Flex/Bison, this to make a
> product that are
> > open for implementation from both C++ as well as Java.
> >
> > The parser will parse a language that we are using to build
> > databases, and it must support this language 100% if to be
> accepted.
> >
> > Here is the code cutting that I am struggling with.
> >
> > method name{
> > SomeText!()text[];
> > if(a < b && b < c){
> > SomeText()!()[];
> > }
> > else{
> > SomeText()!()[];
> > };
> > };
> >
> > I am not interesting in the expression that is inside the name
> > method, I just want ANTLR to grab the text for me, and put it as a
> > node inside the tree. The problem is the fact that the if/else
> > statement is ending with a "};" which is the same token as
> the method
> > end token, and I have no guarantee that there could be more
> that one
> > inside the method. A solution would be to make a counter that will
> > increase for each "{" and decrease for each "}", then I would know
> > when the method ends. To my frustration I don't know how I should
> > make such a counter in ANTRL, that still supports implement in both
> > Java or C++ code.
> > I would be really really happy if someone could help me with this
> > problem!
> >
> > Best reagards,
> >
> > Per
> >
> >
> >
> >
> >
> > Your use of Yahoo! Groups is subject to
> > http://docs.yahoo.com/info/terms/
> >
> >
>
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list