use Parse::RecDescent; $new_grammar = q { # perl int is limited to 32 bits { my Instruction_upper; my Instruction_lower; } program_body : instruction(s) instruction : { Instruction_upper = 0; Instruction_lower = 0; } | nop_cmd | repeat_cmd # the nop cmd command nop_cmd : nop ';' { Instruction_upper = 0; Instruction_lower = 0; } # the repeat command repeat_cmd : repeat '=' hexnum ';' { Instruction_upper = 0; Instruction_lower = (0x7c000000 | ($item[3] & 0x0FFFF) ); nop : "nop" }