preview

Code Fragments of Parse::RecDescent

Decent Essays

Answer : start : As Bs Cs { start.ok := (As.val == Bs.val == Cs.val) } As: : a As { As.val_left := As.val_right + 1 | '' { As.val := 0 } Bs: : b Bs { Bs.val_left := Bs.val_right + 1 # | '' { Bs.val := 0 } Cs: : c Cs { Cs.val_left := Cs.val_right + 1 | '' { Cs.val := 0 } I expect that this can be done entirely within Parse::RecDescent (ParseRecDescent does allow code fragments quite like what I have above) And that might be in fact interesting because it'd show if the the attributes on the right are available before they're needed. Since Parse::RecDescent is recursive descent, and therefore goes depth first left-to-right, I think that'd work in one pass. I'm sure this is S-attributed. (Attribute rules for things on the left depend only on things on the right, i.e. their direct children, so bottom-up works.) Turns out its also L-attributed (top-down left-to-right has what's needed in order) which is I believe what Parse::RecDescent needs to do it in one pass. See abc_2.pl for a Parse::RecDescent for that version. But here I'm doing something conceptually simpler, I think, though it does require more code. First I'm using Parse::RecDesent's feature to generate a parse tree, and then once its in hand I'm explicitly applying an attribute grammar at each node using a depth-first

Get Access