10.02.2013 Views

Foundations of Software - LAMP - EPFL

Foundations of Software - LAMP - EPFL

Foundations of Software - LAMP - EPFL

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Arithmetic Expressions Again<br />

Here is the full parser for arithmetic expressions:<br />

object Arithmetic extends StandardTokenParsers {<br />

lexical.delimiters ++= List(”(”, ”)”, ”+”, ”−”, ”∗”, ”/”)<br />

def expr : Parser[Any] = term ˜ rep(”+” ˜ term | ”−” ˜ term)<br />

def term = factor ˜ rep(”∗” ˜ factor | ”/” ˜ factor)<br />

def factor : Parser[Any] = ”(” ˜ expr ˜ ”)” | numericLit<br />

Question: How can we make it evaluate the parsed expression?<br />

52

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

Saved successfully!

Ooh no, something went wrong!