Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
},
"dependencies": {
"@11ty/eleventy-fetch": "^5.1.1",
"@fortawesome/fontawesome-free": "^7.1.0",
"@fortawesome/fontawesome-free": "^7.2.0",
"bootstrap": "^5.3.8",
"lunr": "^2.3.9",
"markdown-it-anchor": "^9.2.0",
"markdown-it-table-of-contents": "^1.1.0",
"sass": "^1.97.1"
"sass": "^1.97.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,9 @@ public enum Operators
LeftShift,
RightShift,
//...

}


public class BinaryExpression(Expression left, Operator operator, Expression right, TextLocation location) : Expression(location);



```

### Scanning code
Expand Down Expand Up @@ -144,7 +139,6 @@ bool IsDigitValue(char c, int value)

bool IsDigitRange(char c, Range range);


bool ParseIntegerLiteral(ref Scanner scanner, out IntegerLiteral literal)
{
// We keep track of the position before we match anything
Expand Down Expand Up @@ -178,7 +172,6 @@ bool ParseIntegerLiteral(ref Scanner scanner, out IntegerLiteral literal)
literal = null!;
return false;
}

```


Expand Down Expand Up @@ -209,15 +202,12 @@ bool ParseNumberLiteral(ref Scanner scanner, out NumberLiteral number)
number = null!;
return false;
}

```


We can even go one step higher and use this number parser to create our first binary operation parser :

```csharp


// A utility function that resets the position. We can modify it to catch errors
bool ExitParser<TNode>(ref Scanner scanner, out TNode node, int position) where TNode : ASTNode;

Expand All @@ -226,7 +216,6 @@ bool ExitParser<TNode>(ref Scanner scanner, out TNode node, int position) where

bool FollowedByAny(ref Scanner scanner, string chars, out char value, bool withSpaces = false, bool advance = false);


bool Spaces(ref Scanner scanner, int min = 0)
{
var start = scanner.Position;
Expand Down Expand Up @@ -273,7 +262,6 @@ bool Mul(ref Scanner scanner, out Expression expression)
return true;
else return ExitParser(ref scanner, result, out expression, position, orError);
}

```

We can also write the addition/subtraction parser, following the operator precedence :
Expand Down Expand Up @@ -306,7 +294,6 @@ bool Add(ref Scanner scanner, out Expression expression)
return true;
else return ExitParser(ref scanner, result, out expression, position, orError);
}

```

The 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.
Expand All @@ -325,7 +312,6 @@ namespace MyNameSpace
{
shader Parent
{

struct MyStruct {
int a;
};
Expand Down