else if (Char(input, '-'))
98 {
99 return new NegExpression
100 {
101 Op = Exp0(input),
102 };
103 }
104 else
105 {
106 double number = Number(input);
107 if (!double.IsNaN(number))
108 {
109 return new NumberExpression
110 {
111 Number = number,
112 };
113 }
114
115 string name = Name(input);
116 if (name == null)
117 {
118 throw new ArgumentException("Error encountered, at " + new string(*input));
119 }
120
121 if (!Char(input, '('))
122 {
123 return new VariableExpression
124 {
125 Name = name,
126 };
127 }
128
129 FunctionExpression f = FunctionExpression.FromName(name);
130 f.Op = Exp3(input);
131 if (!Char(input, ')'))
132 {
133 throw new ArgumentException("Error encountered, at " + new string(*input));
134 }
135 return f;
136 }
137 }
138
139 private static Expression Exp1(char** input)
140 {
141 Expression e = Exp0(input);
142 while (true)
143 {
144 if (Char(input, '^'))
145 {
146 e = new PowerExpression
147 {
148 Left = e,
149 Right = Exp0(input),
150 };
151 }
152 else
153 {
154 break;
155 }
156 }
157 return e;
158 }
159
160 private static Expression Exp2(char** input)
161 {
162 Expression e = Exp1(input);
163 while (true)
164 {
165 if (Char(input, '*'))
166 {
167 e = new MulExpression
168 {
169 Left = e,
170 Right = Exp1(input),
171 };
172 }
173 else if (Char(input, '/'))
174 {
175 e = new DivExpression
176 {
177 Left = e,
178 Right = Exp1(input),
179 };
180 }
181 else
182 {
183 break;
184 }
185 }
186 return e;
187 }
188
189 private static Expression Exp3(char** input)
190 {
191 Expression e = Exp2(input);
192 while (true)
193 {
194 if (Char(input, '+'))
195 {
196 e = new AddExpression
197 {
198 Left = e,
199