示例#1
0
        public void ParserExpCollection()
        {
            string sourceCode =
                "10 A = 1 + 1 - 2                       \n" +
                "20 A = A + 1 * 7                       \n" +
                "30 A = 1 + A / 8 - ( 11 + 2 )          \n" +
                "40 A = -(A + A) * C                    \n" +
                "50 A = A - C * 1 + B                   \n" +
                "60 A = \"TT\" + \"FF\"                 \n" +
                "70 A = 7 + B : B = 1 + 9               \n" +
                "80 A = 1 + 1 + 2 + A:B = 11 + 9";

            Tokenizer tokenizer = new Tokenizer(sourceCode);
            Parser parser = new Parser(tokenizer);

            parser.Parsing();

            // check statement
            List<Statement> statements = parser.STATEMENTS;

            if (statements.Count != 10)
                throw new Exception("statement count incorrect.");

            //TODO 
        }
示例#2
0
文件: Program.cs 项目: RockyF/GVBASIC
        static void Main(string[] args)
        {
			string path = null;
			if (args.Length > 0) 
				path = args [0];
			else 
				path = "../../../../Bas/_tank.bas";
            // print the file path 
            System.Console.WriteLine("Run file: " + path);

            // read the source
            string sourceCode = System.IO.File.ReadAllText(path);

            // lex  
            Tokenizer tok = new Tokenizer(sourceCode);
            // parser 
            Parser parser = new Parser(tok);
            // runtime
            Runtime rt = new Runtime(parser);
            rt.SetAPI(new DebugAPI());

            rt.Run();

            // wait for key press 
            System.Console.ReadKey();
        }
示例#3
0
        /// <summary>
        /// run the program 
        /// </summary>
        /// <param name="code"></param>
        static public DebugAPI RunProgram( string code )
        {
            Tokenizer tokenizer = new Tokenizer(code);
            Parser parser = new Parser(tokenizer);
            Runtime rt = new Runtime(parser);

            DebugAPI api = new DebugAPI();
            rt.SetAPI(api);

            rt.Run();

            while (!rt.Step()) ;

            return api;
        }
示例#4
0
文件: Runtime.cs 项目: RockyF/GVBASIC
        /// <summary>
        /// constructor 
        /// </summary>
        public Runtime(Parser parser)
        {
            m_parser = parser;

            m_executer = new Dictionary<int, Action<Statement>>()
            {
                { Statement.TYPE_PRINT, doPrint },
                { Statement.TYPE_ASSIGN, doAssign },
                { Statement.TYPE_IF, doIf },
                { Statement.TYPE_DATA, doData },
                { Statement.TYPE_READ, doRead },
                { Statement.TYPE_RESTORE, doRestore },
                { Statement.TYPE_GOTO, doGoto },
                { Statement.TYPE_END, doEnd },
                { Statement.TYPE_FOR_BEGIN, doForBegin },
                { Statement.TYPE_FOR_END, doForEnd },
                { Statement.TYPE_WHILE_BEGIN, onWhileBegin },
                { Statement.TYPE_WHILE_END, onWhileEnd },
                { Statement.TYPE_ON_GOTO, onOnGoto },
                { Statement.TYPE_GOSUB, onGoSub },
                { Statement.TYPE_RETURN, onReturn },
                { Statement.TYPE_POP, onPop },
                { Statement.TYPE_DEF_FN, onDefFn },
                { Statement.TYPE_DIM, onDim },
                { Statement.TYPE_SWAP, onSwap },
                { Statement.TYPE_INPUT, onInput },
                { Statement.TYPE_SIMPLE_CMD, onSimpleCmd },
                { Statement.TYPE_PARAM_CMD, onParamCmd },
            };

            // initial the context 
            m_dataRegion = new DataArea();
            m_symbolTable = new SymbolTable();
            m_forLoopStack = new Stack<ForRecord>();
            m_whileLoopStack = new Stack<WhileRecord>();
            m_goSubStack = new Stack<int>();

            m_innerFunc = new BuildinFunc();
        }
示例#5
0
        public void ParserIf()
        {
            string sourceCode =
                @"10 IF A>1 THEN PRINT C
                  20 IF C=2 THEN PRINT 11 ELSE PRINT 22
                  30 IF B<=1 GOTO 13
                  40 IF E>0 GOTO 11 ELSE 70
                  50 IF F < 6 AND G > 8 THEN PRINT theStr:C=17 ELSE 70";

            Tokenizer tokenizer = new Tokenizer(sourceCode);
            Parser parser = new Parser(tokenizer);

            parser.Parsing();

            // check statement
            List<Statement> statements = parser.STATEMENTS;

            if (statements.Count != 5)
                throw new Exception("statement count incorrect.");
            
            //TODO 

        }