Exemplo n.º 1
0
		public void GetParser(Lexer m_lexer)
		{
			Serialiser b = new Serialiser(arr);
			b.VersionCheck();
			m_startSymbol = (CSymbol)b.Deserialise();
			m_startSymbol.kids = new ObjectList(); // 4.2a
			m_accept = (ParseState)b.Deserialise();
			m_states = (Hashtable)b.Deserialise();
			literals = (Hashtable)b.Deserialise();
			symbolInfo = (Hashtable)b.Deserialise();
			m_concrete = (bool)b.Deserialise();
			GetEOF(m_lexer);
		}
Exemplo n.º 2
0
		public int[] arr; // defined in generated subclass
	
		public void GetEOF(Lexer yyl)
		{
			EOFSymbol = (EOF)symbols["EOF"];
			if (EOFSymbol==null)
				EOFSymbol = new EOF(yyl);
		}
Exemplo n.º 3
0
		public bool Contains(CSymbol a) { return m_set.Contains(a); }
Exemplo n.º 4
0
		public void ClassInit(SymbolsGen yyp)   
		{
			Special = new CSymbol(yyp); Special.yytext="S'"; 
			EOFSymbol = new EOF(yyp).Resolve();
		}
Exemplo n.º 5
0
		public Hashtable m_transitions = new Hashtable(); // string -> Transition
		public Transition GetTransition(CSymbol s)
		{
			Transition t = (Transition)m_transitions[s.yytext];
			if (t!=null)
				return t;
			return new Transition(this,s);
		}
Exemplo n.º 6
0
		public void AddFirst(CSymbol s, int j) 
		{ 
			for (;j<m_rhs.Count;j++) 
			{
				CSymbol r = (CSymbol)m_rhs[j];
				s.AddFollow(r.m_first);
				if (!r.IsNullable())
					return;
			}
		}
Exemplo n.º 7
0
		public CSymbol[] Prefix(int i)
		{
			CSymbol[] r = new CSymbol[i];
			for (int j=0;j<i;j++)
				r[j] = (CSymbol)m_rhs[j];
			return r;
		}
Exemplo n.º 8
0
		public void ClassInit(SymbolsGen yyp)
		{
			EmptySequence = new CSymbol(yyp); EmptySequence.yytext="e";
			Special = new CSymbol(yyp); Special.yytext="S'";
			EOFSymbol = new EOF(yyp).Resolve();
		}
Exemplo n.º 9
0
 public void AddToRhs(CSymbol s)
 {
     this.m_rhs.Add((object)s);
     this.m_actionsOnly = this.m_actionsOnly && s.IsAction();
 }
Exemplo n.º 10
0
		public override void Print(ParseState ps,CSymbol s)
		{
			base.Print(ps,s);
			while (s.m_symtype==CSymbol.SymType.nodesymbol)
				s = s.m_refSymbol;
			Transition t = (Transition)ps.m_transitions[s.yytext];
			Transition.Follow(t).Print();
		}
Exemplo n.º 11
0
		public override void Print(ParseState ps,CSymbol s)
		{
			base.Print(ps,s);
			Console.Write("  ");
			m_lookAhead.Print();
		}
Exemplo n.º 12
0
		public virtual void Print(ParseState ps,CSymbol s)
		{
			Console.Write("  {0}  {1}  ",s.yytext,str);
			if (m_action!=null)
				m_action.Print();
		}
Exemplo n.º 13
0
	public override void SimpleAction(ParserSimpleAction a) 
	{
		string str = a.yytext.Substring(1, a.yytext.Length-1);
		if (str=="null") 
		{
			m_lexer.yytext = "Null";
			a.m_sym = (new CSymbol(this)).Resolve();
			NewConstructor(ref a.m_sym,", "+m_prod.m_lhs.m_yynum+"){}");
			return;
		}
		if (str.Length==0)
			str = m_prod.m_lhs.yytext;
		CSymbol s = (CSymbol)m_symbols.symbols[str];
		if (s==null) 
		{ // not there: define a new node type
			//Console.WriteLine("Symbol {0} needs defining",str);
			m_lexer.yytext = str;
			s = new CSymbol(this);
			m_symbols.symbols[str] = s;
			s.m_symtype = CSymbol.SymType.nodesymbol;
			s.m_refSymbol = (CSymbol)m_prod.m_lhs;
			s.m_emitted = true;
			m_outFile.WriteLine("public class "+str+" : "+s.m_refSymbol.yytext+" { ");
			m_outFile.WriteLine("  public "+str+"(Parser yyq):base(yyq) { }}");
		} 
		else if (s.m_refSymbol!=null) // 4.5c
		{
			CSymbol t=s; // 4.5d
			while (t!=null && t!=(CSymbol)m_prod.m_lhs)
				t=t.m_refSymbol;
			if (t==null)
				Error(46,m_lexer.m_pch,"Simple action "+s.yytext+" does not match symbol type "+m_prod.m_lhs.yytext); // 4.5d
		}   // 4.5c
		else 
			s.m_refSymbol = (CSymbol)m_prod.m_lhs;
		a.m_sym = s;
		int ch;
		str = ")";
		NextNonWhite(out ch);
		if (ch=='(') 
		{
			ch = m_lexer.GetChar();
			str = ","+GetBracketedSeq(ref ch,')').Substring(1);
			NextNonWhite(out ch);
		}
		if (str==",)") // 4.0d
			str=")";
		string init = "{}";
		if (ch=='{') 
		{
			ch = m_lexer.GetChar();
			string ts = GetBracketedSeq(ref ch,'}');			   // 4.5g
			init = "{ "+m_outname+" yyp=("+m_outname+")yyq;\n"+ ts.Substring(1); // 4.5g 4.5h
			NextNonWhite(out ch);
		}
		init = str + init;
		NewConstructor(ref a.m_sym,init);
	}
Exemplo n.º 14
0
	public override void ClassDefinition(string bas) 
	{
		string line, name;
		int n = m_lexer.yytext.Length;
		line = m_lexer.yytext;
		int num = EmitClassDefin(m_lexer.m_buf,ref m_lexer.m_pch,m_lexer.m_buf.Length,null,bas,out bas,out name,false);
		m_lexer.Advance();
		m_lexer.yytext = name;
		CSymbol s = new CSymbol(this);
		s.m_yynum = num;
		s = s.Resolve();
		s.m_defined = true;
		s.m_emitted = true;
		if (line[1]=='n') 
		{
			s.m_symtype = CSymbol.SymType.nodesymbol;
			if (m_symbols.symbols.Contains(bas))
				s.m_refSymbol = (CSymbol)m_symbols.symbols[bas];
			else
				m_symbols.erh.Error(new CSToolsFatalException(44,s,"Unknown base type "+bas+": reorder declarations?"));
		}
	}
Exemplo n.º 15
0
		public Path(ParseState q,CSymbol[] x) 
		{
			m_states = new ParseState[x.Length+1];
			ParseState c;
			c = m_states[0] = q;
			for (int j=0;j<x.Length;j++)
			{
				int k;
				for (k=j;k<x.Length;k++)
					if (!x[k].IsAction())
						break;
				if (k>=x.Length)
				{
					m_states[j+1] = c;
					continue;
				}
				Transition t = (Transition)c.m_transitions[x[k].yytext];
				if (t==null || t.m_next==null)
				{
					valid = false;
					break;
				}
				c = m_states[j+1] = t.m_next.m_next;
			}
		}
Exemplo n.º 16
0
 public Transition GetTransition(CSymbol s)
 {
     return((Transition)this.m_transitions[(object)s.yytext] ?? new Transition(this, s));
 }
Exemplo n.º 17
0
 public bool Contains(CSymbol a)
 {
     return(this.m_set.Contains((object)a));
 }
Exemplo n.º 18
0
	public PrecReference(Lexer lx,TOKEN t) : base(lx)
	{
		precref = ((CSymbol)t).Resolve();
		new SymbolType(((ptokens)lx).m_sgen,t.yytext,true);
	}
Exemplo n.º 19
0
		public SymbolSet lahead = null; // support for lookahead sets
		public bool Find(CSymbol sym) 
		{
			if (sym.yytext.Equals("Null")) // special case
				return true;
			if (sym.yytext[0]=='\'')
				return true;
			if (stypes==null)
				return false;
			return stypes._Find(sym.yytext)!=null;
		}	
Exemplo n.º 20
0
	// proxies for constructors
	internal void NewConstructor(ref CSymbol s,string str)
	{ // may update s to a new node type
		// we have just seen a new initialiser for s
		if (str.Length==0)
			return;
		CSymbol bas = s;
		string newname;
		for (int variant=1;;variant++)
		{ // get a genuinely new identifier
			newname = String.Format("{0}_{1}", bas.yytext, variant);
			s = (CSymbol)m_symbols.symbols[newname];
			if (s==null)
				break;
		}
		m_lexer.yytext = newname;
		s = (new CSymbol(this)).Resolve();
		s.m_symtype = CSymbol.SymType.nodesymbol;
		s.m_refSymbol = bas;
		s.m_emitted = true;
		m_outFile.WriteLine();
		m_outFile.WriteLine(@"/// <summary/>");
		m_outFile.WriteLine("public class "+newname+" : "+bas.yytext+" {");
		m_outFile.WriteLine(@"/// <summary/>");
		m_outFile.WriteLine(@"/// <param name='yyq'></param>");
		m_outFile.WriteLine("  public "+newname+"(Parser yyq):base(yyq"+str+"}");
	}
Exemplo n.º 21
0
		public SymbolType(SymbolsGen yyp,string name,bool defined) 
		{ 
			Lexer yyl = yyp.m_lexer;
			int p = name.IndexOf("+");
			int num = 0;
			if (p>0)
			{
				num = int.Parse(name.Substring(p+1));
				if (num> yyp.LastSymbol)
					yyp.LastSymbol = num;
				name = name.Substring(0,p);
			}
			yyl.yytext = name;
			CSymbol s = new CSymbol(yyp);
			if (num>0)
				s.m_yynum = num;
			s = s.Resolve();
			if (defined) 
				s.m_defined = true;
			m_name = name; m_next=yyp.stypes; yyp.stypes=this;
		}
Exemplo n.º 22
0
	public override void SimpleAction(ParserSimpleAction a)
	{
		string str = a.yytext.Substring(1, a.yytext.Length-1);
		if (str=="null")
		{
			m_lexer.yytext = "Null";
			a.m_sym = (new CSymbol(this)).Resolve();
			NewConstructor(ref a.m_sym,",\""+m_prod.m_lhs.yytext+"\"){}");
			return;
		}
		if (str.Length==0)
			str = m_prod.m_lhs.yytext;
		CSymbol s = (CSymbol)m_symbols.symbols[str];
		if (s==null)
		{ // not there: define a new node type
			//Console.WriteLine("Symbol {0} needs defining",str);
			m_lexer.yytext = str;
			s = new CSymbol(this);
			m_symbols.symbols[str] = s;
			s.m_symtype = CSymbol.SymType.nodesymbol;
			s.m_refSymbol = (CSymbol)m_prod.m_lhs;
			s.m_emitted = true;
			m_outFile.WriteLine(@"/// <summary/>");
			m_outFile.WriteLine("public class "+str+" : "+s.m_refSymbol.yytext+" { ");
			m_outFile.WriteLine(@"/// <summary/>");
			m_outFile.WriteLine(@"/// <param name='yyq'></param>");
			m_outFile.WriteLine("  public "+str+"(Parser yyq):base(yyq) { }}");
		}
		a.m_sym = s;
		int ch;
		str = ")";
		NextNonWhite(out ch);
		if (ch=='(')
		{
			ch = m_lexer.GetChar();
			str = ","+GetBracketedSeq(ref ch,')').Substring(1);
			NextNonWhite(out ch);
		}
		if (str==",)") // 4.0d
			str=")";
		string init = "{}";
		if (ch=='{')
		{
			ch = m_lexer.GetChar();
			init = "yyp=("+m_outname+")yyq;\n"+ GetBracketedSeq(ref ch,'}');
			NextNonWhite(out ch);
		}
		init = str + init;
		NewConstructor(ref a.m_sym,init);
	}
Exemplo n.º 23
0
		public Transition(ParseState p,CSymbol a) 
		{ 
			m_ps = p; m_A = a; 
			m_tno = p.m_sgen.m_trans++;
			p.m_transitions[a.yytext] = this;
		}
Exemplo n.º 24
0
		public static int Check(CSymbol s, Production p, int d) 
		{
			if (s.m_prec==null)
				return 0;
			int a = CheckType(s.m_prec, PrecType.after,d+1);
			int b = CheckType(s.m_prec, PrecType.left,d+1);
			if (a>b)
				return a - p.m_prec;
			else
				return b - p.m_prec;
		}
Exemplo n.º 25
0
		public bool Accessor(CSymbol[] x) { return new Path(x).Top == this; }
Exemplo n.º 26
0
		public bool CouldStart(CSymbol nonterm) { return false; }
Exemplo n.º 27
0
		public ParseState(SymbolsGen syms,CSymbol acc) 
		{ 
			m_sgen = syms;
			m_state=syms.state++; 
			m_accessingSymbol=acc;
			m_items = new ProdItemList();
		}
Exemplo n.º 28
0
		public Production(SymbolsGen syms) 
		{
			m_lhs=null; 
			m_prec=0; 
			m_pno=syms.pno++; 
			m_actionsOnly = true; 
			syms.prods.Add(this);
		}
Exemplo n.º 29
0
		public bool CheckIn(CSymbol a) 
		{
			if (Contains(a))
				return false;
			AddIn(a);
			return true;
		}
Exemplo n.º 30
0
		public Production(SymbolsGen syms,CSymbol lhs) 
		{
			m_lhs=lhs; 
			m_prec=0;  
			m_pno=syms.pno++;
			m_actionsOnly=true;
			syms.prods.Add(this);
			lhs.m_prods.Add(this);
		}
Exemplo n.º 31
0
		public void AddIn (CSymbol t) 
		{
			m_set[t] = true;
		}
Exemplo n.º 32
0
		public Hashtable m_alias = new Hashtable(); // string->int
		public void AddToRhs(CSymbol s) 
		{
			m_rhs.Add(s);
			m_actionsOnly = m_actionsOnly && s.IsAction();
		}
Exemplo n.º 33
0
		public Path(CSymbol[] x) : this((ParseState)(x[0].m_parser.m_symbols.m_states[0]),x) {}
Exemplo n.º 34
0
 public void AddIn(CSymbol t)
 {
     this.m_set[(object)t] = (object)true;
 }