in reply to Re^3: Writing a Programming Language in Perl
in thread Writing a Programming Language in Perl
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:
foo : foo bar foo # Left- and right-recursive foo : baz foo : foo bar baz # Left-recursive foo : baz foo : baz bar foo # Right-recursive foo : baz
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Writing a Programming Language in Perl
by Jeffrey Kegler (Hermit) on Nov 14, 2011 at 17:28 UTC | |
by ikegami (Patriarch) on Nov 14, 2011 at 20:13 UTC |