Пример #1
0
 internal void Pop(ref ParseStackEntry elt, int depth, SYMBOL ns)
 {
     for (; this.m_stack.Count > 0 && depth > 0; --depth)
     {
         elt = (ParseStackEntry)this.m_stack.Pop();
         if (this.m_symbols.m_concrete)
         {
             ns.kids.Push((object)elt.m_value);
         }
     }
     if (depth == 0)
     {
         return;
     }
     this.m_symbols.erh.Error(new CSToolsException(14, this.m_lexer, "Pop failed"));
 }
Пример #2
0
        public override void Pass(ref ParseStackEntry top)
        {
            Parser yyps = top.yyps;
            SYMBOL ns   = this.m_action.Action(yyps);

            yyps.m_ungot = top.m_value;
            if (yyps.m_debug)
            {
                Console.WriteLine("about to pop {0} count is {1}", (object)this.m_depth, (object)yyps.m_stack.Count);
            }
            yyps.Pop(ref top, this.m_depth, ns);
            if (ns.pos == 0)
            {
                ns.pos = top.m_value.pos;
            }
            top.m_value = ns;
        }
Пример #3
0
        public ParseStackEntry StackAt(int ix)
        {
            int count = this.m_stack.Count;

            if (this.m_stkdebug)
            {
                Console.WriteLine("StackAt({0}),count {1}", (object)ix, (object)count);
            }
            ParseStackEntry parseStackEntry = (ParseStackEntry)this.m_stack[ix];

            if (parseStackEntry == null)
            {
                return(new ParseStackEntry(this, 0, (SYMBOL)this.m_symbols.Special));
            }
            if (parseStackEntry.m_value is Null)
            {
                return(new ParseStackEntry(this, parseStackEntry.m_state, (SYMBOL)null));
            }
            if (this.m_stkdebug)
            {
                Console.WriteLine(parseStackEntry.m_value.yyname);
            }
            return(parseStackEntry);
        }
Пример #4
0
 public recoveredError(Parser yyp, ParseStackEntry s)
     : base(yyp, s)
 {
 }
Пример #5
0
		public override void Pass(ref ParseStackEntry top) 
		{
			Parser yyp = top.yyps;
			SYMBOL ns = m_action.Action(yyp); // before we change the stack
			yyp.m_ungot = top.m_value;
			if (yyp.m_debug)
				Console.WriteLine("about to pop {0} count is {1}",m_depth,yyp.m_stack.Count);
			yyp.Pop(ref top,m_depth,ns);
			if (ns.pos==0)
				ns.pos = top.m_value.pos;  // Guess symbol position
			top.m_value = ns;
		}
Пример #6
0
		public override void Pass(ref ParseStackEntry top) 
		{
			Parser yyp = top.yyps;
			if(m_action==null) 
			{
				yyp.Push(top);
				top = new ParseStackEntry(yyp,m_next.m_state,yyp.NextSym());
			} 
			else 
			{
				yyp.Push(new ParseStackEntry(yyp,top.m_state,m_action.Action(yyp)));
				top.m_state = m_next.m_state;
			}
		}
Пример #7
0
		public virtual void Pass(ref ParseStackEntry top) {}
Пример #8
0
		public recoveredError(Parser yyp,ParseStackEntry s):base(yyp,s) {}
Пример #9
0
		public error(Parser yyp,ParseStackEntry s):base(yyp) { state=s.m_state; sym=s.m_value; } //4.4c
Пример #10
0
		internal void Pop(ref ParseStackEntry elt, int depth, SYMBOL ns) 
		{
			for (;m_stack.Count>0 && depth>0;depth--) 
			{
				elt = (ParseStackEntry)m_stack.Pop();
				if (m_symbols.m_concrete) // building the concrete syntax tree
					ns.kids.Push(elt.m_value); // else will be garbage collected
			}
			if (depth!=0) 
				m_symbols.erh.Error(new CSToolsException(14,m_lexer,"Pop failed"));
		}
Пример #11
0
		internal void Push(ParseStackEntry elt) 
		{
			m_stack.Push(elt);
		}
Пример #12
0
		// The Parsing Algorithm
		SYMBOL Parse() 
		{
			ParserEntry pe;
			SYMBOL newtop;
			Create();
			ParseStackEntry top = new ParseStackEntry(this,0,NextSym()); 
			try 
			{
				for (;;) 
				{
					string cnm = top.m_value.yyname; 
					if (m_debug) 
					{
						if (cnm.Equals("TOKEN"))
							Console.WriteLine(String.Format("State {0} with {1} \"{2}\"", top.m_state, cnm,((TOKEN)top.m_value).yytext));
						else
							Console.WriteLine(String.Format("State {0} with {1}", top.m_state, cnm));
					}
					if (top.m_value!=null && top.m_value.Pass(m_symbols,top.m_state, out pe))
						pe.Pass(ref top);
					else if (top.m_value==m_symbols.EOFSymbol) 
					{
						if (top.m_state==m_symbols.m_accept.m_state) 
						{ // successful parse
							Pop(ref top,1,m_symbols.m_startSymbol);
							if (m_symbols.erh.counter>0)
								return new recoveredError(this,top);
							newtop = top.m_value; // extract the return value
							top.m_value = null;
							return newtop;
						}
						if (!Error(ref top,"Unexpected EOF")) // unrecovered error
							return top.m_value;
					} 
					else if (!Error(ref top,"syntax error")) // unrecovered error
						return top.m_value;
					if (m_debug) 
					{
						object ob = null;
						if (top.m_value!=null) 
						{
							ob = top.m_value.m_dollar;
							Console.WriteLine("In state {0} top {1} value {2}",top.m_state,top.m_value.yyname,(ob==null)?"null":ob.GetType().Name);
							if (ob!=null && ob.GetType().Name.Equals("Int32"))
								Console.WriteLine((int)ob);
							else 
								((SYMBOL)(top.m_value)).Print();
						} 
						else 
							Console.WriteLine("In state {0} top NULL",top.m_state);
					}
				}
				// not reached
			} 
			catch(CSToolsStopException ex) // stop parsing
			{
				if (m_symbols.erh.throwExceptions)
					throw ex;						// 4.5b
				m_symbols.erh.Report(ex);			// 4.5b
			}
			return null;
		}
Пример #13
0
		protected bool Error(ref ParseStackEntry top, string str) 
		{
			SYMBOL er = (SYMBOL)new error(this,top);  // 4.4c
			if (m_debug)
				Console.WriteLine("Error encountered: "+str);
			er.pos = top.m_value.pos;
			ParserEntry pe;
			if (m_symbols.symbolInfo[0]!=null && m_symbols.erh.counter<1000) // 4.4c
			// first pop the stack until we find an item that can pass error
			for (;top!=null && m_stack.Count>0; Pop(ref top,1,er)) 
			{
				if (m_debug)
					Console.WriteLine("Error recovery uncovers state {0}",top.m_state);
				if (er.Pass(m_symbols,top.m_state, out pe)) 
				{
					SYMBOL oldtop = top.m_value; 
					top.m_value = er;  
					pe.Pass(ref top); // pass the error symbol
					// now discard tokens until we find one we can pass
					while (top.m_value!=m_symbols.EOFSymbol && !top.m_value.Pass(m_symbols,top.m_state, out pe)) 
					{
						SYMBOL newtop;
						if (pe!=null && pe.IsReduce()) 
						{
							newtop = null;
							if (pe.m_action!=null)
								newtop = pe.m_action.Action(this); // before we change the stack
							m_ungot = top.m_value;
							Pop(ref top,((ParserReduce)pe).m_depth,er);
							newtop.pos = top.m_value.pos;
							top.m_value = newtop;
						} 
						else 
						{ // discard it
							string cnm = top.m_value.yyname;
							if (m_debug) 
							{
								if (cnm=="TOKEN")
									Console.WriteLine("Error recovery discards literal {0}",(string)((TOKEN)top.m_value).yytext);
								else
									Console.WriteLine("Error recovery discards token {0}",cnm);
							}
							top.m_value = NextSym();
						}
					}
					if (m_debug)
						Console.WriteLine("Recovery complete");
					m_symbols.erh.counter++;
					return true;
				}
			}
			m_symbols.erh.Error(new CSToolsException(13,m_lexer,er.pos,"syntax error",str)); 
			top.m_value = er;
			return false;
		}
Пример #14
0
        protected bool Error(ref ParseStackEntry top, string str)
        {
            SYMBOL ns = (SYMBOL) new error(this, top);

            if (this.m_debug)
            {
                Console.WriteLine("Error encountered: " + str);
            }
            ns.pos = top.m_value.pos;
            if (this.m_symbols.symbolInfo[(object)0] != null && this.m_symbols.erh.counter < 1000)
            {
                while (top != null && this.m_stack.Count > 0)
                {
                    if (this.m_debug)
                    {
                        Console.WriteLine("Error recovery uncovers state {0}", (object)top.m_state);
                    }
                    ParserEntry entry;
                    if (ns.Pass(this.m_symbols, top.m_state, out entry))
                    {
                        SYMBOL symbol1 = top.m_value;
                        top.m_value = ns;
                        entry.Pass(ref top);
                        while (top.m_value != this.m_symbols.EOFSymbol && !top.m_value.Pass(this.m_symbols, top.m_state, out entry))
                        {
                            if (entry != null && entry.IsReduce())
                            {
                                SYMBOL symbol2 = (SYMBOL)null;
                                if (entry.m_action != null)
                                {
                                    symbol2 = entry.m_action.Action(this);
                                }
                                this.m_ungot = top.m_value;
                                this.Pop(ref top, ((ParserReduce)entry).m_depth, ns);
                                symbol2.pos = top.m_value.pos;
                                top.m_value = symbol2;
                            }
                            else
                            {
                                string yyname = top.m_value.yyname;
                                if (this.m_debug)
                                {
                                    if (yyname == "TOKEN")
                                    {
                                        Console.WriteLine("Error recovery discards literal {0}", (object)((TOKEN)top.m_value).yytext);
                                    }
                                    else
                                    {
                                        Console.WriteLine("Error recovery discards token {0}", (object)yyname);
                                    }
                                }
                                top.m_value = this.NextSym();
                            }
                        }
                        if (this.m_debug)
                        {
                            Console.WriteLine("Recovery complete");
                        }
                        ++this.m_symbols.erh.counter;
                        return(true);
                    }
                    this.Pop(ref top, 1, ns);
                }
            }
            this.m_symbols.erh.Error(new CSToolsException(13, this.m_lexer, ns.pos, "syntax error", str));
            top.m_value = ns;
            return(false);
        }
Пример #15
0
 internal void Push(ParseStackEntry elt)
 {
     this.m_stack.Push((object)elt);
 }
Пример #16
0
        private SYMBOL Parse()
        {
            this.Create();
            ParseStackEntry s = new ParseStackEntry(this, 0, this.NextSym());

            try
            {
                while (true)
                {
                    do
                    {
                        string yyname = s.m_value.yyname;
                        if (this.m_debug)
                        {
                            if (yyname.Equals("TOKEN"))
                            {
                                Console.WriteLine(string.Format("State {0} with {1} \"{2}\"", (object)s.m_state, (object)yyname, (object)((TOKEN)s.m_value).yytext));
                            }
                            else
                            {
                                Console.WriteLine(string.Format("State {0} with {1}", (object)s.m_state, (object)yyname));
                            }
                        }
                        ParserEntry entry;
                        if (s.m_value != null && s.m_value.Pass(this.m_symbols, s.m_state, out entry))
                        {
                            entry.Pass(ref s);
                        }
                        else if (s.m_value == this.m_symbols.EOFSymbol)
                        {
                            if (s.m_state == this.m_symbols.m_accept.m_state)
                            {
                                this.Pop(ref s, 1, (SYMBOL)this.m_symbols.m_startSymbol);
                                if (this.m_symbols.erh.counter > 0)
                                {
                                    return((SYMBOL) new recoveredError(this, s));
                                }
                                SYMBOL symbol = s.m_value;
                                s.m_value = (SYMBOL)null;
                                return(symbol);
                            }
                            if (!this.Error(ref s, "Unexpected EOF"))
                            {
                                return(s.m_value);
                            }
                        }
                        else if (!this.Error(ref s, "syntax error"))
                        {
                            return(s.m_value);
                        }
                    }while (!this.m_debug);
                    if (s.m_value != null)
                    {
                        object dollar = s.m_value.m_dollar;
                        Console.WriteLine("In state {0} top {1} value {2}", (object)s.m_state, (object)s.m_value.yyname, dollar != null ? (object)dollar.GetType().Name : (object)"null");
                        if (dollar != null && dollar.GetType().Name.Equals("Int32"))
                        {
                            Console.WriteLine((int)dollar);
                        }
                        else
                        {
                            s.m_value.Print();
                        }
                    }
                    else
                    {
                        Console.WriteLine("In state {0} top NULL", (object)s.m_state);
                    }
                }
            }
            catch (CSToolsStopException ex)
            {
                if (this.m_symbols.erh.throwExceptions)
                {
                    throw ex;
                }
                this.m_symbols.erh.Report((CSToolsException)ex);
            }
            return((SYMBOL)null);
        }