grammar problems
[email protected] (Jonas Wolf) Thu, 20 May 2004 13:52:04 +0100
| Newsgroups | perl.recdescent |
|---|---|
| Message-ID | <OF3BCD0147.3F27BB0B-ON80256E9A.00469D05-80256E9A.00466148@uk.ibm.com> |
Hello,
I recently downloaded the Parse::RecDescent package to parse
boolean queries. I have several questions, not necessarily about
the package itself, but rather about my grammar.
I am currently using the following grammar:
my $grammar = q
{
<autotree>
disj : qualif(?) conj disjRec(s?)
disjRec : disjOp conj
conj : term conjRec(s?)
conjRec : conjOp term
term : brack | phrase | ident
brack : '(' disj ')'
phrase : '"' ident(s?) '"'
ident : /[a-zA-Z0-9]+/i
qualif : ident '='
conjOp : /AND/i
disjOp : /OR/i
};
I have several problems with this.
Firstly, the precedence isn't quite what I want in 'qualif'. I would
like 'ident' to bind tightly to whatever comes next to it. Currently
it seems to associate it with the whole 'disj' that comes after.
Secondly, I would like the 'conjOp' operator to be optional, and that
the parser recognises this. This means a query for 'a b' would be
interpreted as 'a AND b'. I tried replacing the conjOp rule with
'conjOp : /AND/i | ""', but this does not work, as now a query
'a AND b' is interpreted as 'a AND and ...'.
Any help would be appreciated.
Thanks, Jonas.