示例#1
0
        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}.");
            }
        }
示例#2
0
        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);
        }
示例#3
0
 public virtual TResult Visit(AssignStmtSyntax syntax)
 {
     return(DefaultResult);
 }
示例#4
0
 public void LeaveAssignStmt(AssignStmtSyntax assignStmt, WaddleContext ctx)
 {
 }