예제 #1
0
//-----------------------------------------------------------
        public void Visit(NVarDef node)
        {
            Console.WriteLine($"+++++++++++++++ NVARDEF ++++++++++++++++");

            var variableName = node.AnchorToken.Lexeme;

            //Console.WriteLine($"variable: {variableName}");
            if (pasones == 0)
            {
                if (globVars.Contains(variableName))
                {
                    throw new SemanticError(
                              "Duplicated variable: " + variableName,
                              node.AnchorToken);
                }
                else
                {
                    //Console.WriteLine($"Agregando Variable: {variableName} ");
                    globVars.Add(variableName);
                }
            }
            else if (pasones == 1)
            {
                if (Table[nombreFuncion].locTable.ContainsKey(node.AnchorToken.Lexeme))
                {
                    throw new SemanticError("parameter and local variable names have to be unique on function: " + nombreFuncion,
                                            node.AnchorToken);
                }

                Sharmuta sha = new Sharmuta(node.AnchorToken.Lexeme, false, null);
                Table[nombreFuncion].locTable[node.AnchorToken.Lexeme] = sha;
            }
        }
예제 #2
0
 public void Visit(NParameter node)
 {
     Console.WriteLine($"+++++++++++++++ NParameter ++++++++++++++++");
     if (pasones == 1)
     {
         Sharmuta sha = new Sharmuta(node.AnchorToken.Lexeme, true, variablePosition);
         Table[nombreFuncion].locTable[node.AnchorToken.Lexeme] = sha;
         variablePosition++;
     }
     VisitChildren(node);
 }