Talk:Recursive descent parser generator: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
mNo edit summary
Line 12: Line 12:
</pre>
</pre>


Is there any way to simplify this? (I don't seem to remember any parser generators using two pieces of code like that, but I can't find anything saying you can get away with just one right now.)
Is there any way to simplify this?


The example I want to use is to take an arithmetic expression and turn it in to a series of single operations in the right order. So:
The example I want to use is to take an arithmetic expression and turn it in to a series of single operations in the right order. So:

Revision as of 06:20, 2 April 2014

Input specification

The main thing that needs to be fixed before adding any examples is the input specification. I want to make it detailed enough to be at least slightly usable (so more than just a recognizer) but I'm having trouble coming up with a clear way of expressing both the rule and the extra code generated when the rule is applied, especially taking in to account all the different languages that you might want to output with or to. Here's one attempt, but as you can see, it's not that clear:

!! start
pre-traversal code here
-> var expr
post-traversal code here

!! expr
...

Is there any way to simplify this? (I don't seem to remember any parser generators using two pieces of code like that, but I can't find anything saying you can get away with just one right now.)

The example I want to use is to take an arithmetic expression and turn it in to a series of single operations in the right order. So:

(one + two) * three + four * five

Becomes something like:

_a = one + two
_b = _a * three
_c = four * five
_d = _b + _c

MagiMaster (talk) 06:10, 2 April 2014 (UTC)