public void Visit(NFunDefList node)
 {
     foreach (NFunDef nFunDef in node)
     {
         Visit((dynamic)nFunDef);
     }
 }
Beispiel #2
0
        // Appends NFunDef to nFunDefList
        public void FunDef(NFunDefList nFunDefList)
        {
            NFunDef nFunDef = new NFunDef()
            {
                AnchorToken = Expect(TokenCategory.IDENTIFIER)
            };
            NParameterList nParameterList = new NParameterList();

            Expect(TokenCategory.PARENTHESIS_LEFT);
            if (CurrentToken == TokenCategory.IDENTIFIER)
            {
                nParameterList.Add(new NParameter()
                {
                    AnchorToken = Expect(TokenCategory.IDENTIFIER)
                });
                while (CurrentToken == TokenCategory.COMMA)
                {
                    Expect(TokenCategory.COMMA);
                    nParameterList.Add(new NParameter()
                    {
                        AnchorToken = Expect(TokenCategory.IDENTIFIER)
                    });
                }
            }
            Expect(TokenCategory.PARENTHESIS_RIGHT);
            Expect(TokenCategory.CURLY_BRACE_LEFT);
            NVarDefList nVarDefList = (NVarDefList)VarDefList();
            NStmtList   nStmtList   = (NStmtList)StmtList();

            Expect(TokenCategory.CURLY_BRACE_RIGHT);
            nFunDef.Add(nParameterList);
            nFunDef.Add(nVarDefList);
            nFunDef.Add(nStmtList);
            nFunDefList.Add(nFunDef);
        }
        public string Visit(NFunDefList nFunDefList)
        {
            string retVal = "";

            foreach (NFunDef nFunDef in nFunDefList)
            {
                retVal += Visit((dynamic)nFunDef);
            }
            return(retVal);
        }
        //-----------------------------------------------------------

        public string Visit(NProgram nProgram)
        {
            NVarDefList nVarDefList = (NVarDefList)nProgram[0];
            NFunDefList nFunDefList = (NFunDefList)nProgram[1];

            return("// Code generated by the int64 compiler.\n\n"
                   + ".assembly 'int64' {}\n\n"
                   + ".assembly extern 'int64lib' {}\n\n"
                   + ".class public 'Int64Program' extends ['mscorlib']'System'.'Object' {\n"
                   + Visit((dynamic)nVarDefList)
                   + Visit((dynamic)nFunDefList)
                   + "}\n");
        }
Beispiel #5
0
 public void Visit(NFunDefList node)
 {
     foreach (NFunDef funDef in node)
     {
         FunctionSym newFuncSym = new FunctionSym(funDef.AnchorToken, FunctionSymKind.USER_DEFINED);
         // Add parameters to local scope
         foreach (NParameter param in funDef[0])
         {
             VariableSym newParam = new VariableSym(param.AnchorToken, VariableSymKind.PARAMETER);
             newFuncSym.AddLocalVariable(newParam);
         }
         // Add variables to local scope
         foreach (NVarDef variable in funDef[1])
         {
             VariableSym newVariable = new VariableSym(variable.AnchorToken, VariableSymKind.REGULAR);
             newFuncSym.AddLocalVariable(newVariable);
         }
         semanticAnalyzer.AddFunction(newFuncSym);
     }
 }
Beispiel #6
0
        // Returns NProgram
        public Node Program()
        {
            NProgram    nProgram    = new NProgram();
            NVarDefList nVarDefList = new NVarDefList();
            NFunDefList nFunDefList = new NFunDefList();

            while (firstOfProgram.Contains(CurrentToken))
            {
                if (CurrentToken == TokenCategory.VAR)
                {
                    VarDef(nVarDefList);
                }
                else if (CurrentToken == TokenCategory.IDENTIFIER)
                {
                    FunDef(nFunDefList);
                }
                else if (CurrentToken == TokenCategory.EOF)
                {
                    break;
                }
                else
                {
                    throw new SyntaxError(firstOfProgram, tokenStream.Current);
                }
            }
            if (!firstOfProgram.Contains(CurrentToken))
            {
                throw new SyntaxError(new HashSet <TokenCategory>()
                {
                    TokenCategory.IDENTIFIER,
                    TokenCategory.VAR,
                    TokenCategory.EOF
                }
                                      , tokenStream.Current);
            }
            nProgram.Add(nVarDefList);
            nProgram.Add(nFunDefList);
            return(nProgram);
        }
 public void Visit(NFunDefList node)
 {
     Console.WriteLine($"+++++++++++++++ NFUNDEFLIST ++++++++++++++++");
     VisitChildren(node);
 }