Exemplo n.º 1
0
        //
        public override void Parse()
        {
            var parser = new ProgramParser(this);

            parser.Parse();

            //
            var token = CurrentToken();

            if (token.m_Text != ".")
            {
                //TODO error:
                Debug.Write("Missing .");
            }



            //try
            //{
            //    while (!((token = NextToken()) is EofToken))
            //    {
            //        var type = (PascalTokenType)token.m_Type;
            //        if (type == PascalTokenType.Identifier)
            //        {
            //            string entry_name = token.m_Text;
            //            var entry = (m_SymbolTableStack as ISymbolTableStack).LookupLocal(entry_name);
            //            if (entry == null)
            //            {
            //                entry = (m_SymbolTableStack as ISymbolTableStack).EnterLocalSymbolTable(entry_name);
            //            }
            //            entry.AppendLineNumber(token.m_LineNumber);
            //        }
            //        else if (type == PascalTokenType.Error)
            //        {
            //            Console.WriteLine("Error token found during parsing.");
            //        }
            //    }
            //}
            //catch (Exception)
            //{
            //    Console.WriteLine("Error during parsing.");
            //}
        }
Exemplo n.º 2
0
        public override void Parse()
        {
            try
            {
                ParseHead();

                //
                (m_SymbolTableStack as SymbolTableStack).Push();

                var program_parser = new ProgramParser(this);
                program_parser.Parse();

                (m_SymbolTableStack as SymbolTableStack).Pop();

                var token = CurrentToken();
                if (token.m_Text != ";")
                {
                    //TODO: error
                    ErrorReporter.RecordError(9, m_Scanner.m_CurrentToken.m_LineNumber);
                    throw new Exception();
                }

                //
                ConsumeCurrentToken();//skip ;
            }
            catch (Exception)
            {
            }

            //if ((PascalTokenType)token.m_Type == PascalTokenType.Procedure)
            //{
            //    //
            //    (m_SymbolTableStack as SymbolTableStack).Push();

            //    var proceduer_parser = new ProcedureParser(this);
            //    proceduer_parser.Parse();

            //    //
            //    SymbolTablePrinter.RecordSymbolTable(m_SymbolTableStack.GetLocalSymbolTable());
            //    (m_SymbolTableStack as SymbolTableStack).Pop();
            //}
        }