diff --git a/Upsilon/Binder/Binder.cs b/Upsilon/Binder/Binder.cs index 3466041..05ddedd 100644 --- a/Upsilon/Binder/Binder.cs +++ b/Upsilon/Binder/Binder.cs @@ -131,7 +131,7 @@ namespace Upsilon.Binder case SyntaxKind.FunctionExpression: return BindFunctionExpression((FunctionExpressionSyntax) e); case SyntaxKind.BadExpression: - return new BoundLiteralExpression(new ScriptNull(), e.Span); + return new BoundBadExpression(e.Span); case SyntaxKind.ScriptUnit: break; default: @@ -143,6 +143,8 @@ namespace Upsilon.Binder private BoundExpression BindUnaryExpression(UnaryExpressionSyntax e) { var inExp = BindExpression(e.Expression); + if (inExp.Kind == BoundKind.BoundBadExpression) + return new BoundBadExpression(e.Span); var op = BoundUnaryOperator.Bind(e.Operator.Kind, inExp.Type); if (op == null) { @@ -157,6 +159,8 @@ namespace Upsilon.Binder { var left = BindExpression(e.Left); var right = BindExpression(e.Right); + if (left.Kind == BoundKind.BoundBadExpression || right.Kind == BoundKind.BoundBadExpression) + return new BoundBadExpression(e.Span); var op = BoundBinaryOperator.Bind(e.Operator.Kind, left.Type, right.Type); if (op == null) { @@ -206,7 +210,7 @@ namespace Upsilon.Binder if (expression.Type != Type.Function && expression.Type != Type.Unknown) { _diagnostics.LogError($"Unknown function called.", e.Span); - return new BoundLiteralExpression(new ScriptNull(), e.Span); + return new BoundBadExpression(e.Span); } var parameters = ImmutableArray.CreateBuilder(); @@ -378,7 +382,7 @@ namespace Upsilon.Binder if (!Scope.TryGetVariable(name, true, out var variable)) { _diagnostics.LogUnknownVariable(e.Identifier.Span, name); - return new BoundLiteralExpression(new ScriptNull(), e.Span); + return new BoundBadExpression(e.Span); } var boundVariable = new BoundVariableSymbol(variable, false, e.Identifier.Span); return new BoundVariableExpression(boundVariable, e.Span); @@ -480,7 +484,7 @@ namespace Upsilon.Binder } } - return new BoundExpressionStatement(new BoundLiteralExpression(new ScriptNull(), e.Span), e.Span); + return new BoundExpressionStatement(new BoundBadExpression(e.Span), e.Span); } private BoundStatement BindMultiAssignmentStatement(MultiAssignmentStatementSyntax s) @@ -642,7 +646,7 @@ namespace Upsilon.Binder else { _diagnostics.LogCannotConvert(Type.Function, variable.Type, e.Span); - return new BoundExpressionStatement(new BoundLiteralExpression(new ScriptNull(), e.Span), e.Span); + return new BoundExpressionStatement(new BoundBadExpression(e.Span), e.Span); } } } @@ -706,7 +710,7 @@ namespace Upsilon.Binder if (index.Type != Type.Number && index.Type != Type.String && index.Type != Type.Unknown) { _diagnostics.LogInvalidIndexExpression(expression.Type, index.Type, e.Span); - return new BoundLiteralExpression(new ScriptNull(), e.Span); + return new BoundBadExpression(e.Span); } switch (expression.Type) { @@ -756,7 +760,7 @@ namespace Upsilon.Binder return new BoundIndexExpression(expression, index, Type.String, e.Span); default: _diagnostics.LogInvalidIndexExpression(expression.Type, index.Type, e.Span); - return new BoundLiteralExpression(new ScriptNull(), e.Span); + return new BoundBadExpression(e.Span); } } @@ -823,7 +827,7 @@ namespace Upsilon.Binder return new BoundFullStopIndexExpression(expression, index, Type.String, e.Span); default: _diagnostics.LogInvalidIndexExpression(expression.Type, Type.String, e.Span); - return new BoundLiteralExpression(new ScriptNull(), e.Span); + return new BoundBadExpression(e.Span); } } diff --git a/Upsilon/Binder/BoundExpressions/BoundBadExpression.cs b/Upsilon/Binder/BoundExpressions/BoundBadExpression.cs new file mode 100644 index 0000000..3f3df68 --- /dev/null +++ b/Upsilon/Binder/BoundExpressions/BoundBadExpression.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using Upsilon.BaseTypes; +using Upsilon.Text; + +namespace Upsilon.Binder +{ + public class BoundBadExpression : BoundExpression + { + public BoundBadExpression(TextSpan span) : base(span) + { + } + + public override BoundKind Kind => BoundKind.BoundBadExpression; + public override IEnumerable GetNodeAtPosition(int linePosition, int characterPosition) + { + yield break; + } + + public override IEnumerable GetChildren() + { + yield break; + } + + public override Type Type => Type.Nil; + } +} \ No newline at end of file diff --git a/Upsilon/Binder/BoundKind.cs b/Upsilon/Binder/BoundKind.cs index 45a31ec..2fdb4ed 100644 --- a/Upsilon/Binder/BoundKind.cs +++ b/Upsilon/Binder/BoundKind.cs @@ -13,6 +13,7 @@ namespace Upsilon.Binder BoundTableExpression, BoundIndexExpression, BoundFunctionExpression, + BoundBadExpression, // Statements BoundAssignmentStatement, @@ -29,6 +30,6 @@ namespace Upsilon.Binder BoundNumericForStatement, BoundGenericForStatement, BoundBreakStatement, - BoundWhileStatement + BoundWhileStatement, } } \ No newline at end of file diff --git a/Upsilon/Evaluator/Evaluator.cs b/Upsilon/Evaluator/Evaluator.cs index 95d9aba..882dccc 100644 --- a/Upsilon/Evaluator/Evaluator.cs +++ b/Upsilon/Evaluator/Evaluator.cs @@ -254,7 +254,7 @@ namespace Upsilon.Evaluator case BoundKind.BoundFullstopIndexExpression: return EvaluateFullStopIndexExpression((BoundFullStopIndexExpression) e); default: - throw new NotImplementedException(); + throw new NotImplementedException(e.Kind.ToString()); } } diff --git a/Ycicle/Program.cs b/Ycicle/Program.cs index 6171520..1ae6b40 100644 --- a/Ycicle/Program.cs +++ b/Ycicle/Program.cs @@ -38,6 +38,19 @@ namespace Ycicle Console.ResetColor(); continue; } + script.Bind(); + if (script.Diagnostics.Errors.Count > 0) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Errors were found during parsing"); + foreach (var diagnosticsMessage in script.Diagnostics.Errors) + { + LogMessage(DiagnosticLevel.Error, diagnosticsMessage); + } + Console.ResetColor(); + continue; + } + //Console.WriteLine(script.PrettyPrintSyntaxTree()); var evaluate = script.Evaluate();