Пример #1
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);
                }
            }
        }
Пример #2
0
 public GFuncStruct(string p_u, int arityy, FunContainer refe)
 {
     p_or_u    = p_u;
     arity     = arityy;
     refToFunc = refe;
 }