in reply to Re: Parsing and Translation pt.2
in thread Parsing and Translation pt.2
I don't want to post the entire code because it is unnecessary. In fact I don't have any problems with the parser I have written. The grammar works fine and my evals all return what I have asked them to. All I want to know/do is read in a file and parse it. I'm having trouble understanding if this is in fact how Parse::RecDescent could potentially be used.
Here is part of the code:use strict; use warnings; use Parse::RecDescent; $::RD_ERRORS = 1; $::RD_WARN = 1; $::RD_HINT = 1; my $grammar = q{ identifier : /[a-z]\w+/ binops : '+' | '-' | '/' | '*' | '%' | '**' lbinops: '!' | '<' | '>' | '>='| '<='| '&&'| '||' | '==' integer: /-\d+/ {print "hello $item[-1]" if $::debugging;} number : /(\d+|\d*\.\d+)/ {print "hello $item[-1]" if $::debuggin +g;} }; #evals: these will evaluate to "1" and print #print "valid number\n" if $parser->number(2); #print "valid integer\n" if $parser->integer(-2);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Parsing and Translation pt.2 (Parse::RecDescent)
by toolic (Bishop) on Aug 07, 2010 at 01:21 UTC | |
|
Re^3: Parsing and Translation pt.2
by ikegami (Patriarch) on Aug 09, 2010 at 16:45 UTC |