private void WaddleAssignStmt(AssignStmtSyntax assignStmt) { if (_currentFunction == null) { throw new SemanticErrorException($"can not use assign statement outside of function."); } if (_currentFunction !.Variables.ContainsKey(assignStmt.StartToken.Lexeme) == false) { throw new SemanticErrorException( $"unknown identifier ({assignStmt.StartToken.Lexeme}) @({assignStmt.StartToken.LineNumber}{assignStmt.StartToken.CharPosition})."); } var identifier = _currentFunction?.Variables[assignStmt.StartToken.Lexeme] !; var exprType = WaddleExpression(assignStmt.Expression); // check IsAssignableFrom if (IsAssignableFrom(identifier.Type !, exprType) == false) { throw new SemanticErrorException($"The type {exprType} can not be assigned into {identifier.Name}."); } }
public bool EnterAssignStmt(AssignStmtSyntax assignStmt, WaddleContext ctx) { if (_currentFunction == null) { throw new SemanticErrorException($"can not use assign statement outside of function."); } if (_currentFunction !.Variables.ContainsKey(assignStmt.StartToken.Lexeme) == false) { throw new SemanticErrorException( $"unknown identifier ({assignStmt.StartToken.Lexeme}) @({assignStmt.StartToken.LineNumber}{assignStmt.StartToken.CharPosition})."); } var identifier = _currentFunction?.Variables[assignStmt.StartToken.Lexeme] !; var exprType = assignStmt.Expression.Accept(TypeVisitor); // check IsAssignableFrom if (identifier.Type != exprType) { throw new SemanticErrorException($"The type {exprType} can not be assigned into {identifier.Name}."); } return(true); }
public virtual TResult Visit(AssignStmtSyntax syntax) { return(DefaultResult); }
public void LeaveAssignStmt(AssignStmtSyntax assignStmt, WaddleContext ctx) { }