mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-05 21:50:02 +00:00
23 lines
530 B
Plaintext
23 lines
530 B
Plaintext
|
/*
|
||
|
* 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); }
|