Example #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 
        }
Example #2
0
        /// <summary>
        /// run the program
        /// </summary>
        public void Run()
        {
            try
            {
                // generate the IR
                m_parser.Parsing();

                m_statements = m_parser.STATEMENTS;

                // process the data statement
                List <Statement> removeList = new List <Statement>();
                foreach (Statement s in m_statements)
                {
                    if (s.m_type == Statement.TYPE_DATA)
                    {
                        doData(s);
                        removeList.Add(s);
                    }
                }
                // remove the data statments
                foreach (Statement s in removeList)
                {
                    m_statements.Remove(s);
                }

                // index the line number
                m_lineNumDic = new Dictionary <int, int>();
                for (int i = 0; i < m_statements.Count; i++)
                {
                    Statement s = m_statements[i];

                    s.m_lineIndex = i;

                    if (!m_lineNumDic.ContainsKey(s.m_lineNum))
                    {
                        m_lineNumDic.Add(s.m_lineNum, i);
                    }
                }

                m_isRunning = true;
                m_index     = 0;

                m_apiCall.ProgramStart();
            }
            catch (ErrorCode ec)
            {
                m_apiCall.ErrorCode("?" + ec.Message + " ERROR IN " + m_parser.CUR_LINE_NUM);
            }
        }
Example #3
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 

        }