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;