private static void CheckStatement(Context expression, Action <CompileException, Context> onError, SymbolTable table) { if (expression.Children.Count == 0) { return; } if (expression.Children.Count == 2 && expression.Children.Last.Value is VariableAssignmentIdentifier v) { string type; if (v.IsNewVariable) { var variable = v.Children.First.Value as VariableDefinitionContext; type = variable.Type; table.RegisterVariable(variable.Name, type, variable); } else { string name = v.Identifier; type = TableSearcher.GetVar(table, name, expression).type; } string expressionType = GetExpressionType(expression.Children.First.Value, onError, table); if (expressionType != "void" && type != expressionType) { onError(new CompileException($"Type of expression in statement does not match type of assignment"), expression); } return; } GetExpressionType(expression, onError, table); }
private static string CheckFunctionCall(ExpressionContext expression, Action <CompileException, Context> onError, SymbolTable table) { string name = (expression.Children.First.Value as IdentifierContext).Identifier; var children = expression.Children.Skip(1); var func = TableSearcher.GetFunc(table, name, expression); return(CheckFunctionCall(children, name, func, onError, table)); }