1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-19 00:04:51 +00:00
TiddlyWiki5/node_modules/pegjs/examples/arithmetics.pegjs
Jeremy Ruston b27a99a7fb Added pegjs
Which is going to replace uglify
2011-12-28 18:03:07 +00:00

23 lines
530 B
JavaScript

/*
* Classic example grammar, which recognizes simple arithmetic expressions like
* "2*(3+4)". The parser generated from this grammar then computes their value.
*/
start
= additive
additive
= left:multiplicative "+" right:additive { return left + right; }
/ multiplicative
multiplicative
= left:primary "*" right:multiplicative { return left * right; }
/ primary
primary
= integer
/ "(" additive:additive ")" { return additive; }
integer "integer"
= digits:[0-9]+ { return parseInt(digits.join(""), 10); }