Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How to find matching pairs

by ajwans (Scribe)
on Mar 12, 2002 at 02:18 UTC ( [id://151030]=note: print w/replies, xml ) Need Help??


in reply to How to find matching pairs

This kind of thing cannot be specified by regular expressions except in the trivial case where you only have one pair of brackets. In order to properly specify and parse complex expressions you could use Damian Conway's excellent Parse::RecDescent.

Using this you can specify your input as a context free grammar. Your grammar would probably be something like

start: expression expression: expression m/[+-/*]/ expression '(' expression ')' function '(' expression ')' identifier number


There is an excellent FAQ on Parse::RecDescent available on the web.

1. dude, what does mine say?
2. "sweet", what about mine?
3. "dude", what does mine say?
4. GOTO 2

Replies are listed 'Best First'.
Re: Re: How to find matching pairs
by Anonymous Monk on Mar 12, 2002 at 05:31 UTC
    You can actually, since Perl's regexes can evaluate code and interpolate patterns at regex run-time. This enables recursive regexes, see the perlre manpage for an example.

    Cheers,
    -Anomo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://151030]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-29 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found