10.02.2013 Views

Foundations of Software - LAMP - EPFL

Foundations of Software - LAMP - EPFL

Foundations of Software - LAMP - EPFL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A Problem with Top-Down Parsing<br />

As parser combinators work top-down, they don’t allow left-recursion.<br />

A production like<br />

def expr = expr ˜ ”−” ˜ term<br />

would go into an infinite recursion when executed.<br />

The alternative:<br />

def expr = term ˜ rep(”−” ˜ term)<br />

produces a “right-leaning” tree: X − Y − Z parses<br />

X ˜ List(”−” ˜ Y, ”−” ˜ Z)<br />

But the correct reduction/evaluation <strong>of</strong> +,−,∗,/ is left-leaning!<br />

53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!