use Parse::RecDescent; use strict; use warnings; my $grammar = qq~ RecTest: ExpSet(s) ( Expression | SubExp ) | Expression | SubExp | Expression: ELEMENT COMPARE ELEMENT ExpSet: ( Expression | SubExp ) JOIN SubExp: '(' (ExpSet(s) Expression | Expression) ')' ELEMENT: 'h' COMPARE: /(?:=(?![><]=))?[><]=?/ | '!=' | '=' JOIN: /and/i | /or/i | /xor/i ~; my $parser = new Parse::RecDescent($grammar) or die; print $parser->RecTest('(h = h and h != h) and ((h > h or h < h') or die;