start : _ expression { return $2; } expression : additive additive : multiplicative (plus / minus) additive { if ($2 === "+") { return $1 + $3; } if ($2 === "-") { return $1 - $3; } } / multiplicative multiplicative : primary (times / divide) multiplicative { if ($2 === "*") { return $1 * $3; } if ($2 === "/") { return $1 / $3; } } / primary primary : integer / lparen expression rparen { return $2 } integer "integer" : [0-9]+ _ { return parseInt($1.join("")); } plus : "+" _ { return $1; } minus : "-" _ { return $1; } times : "*" _ { return $1; } divide : "/" _ { return $1; } lparen : "(" _ rparen : ")" _ _ "whitespace" : [ \t\n\r]*