views:

43

answers:

1

I am testing the grammar from P::RD tutorial in order to develop my own grammar. I haven't figured out how to print a string declaration and append '$' to the front of it. For example "STRING sDir" should print out "$sDir". It is simple enough to just do a $string =~ s/STRING /\$/, but what about the case where there is assignment? eg. "STRING sDir = aNewDir".

Here is the grammar

OP       : m([-+*/%])      # Mathematical operators
INTEGER  : /[-+]?\d+/      # Signed integers
VARIABLE : /\w[a-z0-9_]*/i # Variable
STRING   : /STRING/i       # String declaration

expression : INTEGER OP expression
          { return main::expression(@item) }
          | VARIABLE OP expression
          { return main::expression(@item) }
          | INTEGER
          | VARIABLE
          { return $main::VARIABLE{$item{VARIABLE}} }

I am starting to think that regex will suffice, but want to know how to create a complex one for comma separated declarations such as "STRING, foo, bar" -> $foo; $bar;

+1  A: 
Axeman
I understand how the engine works already. My question is: Just like a print_instruction prints an expression using the print command in the action, how can I print a STRING expression with a '$' in front?
Speedyshady
Well it works. I actually tried something similar awhile ago, but maybe I wasn't calling the subrule in a rule. Thanks
Speedyshady