-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser-grammar.pegjs
More file actions
35 lines (25 loc) · 892 Bytes
/
parser-grammar.pegjs
File metadata and controls
35 lines (25 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* 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; }
/ left:multiplicative "-" right:additive { return left - right; }
/ multiplicative
multiplicative
= left:primary "*" right:multiplicative { return left * right; }
/ left:primary "/" right:multiplicative { return left / right; }
/ primary
primary
= decimal
/ integer
/ cell
/ "(" additive:additive ")" { return additive; }
integer "integer"
= digits:[0-9]+ { return parseInt(digits.join(""), 10); }
decimal "decimal"
= start: [0-9]+'.' end:[0-9]+ { return parseFloat (start.join("") + "." + end.join("")); }
cell
= col: [a-zA-Z]+ row:[0-9]+ {return window.resolveCell(row.join(""),col.join(""))}