@@ -93,14 +93,9 @@ public enum Operators
9393 LeftShift ,
9494 RightShift ,
9595 // ...
96-
9796 }
9897
99-
10098public class BinaryExpression (Expression left , Operator operator , Expression right , TextLocation location ) : Expression (location );
101-
102-
103-
10499```
105100
106101### Scanning code
@@ -144,7 +139,6 @@ bool IsDigitValue(char c, int value)
144139
145140bool IsDigitRange (char c , Range range );
146141
147-
148142bool ParseIntegerLiteral (ref Scanner scanner , out IntegerLiteral literal )
149143{
150144 // We keep track of the position before we match anything
@@ -178,7 +172,6 @@ bool ParseIntegerLiteral(ref Scanner scanner, out IntegerLiteral literal)
178172 literal = null ! ;
179173 return false ;
180174}
181-
182175```
183176
184177
@@ -209,15 +202,12 @@ bool ParseNumberLiteral(ref Scanner scanner, out NumberLiteral number)
209202 number = null ! ;
210203 return false ;
211204}
212-
213205```
214206
215207
216208We can even go one step higher and use this number parser to create our first binary operation parser :
217209
218210``` csharp
219-
220-
221211// A utility function that resets the position. We can modify it to catch errors
222212bool ExitParser <TNode >(ref Scanner scanner , out TNode node , int position ) where TNode : ASTNode ;
223213
@@ -226,7 +216,6 @@ bool ExitParser<TNode>(ref Scanner scanner, out TNode node, int position) where
226216
227217bool FollowedByAny (ref Scanner scanner , string chars , out char value , bool withSpaces = false , bool advance = false );
228218
229-
230219bool Spaces (ref Scanner scanner , int min = 0 )
231220{
232221 var start = scanner .Position ;
@@ -273,7 +262,6 @@ bool Mul(ref Scanner scanner, out Expression expression)
273262 return true ;
274263 else return ExitParser (ref scanner , result , out expression , position , orError );
275264}
276-
277265```
278266
279267We can also write the addition/subtraction parser, following the operator precedence :
@@ -306,7 +294,6 @@ bool Add(ref Scanner scanner, out Expression expression)
306294 return true ;
307295 else return ExitParser (ref scanner , result , out expression , position , orError );
308296}
309-
310297```
311298
312299The sharpest ones will notice I'm not using recursion for everything, i'm using a while loop. This is a small optimisation called [ precedence climbing] ( https://eli.thegreenplace.net/2012/08/02/parsing-expressions-by-precedence-climbing ) to avoid to many recursions when parsing long and complex expressions.
@@ -325,7 +312,6 @@ namespace MyNameSpace
325312{
326313 shader Parent
327314 {
328-
329315 struct MyStruct {
330316 int a;
331317 };
0 commit comments