You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pegjs/examples/arithmetics.pegjs

26 lines
792 B
Plaintext

start : _ additive { return $2; }
15 years ago
additive : multiplicative plus additive { return $1 + $3; }
/ multiplicative minus additive { return $1 - $3; }
15 years ago
/ multiplicative
multiplicative : primary times multiplicative { return $1 * $3; }
/ primary divide multiplicative { return $1 / $3; }
15 years ago
/ primary
primary : integer
/ lparen additive rparen { return $2 }
15 years ago
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]*