[antlr-interest] Nested Matching Parenthesis

cgodfrey86 cgodfrey at epnet.com
Wed May 28 09:28:54 PDT 2003


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/ 




More information about the antlr-interest mailing list