Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Parse::RecDescent for simple syntax-directed translation

by tomazos (Deacon)
on Jun 18, 2006 at 18:17 UTC ( [id://556134]=note: print w/replies, xml ) Need Help??


in reply to Re: Parse::RecDescent for simple syntax-directed translation
in thread Parse::RecDescent for simple syntax-directed translation

Thanks for answering my question. The regex solution is cool.

I should have qualified my statement by saying that standard regular grammars cannot handle this sort of pattern, whereas Perl's regexes can do everything and anything.

In fact embedded actions within a Perl regex can do anything Perl can do - Therefore Perl regex's can do anything Perl can do. :)

I guess I can see from your use of Parse::RecDescent, Update: And from re-reading the very long manual last night, that the answer to my question is something like:

my $grammar = q{ match : part(s) { print join('', @{$item[1]}) } part : AnB part : 'a' part : /[^a]+/ AnB : 'a' AnB 'b' { 'c' . $item[2] . 'd' } AnB : 'ab' { 'cd' } }

-Andrew.

Replies are listed 'Best First'.
Re^3: Parse::RecDescent for simple syntax-directed translation
by ikegami (Patriarch) on Jun 20, 2006 at 23:52 UTC

    Close. Your grammar strips out all whitespace. Replace
    match : part(s) { print join('', @{$item[1]}) }
    with
    match : <skip:''> part(s) { print join('', @{$item[2]}) }

    A slight improvement is to replace
    match : <skip:''> part(s) { print join('', @{$item[2]}) }
    with
    process : <skip:''> part(s) { join('', @{$item[2]}) }
    so you can do
    $filter = Parse::RecDescent->new($grammar);
    print $filter->process('eeeeaaaabbbeeee');

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-19 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found