in reply to Parse::RecDescent and grammar specification

A recursive descent parser, as I understand it, doesn't match the longest token first, it matches the first possibility first.

In this case, with simple lines composed of only one literal apiece, you'll either have to specify the longest token first, or rewrite the grammar slightly:

main: /^\s*\Z/ | input_line | <error> EOL: /\s*\Z/ input_line: opcode_8031 | <error> # # The opcode code list. Reverse these two to fix, or RET/RETI orderi +ng to break. # opcode_8031: opcode_ret EOL | opcode_reti EOL opcode_ret: OP_RET { print "Got ret!\n" } opcode_reti: OP_RETI { print "Got reti!\n" } # # 8031 opcodes # OP_RET: 'ret' OP_RETI: 'reti'
The important change is that EOL moves from input_line to the opcode_8031 production. The code blocks in there are for debugging purposes, to make sure what I thought would match does.

Half the trick in a grammar is figuring out where to put the blank spaces. Especially the ones that aren't really blank.