Re: expressions ?! how ?

[email protected] (raptor) Wed, 30 Jul 2003 10:16:32 +0300
Newsgroups perl.recdescent
Message-ID <[email protected]>
]- yep it work, i ever tried several other variants that worked too.. the main problem (not a big one) is that if I use
<leftop:..> directive the @item access to separate elements is differnt/harder (which is normal as we know how it work) i.e. @item is a mulidimentional array and become deeper and deeper as the expression become more complex.
I just want a flattened string of all and in this case I have to make a complex for-in-for cycle.

expression  : <leftop: andExpr 'or' andExpr> { "$item[1][0] $item[1][2]" }  

or some such..(print Dumper \@item gives better idea).
In my case I saw that it will be easier to just use s/// instead of grammar, but never mind it was a good exersice to understan a little bit of the problems with rescursions :") in RecDescent...

|I could be wrong of course, I didnt look into it that deeply. But it seems
|to me that the grammar
|
|expression  : <leftop: andExpr 'or' andExpr>
|andExpr     : <leftop: notExpr 'and' notExpr>
|notExpr     : 'not' brackExpr | brackExpr
|brackExpr   : '(' expression ')' |  comparison
|comparison  : identifier compType identifier
|compType    : '=' | '>' | '<' | '>=' | '<='
|identifier  : fieldName | number
|fieldName   : /[a-z]+/
|number      : /\d+/
|
|works fine. (At least off the top of my head I couldnt build an expression
|that would break it.)
|
|Anyway, the below link documents a mechanical means of eliminating left
|recursion from a PRD grammar. And has lots of links to better articles on
|the subject.
|
|  http://perlmonks.org/index.pl?node_id=153155
|
|Yves
|