diff --git a/peggy/02_calc/calc.pegjs b/peggy/02_calc/calc.pegjs new file mode 100644 index 0000000..0ea6b86 --- /dev/null +++ b/peggy/02_calc/calc.pegjs @@ -0,0 +1,11 @@ +s = e + +e = left:t "+" right:e { return left + right; } + / t + +t = left:f "*" right:t { return left * right; } + / f + +f = _ num:[0-9]+ _ { return parseInt(num.join(""), 10); } + +_ = [ \t\n\r]*