|
1 | | -// IronMeta Copyright � Gordon Tisher 2018 |
| 1 | +// IronMeta Copyright � The IronMeta Developers |
2 | 2 |
|
3 | 3 | using System; |
4 | 4 | using System.Linq; |
5 | 5 |
|
6 | 6 | using IronMeta.Matcher; |
7 | 7 |
|
8 | | -// This grammar is far more complicated than |
| 8 | +// This grammar is far more complicated than |
9 | 9 | // it needs to be, in order to demonstrate |
10 | 10 | // the features of the IronMeta system. |
11 | 11 |
|
12 | 12 | ironmeta Calc<char, int> : Matcher<char, int> |
13 | 13 | { |
14 | 14 | Expression = Additive; |
15 | | - |
| 15 | + |
16 | 16 | Additive = Add | Sub | Multiplicative; |
17 | | - |
18 | | - Add = BinaryOp(Additive, '+', Multiplicative) |
| 17 | + |
| 18 | + Add = BinaryOp(Additive, '+', Multiplicative) |
19 | 19 | -> { return _IM_Result.Results.Aggregate((total, n) => total + n); }; |
20 | | - Sub = BinaryOp(Additive, '-', Multiplicative) |
| 20 | + Sub = BinaryOp(Additive, '-', Multiplicative) |
21 | 21 | -> { return _IM_Result.Results.Aggregate((total, n) => total - n); }; |
22 | | - |
| 22 | + |
23 | 23 | Multiplicative = Multiply | Divide; |
24 | 24 | Multiplicative = Number(DecimalDigit); |
25 | | - |
26 | | - Multiply = BinaryOp(Multiplicative, "*", Number, DecimalDigit) |
| 25 | + |
| 26 | + Multiply = BinaryOp(Multiplicative, "*", Number, DecimalDigit) |
27 | 27 | -> { return _IM_Result.Results.Aggregate((p, n) => p * n); }; |
28 | | - Divide = BinaryOp(Multiplicative, "/", Number, DecimalDigit) |
| 28 | + Divide = BinaryOp(Multiplicative, "/", Number, DecimalDigit) |
29 | 29 | -> { return _IM_Result.Results.Aggregate((q, n) => q / n); }; |
30 | | - |
31 | | - BinaryOp :first :op :second .?:type = first:a KW(op) second(type):b |
| 30 | + |
| 31 | + BinaryOp :first :op :second .?:type = first:a KW(op) second(type):b |
32 | 32 | -> { return new List<int> { a, b }; }; |
33 | | - |
| 33 | + |
34 | 34 | Number :type = Digits(type):n WS* -> { return n; }; |
35 | | - |
| 35 | + |
36 | 36 | Digits :type = Digits(type):a type:b -> { return a*10 + b; }; |
37 | 37 | Digits :type = type; |
38 | | - |
39 | | - DecimalDigit = ['0'-'9']:c -> { return (char)c - '0'; }; |
| 38 | + |
| 39 | + DecimalDigit = ['0'-'9']:c -> { return (char)c - '0'; }; |
40 | 40 | KW :str = str WS*; |
41 | 41 | WS = ' ' | '\n' | '\r' | '\t'; |
42 | 42 | } |
0 commit comments