예제 #1
0
        //-----------------------------------------------------------
        //<id>//
        public void Visit(Identifier node, int i)
        {
            var variableName = node.AnchorToken.Lexeme;

            if (i == 1)
            {
                if (GlobalVarsTable.Contains(variableName))
                {
                    throw new SemanticError(
                              "Duplicated var: " + variableName,
                              node.AnchorToken);
                }
                else
                {
                    GlobalVarsTable[variableName] = "Global Var";
                }
            }
            else if (i == 2)
            {
                if (FunctionTable.Contains(variableName))
                {
                    throw new SemanticError(
                              "Duplicated function: " + variableName,
                              node.AnchorToken);
                }
                else
                {
                    currentFunc = variableName;
                    FunctionTable[variableName] = new GFuncStruct("u", 0, new FunContainer());
                }
            }
        }
예제 #2
0
        //-----------------------------------------------------------
        //<id>//
        public void Visit(Identifier node, char i)
        {
            var variableName = node.AnchorToken.Lexeme;

            if (i.Equals('f'))
            {
                if (FunctionTable.Contains(variableName))
                {
                    currentFunc = variableName;
                    FunMethods[variableName] = new FunContainer();
                }
            }
            else if (i.Equals('p'))
            {
                var fctemp = FunMethods[currentFunc];
                fctemp.ParticularFunction[variableName] = new DataOfFunc("param", parameterCounter);
                FunMethods[currentFunc] = fctemp;
                parameterCounter++;
            }
            else if (i.Equals('v'))
            {
                var fctemp = FunMethods[currentFunc];
                if (fctemp.ParticularFunction.Contains(variableName))
                {
                    throw new SemanticError(
                              "Duplicated var: " + variableName,
                              node.AnchorToken);
                }
                else
                {
                    fctemp.ParticularFunction[variableName] = new DataOfFunc("local", -1);
                    FunMethods[currentFunc] = fctemp;
                }
            }
            else if (i.Equals('s'))
            {
                var fctemp = FunMethods[currentFunc];
                if (!fctemp.ParticularFunction.Contains(variableName) && !GlobalVarsTable.Contains(variableName))
                {
                    throw new SemanticError(
                              "Undeclared var: " + variableName,
                              node.AnchorToken);
                }
            }
            else if (i.Equals('c') || i.Equals('q'))
            {
                var fctemp = FunMethods[currentFunc];
                if (!fctemp.ParticularFunction.Contains(variableName) && !GlobalVarsTable.Contains(variableName))
                {
                    throw new SemanticError(
                              "Undeclared var: " + variableName,
                              node.AnchorToken);
                }
            }
        }
예제 #3
0
        //-----------------------------------------------------------
        //<decrease>//
        public void Visit(Decrease node, char i)
        {
            var variableName = node.AnchorToken.Lexeme;
            var fctemp       = FunMethods[currentFunc];

            if (!fctemp.ParticularFunction.Contains(variableName) && !GlobalVarsTable.Contains(variableName))
            {
                throw new SemanticError(
                          "Undeclared var: " + variableName,
                          node.AnchorToken);
            }
        }