- Timestamp:
- 10/31/13 13:11:51 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GPDL/Examples/Factorial.txt
r10061 r10099 11 11 public int GetValue(string id) { 12 12 int val = 0; 13 values.TryGetValue(id, out val); 13 values.TryGetValue(id, out val); 14 14 return val; 15 15 } … … 18 18 19 19 NONTERMINALS 20 Program<<int n, out int r>>. /* return value is the result of the last statement. */21 StatSeq<<out int r>>. 20 Program<<int n, out int r>>. /* return value is the result of the last statement. */ 21 StatSeq<<out int r>>. 22 22 AssignStat<<out int r>>. /* result of assignment is the assigned value */ 23 23 IncStat<<out int r>>. 24 24 DecStat<<out int r>>. 25 25 WhileStat<<out int r>>. /* result of while loop is the result of the last executed statement */ 26 ReturnStat<<out int r>>.27 26 Expr<<out int r>>. 28 27 AdditionExpr<<out int r>>. … … 36 35 AssignStatAndStatSeq<<out int r>>. 37 36 WhileStatAndStatSeq<<out int r>>. 38 ReturnStatAndStatSeq<<out int r>>.39 37 40 38 TERMINALS … … 56 54 . 57 55 StatSeq<<out int r>> = LOCAL << r = 0; >> 58 Nothing<<out r>> 56 Nothing<<out r>> 59 57 | AssignStatAndStatSeq<<out r>> 60 58 | WhileStatAndStatSeq<<out r>> 61 | ReturnStatAndStatSeq<<out r>> 62 | IncStat<<out r>> 63 | DecStat<<out r>> 59 | IncStat<<out r>> 60 | DecStat<<out r>> 64 61 . 65 62 … … 69 66 WhileStatAndStatSeq<<out int r>> = 70 67 StatSeq<<out r>> WhileStat<<out r>> 71 .72 ReturnStatAndStatSeq<<out int r>> =73 StatSeq<<out r>> ReturnStat<<out r>>74 68 . 75 69 … … 90 84 StatSeq<<out r>> SEM << } >> 91 85 . 92 ReturnStat<<out int r>> = Expr<<out r>> SEM << return; >> 93 . 86 94 87 Expr<<out int r>> = LOCAL << string id; >> 95 88 AdditionExpr<<out r>> … … 98 91 | DivisionExpr<<out r>> 99 92 | Const<<out r>> 100 | ident<<out id>> 93 | ident<<out id>> SEM << r = symTab.GetValue(id); >> 101 94 . 102 AdditionExpr<<out int r>> = 103 Expr<<out e1>> Expr<<out e2>> 95 AdditionExpr<<out int r>> = LOCAL << int e1, e2; >> 96 Expr<<out e1>> Expr<<out e2>> SEM << r = e1 + e2; >> 104 97 . 105 SubtractionExpr<<out int r>> = 106 Expr<<out e1>> Expr<<out e2>> 98 SubtractionExpr<<out int r>> = LOCAL << int e1, e2; >> 99 Expr<<out e1>> Expr<<out e2>> SEM << r = e1 - e2; >> 107 100 . 108 MultiplicationExpr<<out int r>> = 109 Expr<<out e1>> Expr<<out e2>> 101 MultiplicationExpr<<out int r>> = LOCAL << int e1, e2; >> 102 Expr<<out e1>> Expr<<out e2>> SEM << r = e1 * e2; >> 110 103 . 111 DivisionExpr<<out int r>> = 112 Expr<<out e1>> Expr<<out e2>> 104 DivisionExpr<<out int r>> = LOCAL << int e1, e2; >> 105 Expr<<out e1>> Expr<<out e2>> SEM << r = e2 == 0 ? 1 : e1 / e2; >> 113 106 . 114 107 BooleanExpr<<out bool b>> = … … 117 110 | NotExpr<<out b>> 118 111 . 119 NotExpr<<out bool b>> = 120 BooleanExpr<<out notB>> 112 NotExpr<<out bool b>> = LOCAL << bool notB; >> 113 BooleanExpr<<out notB>> SEM << b = !notB; >> 121 114 . 122 LessThanExpr<<out bool b>> = 123 Expr<<out lhs>> Expr<<out rhs>> 115 LessThanExpr<<out bool b>> = LOCAL << int lhs, rhs; >> 116 Expr<<out lhs>> Expr<<out rhs>> SEM << b = lhs < rhs; >> 124 117 . 125 EqualExpr<<out bool b>> = 126 Expr<<out lhs>> Expr<<out rhs>> 118 EqualExpr<<out bool b>> = LOCAL << int lhs, rhs; >> 119 Expr<<out lhs>> Expr<<out rhs>> SEM << b = lhs == rhs; >> 127 120 . 128 121 129 122 130 MINIMIZE /* could also use the keyword MAXIMIZE here */123 MINIMIZE 131 124 << 132 125 var ns = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Note: See TracChangeset
for help on using the changeset viewer.