[antlr-interest] Skipping grammar

Anthony W Youngman Anthony.Youngman at ECA-International.com
Tue Oct 7 06:33:08 PDT 2003


I think you're missing the point. Define a ; as SEMI. The way I'd do it
(and this is all pseudocode) is

if_statement: "IF" lcurly (method)* rcurly "ELSE" lcurly (method)*
rcurly SEMI ;
method: blah_blah SEMI ;

That way, the lexer doesn't care whether ; is ending a method or an if
clause, and the parser won't get confused because when it hits a
right-curly it will be expecting an ELSE or a SEMI, and not a method.
And if the ELSE is optional you just mark it as such so when the parser
hits the right-curly after the if, it's expecting an ELSE or a SEMI and
nothing else.

Cheers,
Wol

-----Original Message-----
From: pwolleba [mailto:pwolleba at yahoo.no] 
Sent: 07 October 2003 08: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/ 





***********************************************************************************

This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.

***********************************************************************************


 

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




More information about the antlr-interest mailing list