LARA

// polynomial ::= term ("+" term)*
def parsePolynomial = {
  parseTerm
  while (lex.current==PLUS) {
    lex.next
    parseTerm
  }
}
// term ::= factor ("*" factor)*
def parseTerm = {
  parseFactor
  while (lex.current==MUL) {
    lex.next
    parseFactor
  }
}
// factor ::= constant | variable | "(" polynomial ")"
def parseFactor = {
  if (lex.current==CONST)
    lex.next
  else if (lex.current==IDENT)
    lex.next
  else if (lex.current==OPAREN) {
    lex.next
    parsePolynomial
    eat(CPAREN)
  } else
    error("Expected const, ident, or open paren")
  }
}
def eat(t : Token) = {
  if (lex.current==t)
    lex.next
  else
    error("Expected token " + t)
}