[antlr-interest] Nested Matching Parenthesis
Matt Benson
gudnabrsam at yahoo.com
Wed May 28 09:35:55 PDT 2003
Not that I know anything but I think the approach you
were taking is the "ANTLR way to do it." I think your
expr rule would be recursive, though:
> expr : PATTERN
> | OPEN_PAREN expr CLOSE_PAREN
> ;
But again, what do I know?
-Matt
--- cgodfrey86 <cgodfrey at epnet.com> wrote:
> Hello,
>
> I'm trying to write a parser grammar that will check
> for matching
> parenthesis. There can be any number of parenthesis,
> but they must
> match
>
> So,
> (test) or
> ((test)) or
> (((test))) are all valid expressions
>
> (test or
> ((test
> etc are all invalid
>
> So, I have a rule like this
>
> expr : PATTERN
> | OPEN_PAREN PATTERN CLOSE_PAREN
> ;
>
> Would it make sense to write rules which count the
> number of
> consecutive open parens and close parens and check
> for matches? or is
> there an easier way to approach this that I am
> missing?
>
> start_parens : (OPEN_PAREN)+;
> end_parens : (CLOSE_PARENS)+;
>
> Thanks In Advance
>
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list