示例#1
0
        public ProgNode Parse(string code)
        {
            lex.init(code);
            ProgNode prg  = new ProgNode();
            StmtNode stmt = parseStmt();

            while (stmt != null)
            {
                prg.stmts.Add(stmt);
                stmt = parseStmt();
            }
            return(prg);
        }
示例#2
0
 public static void Check(ProgNode tree)
 {
     errors.Clear();
     funcs.Clear();
     cnsts.Clear();
     funcs.Add(new FncDecStmtNode()
     {
         ID = new LexUnit()
         {
             lexeme = "cos"
         }, paramList = new List <LexUnit>()
         {
             new LexUnit()
             {
                 lexeme = "x"
             }
         }
     });
     funcs.Add(new FncDecStmtNode()
     {
         ID = new LexUnit()
         {
             lexeme = "sin"
         }, paramList = new List <LexUnit>()
         {
             new LexUnit()
             {
                 lexeme = "x"
             }
         }
     });
     funcs.Add(new FncDecStmtNode()
     {
         ID = new LexUnit()
         {
             lexeme = "tan"
         }, paramList = new List <LexUnit>()
         {
             new LexUnit()
             {
                 lexeme = "x"
             }
         }
     });
     funcs.Add(new FncDecStmtNode()
     {
         ID = new LexUnit()
         {
             lexeme = "sqrt"
         }, paramList = new List <LexUnit>()
         {
             new LexUnit()
             {
                 lexeme = "x"
             }
         }
     });
     funcs.Add(new FncDecStmtNode()
     {
         ID = new LexUnit()
         {
             lexeme = "ln"
         }, paramList = new List <LexUnit>()
         {
             new LexUnit()
             {
                 lexeme = "x"
             }
         }
     });
     funcs.Add(new FncDecStmtNode()
     {
         ID = new LexUnit()
         {
             lexeme = "log"
         }, paramList = new List <LexUnit>()
         {
             new LexUnit()
             {
                 lexeme = "x"
             }
         }
     });
     funcs.Add(new FncDecStmtNode()
     {
         ID = new LexUnit()
         {
             lexeme = "abs"
         }, paramList = new List <LexUnit>()
         {
             new LexUnit()
             {
                 lexeme = "x"
             }
         }
     });
     cnsts.Push("pi");
     cnsts.Push("e");
     foreach (var stmt in tree.stmts)
     {
         Check(stmt);
     }
 }