Exemplo n.º 1
0
 // Returns NExprPrimary or any of subproduction nodes
 public Node ExprPrimary()
 {
     if (CurrentToken == TokenCategory.IDENTIFIER)
     {
         Token identifier = Expect(TokenCategory.IDENTIFIER);
         if (CurrentToken == TokenCategory.PARENTHESIS_LEFT)
         {
             NFunCall nFunCall = new NFunCall()
             {
                 AnchorToken = identifier
             };
             nFunCall.Add(FunCall());
             return(nFunCall);
         }
         else
         {
             NExprPrimary nExprPrimary = new NExprPrimary();
             nExprPrimary.AnchorToken = identifier;
             return(nExprPrimary);
         }
     }
     else if (firstOfLitAlt.Contains(CurrentToken))
     {
         return(LitAlt());
     }
     else if (CurrentToken == TokenCategory.PARENTHESIS_LEFT)
     {
         Expect(TokenCategory.PARENTHESIS_LEFT);
         Node resultingNode = Expr();
         Expect(TokenCategory.PARENTHESIS_RIGHT);
         return(resultingNode);
     }
     return(new Node());
 }
Exemplo n.º 2
0
 public string Visit(NExprPrimary nExprPrimary)
 {
     if (nExprPrimary.children.Count == 0)
     {
         Token  anchorToken = nExprPrimary.AnchorToken;
         string lexeme      = anchorToken.Lexeme;
         return(loadVariable(lexeme));
     }
     return(GenericChildVisitor(nExprPrimary));
 }
 public void Visit(NExprPrimary nExprPrimary)
 {
     if (nExprPrimary.children.Count == 0)
     {
         Token  anchorToken = nExprPrimary.AnchorToken;
         string lexeme      = anchorToken.Lexeme;
         if (currentFunction.GetLocalVariableSymbolByLexeme(lexeme) == null && semanticAnalyzer.GetGlobalVariableSymbolByLexeme(lexeme) == null)
         {
             throw new SemanticError("Variable not in scope", anchorToken);
         }
     }
     GenericChildVisitor(nExprPrimary);
 }
Exemplo n.º 4
0
//-----------------------------------------------------------
        public void Visit(NExprPrimary node)
        {
            Console.WriteLine($"+++++++++++++++ NExprPrimary ++++++++++++++++");

            if (pasones == 2)
            {
                if (!Table[nombreFuncion].locTable.ContainsKey(node.AnchorToken.Lexeme))
                {
                    if (!globVars.Contains(node.AnchorToken.Lexeme))
                    {
                        throw new SemanticError("variable [" + node.AnchorToken.Lexeme + "] has not been declared ",
                                                node.AnchorToken);
                    }
                }
            }

            //Console.WriteLine($"\t\t\t\t\t\t\t\t+++++++++++++++ 3er pason  {node.AnchorToken.Lexeme}  ++++++++++++++++");

            //VisitBinaryOperator('*', node /*, Type.INT*/);
            VisitChildren(node);
        }