public void Visit(NAssign nAssign)
        {
            string lexeme = nAssign.AnchorToken.Lexeme;

            if (currentFunction.GetLocalVariableSymbolByLexeme(lexeme) != null || semanticAnalyzer.GetGlobalVariableSymbolByLexeme(lexeme) != null)
            {
                Visit((dynamic)nAssign[0]);
            }
            else
            {
                throw new SemanticError("Variable not in scope", nAssign.AnchorToken);
            }
        }
Пример #2
0
        // Loads variable into stack (push) by resolving if it is a local, global or parameter one
        string loadVariable(string lexeme)
        {
            VariableSym varSym = currentFunction.GetLocalVariableSymbolByLexeme(lexeme);

            if (varSym != null)               // Lexeme represents local variable or parameter
            {
                if (varSym.kind == VariableSymKind.PARAMETER)
                {
                    return("\t\tldarg '" + lexeme + "'\n");
                }
                else
                {
                    return("\t\tldloc '" + lexeme + "'\n");
                }
            }
            else               // Lexeme represents global variable
            {
                return("\t\tldsfld int64 Int64Program::'" + lexeme + "'\n");
            }
        }