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.

Evaluate by FoldLeft<br />

We can solve this problem by delaying reduction until all elements <strong>of</strong> a<br />

repetition have been parsed and then performing a fold left on the list:<br />

def expr : Parser[Int] =<br />

term ˜ rep (”+” ˜ term | ”−” ˜ term) ˆˆ reduceList<br />

def term : Parser[Int] =<br />

factor ˜ rep (”∗” ˜ factor | ”/” ˜ factor) ˆˆ reduceList<br />

def factor : Parser[Int] =<br />

”(” ˜> expr

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

Saved successfully!

Ooh no, something went wrong!