Perl-Sensitive Sunglasses | |
PerlMonks |
Re^4: Writing a Programming Language in Perlby ikegami (Patriarch) |
on Oct 25, 2011 at 22:15 UTC ( [id://933718]=note: print w/replies, xml ) | Need Help?? |
In theory, it works in practice. At a glance, it seems to me it assumes a simplistic world. The world doesn't conform to BNF. That's why Perl regular expressions aren't actually regular. As I said above, associativity is an example of something BNF can't handle. In BNF, all three of the following are the equivalent:
You might think one could deviate from BNF and declare the second form to be left-associative and the third form to be right-associative. However, (most?) parsers can only handle left-recursion or right-recursion, not both. That means one cannot support both the second and the third form, which means we're back to square one. You need special tools to handle associativity (like PRD's <leftop> and <rightop>) or more generically, the ability to pass down context (like PRD's subrule args). I have examples of both methods. The ability to pass down context is surely useful in other circumstances, too. It can help if you have ambiguities in your grammar. It can probably help with specialised error messages.
In Section
Seekers of Perl Wisdom
|
|