[antlr-interest] Re: Skipping grammar
pwolleba
pwolleba at yahoo.no
Tue Oct 7 10:00:59 PDT 2003
Yes that is correct, what is inside the bracket is a different
language which I at the moment don't want to write a parser for (it
is pretty complex and big). Anyway I have just come back to work, and
I am going to try out your solution Arnar, hopefully it will work!
I just want to thank the community for trying to find a solution to
my question, and I must say it came really fast!
Best regards,
Per
--- In antlr-interest at yahoogroups.com, "Arnar Birgisson"
<arnarb at o...> wrote:
> Hi..
>
> In my earlier post, I understood Per differently. I think he want's
to
> parse "method name{ <whatever> };" and just eat up <whatever>,
including
> any nested braces, and put it in a variable, completely without
lexing
> and/or parsing it. Per, is this correct?
>
> The result of all this being a tree something like this:
>
> METHOD
> |
> name-body
>
> where the body node contains anything inside the {..} as it's text.
>
> Arnar
>
> >>> Anthony.Youngman at E... 10/07/03 1:33 PM >>>
> 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 y...]
> 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/
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list