Ejemplo n.º 1
0
 public Dfa(Nfa nfa) : base(nfa.m_tks)
 {
     m_tokens = m_tks.m_tokens;
     AddNfaNode(nfa);          // the starting node is Closure(start)
     Closure();
     AddActions();             // recursively build the Dfa
 }
Ejemplo n.º 2
0
Archivo: Dfa.cs Proyecto: m33p/radegast
 public Dfa(Nfa nfa)
     : base(nfa.m_tks)
 {
     this.m_tokens = this.m_tks.m_tokens;
     this.AddNfaNode((NfaNode)nfa);
     this.Closure();
     this.AddActions();
 }
Ejemplo n.º 3
0
 // needed after deserialisation
 /// <exclude/>
 public static void SetTokens(YyLexer tks, Hashtable h)
 {
     foreach (Dfa v in h.Values)
     {
         if (v.m_tokens!=null)
             continue;
         v.m_tokens = tks;
         Dfa.SetTokens(tks,v.m_map);
     }
 }
Ejemplo n.º 4
0
		public static void SetTokens(YyLexer tks, Hashtable h) // needed after deserialisation
		{
			foreach (Dfa v in h.Values)
			{
				if (v.m_tokens!=null)
					continue;
				v.m_tokens = tks;
				Dfa.SetTokens(tks,v.m_map);
			}
		}
Ejemplo n.º 5
0
Archivo: Dfa.cs Proyecto: m33p/radegast
 public static void SetTokens(YyLexer tks, Hashtable h)
 {
     foreach (Dfa dfa in (IEnumerable)h.Values)
     {
         if (dfa.m_tokens == null)
         {
             dfa.m_tokens = tks;
             Dfa.SetTokens(tks, dfa.m_map);
         }
     }
 }
Ejemplo n.º 6
0
 public static void SetTokens(YyLexer tks, Hashtable h) // needed after deserialisation
 {
     foreach (Dfa v in h.Values)
     {
         if (v.m_tokens != null)
         {
             continue;
         }
         v.m_tokens = tks;
         Dfa.SetTokens(tks, v.m_map);
     }
 }
Ejemplo n.º 7
0
        public string m_state = "YYINITIAL"; // exposed for debugging (by request)

        public Lexer(YyLexer tks)
        {
            m_state = "YYINITIAL";
            tokens  = tks;
        }
Ejemplo n.º 8
0
 /// <exclude/>
 public Dfa(TokensGen tks)
     : base(tks)
 {
     m_tokens = tks.m_tokens;
 }
Ejemplo n.º 9
0
 /// <exclude/>
 public Dfa(Nfa nfa)
     : base(nfa.m_tks)
 {
     m_tokens = m_tks.m_tokens;
     AddNfaNode(nfa); // the starting node is Closure(start)
     Closure();
     AddActions(); // recursively build the Dfa
 }
 /// <exclude/>
 public Lexer(YyLexer tks)
 {
     m_state="YYINITIAL";
     tokens = tks;
 }
Ejemplo n.º 11
0
	void _Create()
	{
		m_outFile.WriteLine("using System;using Tools;");
		m_tokens = new YyLexer(erh);
		string buf = "";
		string str = "";
		string name="";
		string startsym;
		Nfa nfa;
		int p,q,max;
		Console.WriteLine("Reading Input File"); 
		while (!m_inFile.Eof()) 
		{
			buf = m_inFile.ReadLine();
			startsym = "YYINITIAL";
			max = buf.Length;
			p = 0;
			if (!White(buf,ref p,max))
				continue;
			if (buf[p]=='%') 
			{ // directive
				// %lexer
				if(buf.Length>=p+6 && "%lexer".Equals(buf.Substring(p,6))) 
				{
					m_lexerseen = true;
					p+=6; 
					if (!White(buf,ref p, max))
						continue;
					q = p;
					NonWhite(buf,ref p, max);
					if (q!=p)
						m_outname = buf.Substring(q,p-q);
					continue;
				}
				// %encoding
				if (buf.Length>=p+9 && "%encoding".Equals(buf.Substring(p,9)))
				{
					p+=9; White(buf,ref p, max);
					q = p;
					NonWhite(buf,ref p, max);
					m_tokens.InputEncoding = buf.Substring(q,p-q);
					continue;
				}
				// %namespace
				if (buf.Length>=p+10 && "%namespace".Equals(buf.Substring(p,10))) 
				{
					p+=10; White(buf,ref p,max);
					q = p;
					NonWhite(buf,ref p,max);
					m_outFile.WriteLine("namespace "+buf.Substring(q,p-q)+" {");
					m_namespace = true;
					continue;
				}
				// %define
				if(buf.Length>=p+7 && "%define".Equals(buf.Substring(p,7))) 
				{
					p+=7; White(buf,ref p,max);
					q = p;
					if (!NonWhite(buf,ref p,max)) 
					{
						erh.Error(new CSToolsException(44,"Bad define"));
						continue;
					}
					name=buf.Substring(q,p-q);
					p++;
					if (White(buf,ref p,max))
						defines[name]=buf.Substring(p,max-p);
				} 
				else
					// % token/node
					if (buf.Length>=p+6 && "%token".Equals(buf.Substring(p,6)))
					EmitClassDefin(buf,ref p,max,m_inFile,"TOKEN", out str,out name,true);
				else if (buf.Length>=p+5 && "%node".Equals(buf.Substring(p,5)))
					EmitClassDefin(buf,ref p,max,m_inFile,"NODE",out str,out name,true);
				else if (buf.Length>=p+2 && "%{".Equals(buf.Substring(p,2)))
					CopyCode();
				else if (buf.Length>=p+9 && "%declare{".Equals(buf.Substring(p,9))) 
				{
					p += 8;
					m_actvars = ToBraceIfFound(ref buf,ref p,ref max,m_inFile);
					m_actvars = m_actvars.Substring(1,m_actvars.Length-2);
				} 
				else
					m_tokens.erh.Error(new CSToolsException(8,"Unknown directive "+buf.Substring(p,max-p)));
				continue;
			} 
			else if (buf[p]=='<') 
			{  // startstate
				q = p++;
				while (p<max && buf[p]!='>')
					p++;
				if (p++ ==max) 
				{
					m_tokens.erh.Error(new CSToolsException(25,"Bad startsymbol"));
					continue;
				}
				startsym = buf.Substring(q+1,p-q-2);
				White(buf, ref p, max);
			}
			q=p; // can't simply look for nonwhite space here because embedded spaces
			GetRegex(buf,ref p,max);
			string trgx = buf.Substring(q,p-q);
			if (m_tokens.toupper)
				trgx = trgx.ToUpper();
			Regex rgx = new Regex(this,q,trgx);
			Nfa nfa1= new Nfa(this,rgx);
			if (!m_startstates.Contains(startsym))
				m_startstates[startsym] = new Nfa(this);
			nfa = (Nfa)m_startstates[startsym];
			nfa.AddEps(nfa1);
			White(buf,ref p,max);
			m_actions[nfa1.m_end.m_state] = nfa1.m_end;
			// handle multiline actions enclosed in {}
			nfa1.m_end.m_sTerminal = ToBraceIfFound(ref buf,ref p, ref max,m_inFile);
			// examine action string
			if (nfa1.m_end.m_sTerminal.Length>0 && nfa1.m_end.m_sTerminal[0] == '%') 
			{
				string tokClass,b = nfa1.m_end.m_sTerminal;
				q = 1;
				max = b.Length;
				int n;
				for (n=0;q<max&&b[q]!=' '&&b[q]!='\t'&&b[q]!='\n'&&b[q]!='{'&&b[q]!=':';q++,n++) // extract the class name
					;
				tokClass = b.Substring(1,n); // new-style auto token construction
				object ob = m_tokens.tokens[tokClass];
				TokClassDef t = (TokClassDef)ob;
				bool isNew = (t==null);
				// check for initialisation action following %name
				string init = b.Substring(n+1,b.Length-n-1);
				string bas1 = "TOKEN";
				bool haveInit = false;
				for (int j=0;j<init.Length;j++)
					if (init[j]=='{') 
					{
						haveInit = true;
						break;
					} 
					else if (init[j]==':') 
					{
						bas1 = "";
						for (;init[j]==' '||init[j]=='\r';j++)
							;
						for (;init[j]!=' '&&init[j]!='\t'&&init[j]!='{'&&init[j]!='\n';j++)
							bas1 += init[j];
						break;
					}
				if (isNew && tokClass!="TOKEN") 
				{ // this token class has not been declared. Do so now
					bool isNode = (m_tokens.tokens[bas1]!=null);
					t = new TokClassDef(this,tokClass,bas1); // updates TOKEN.tokens
					m_outFile.WriteLine("//%{0}+{1}",tokClass,t.m_yynum);
					m_outFile.Write("public class {0} : {1}",tokClass,bas1);
					m_outFile.WriteLine("{ public override string yyname { get { return \""+tokClass+"\";}}");
					m_outFile.WriteLine("public override int yynum { get { return "+t.m_yynum+"; }}");
					m_outFile.WriteLine(" public "+tokClass+"(Lexer yyl):base(yyl) {}}");
				}
				if (haveInit && init.IndexOf("%except")<0) 
				{
					init = init.Replace("yylval","yymval"); // yuk: avoid the next line munging yylval
					init = FixActions(init);
					init = init.Replace("yymval","yylval");
					nfa1.m_end.m_sTerminal = "%"+NewConstructor(t,init);
				}
			} 
		}
		if (!m_lexerseen)
			m_tokens.erh.Error(new CSToolsException(26,"No %lexer directive detected: possibly incorrect text encoding?"));
		Console.WriteLine("Constructing DFAs");
		foreach (string s in m_startstates.Keys)
		{
			Dfa d = new Dfa((Nfa)m_startstates[s]);
			m_tokens.starts[s] = d;
			if (d.m_actions!=null)
				Console.WriteLine("Warning: This lexer script generates an infinite token stream on bad input");
		}
		Console.WriteLine("Output phase"); 
		Emit(m_actions,m_actvars,m_namespace,m_showDfa);
		Console.WriteLine("End of Create");
        object o = m_tokens.starts["YYINITIAL"];
        if (o == null)
            Console.WriteLine("Warning: No lexer");
        else if (((Dfa)o).m_actions!=null) // repeat the above warning
			Console.WriteLine("Warning: This lexer script generates an infinite token stream on bad input"); 
	}
Ejemplo n.º 12
0
public LSLTokens(YyLexer tks):base(tks){}
Ejemplo n.º 13
0
public PCLexer(YyLexer tks):base(tks){}
Ejemplo n.º 14
0
Archivo: Dfa.cs Proyecto: m33p/radegast
 public Dfa(TokensGen tks)
     : base(tks)
 {
     this.m_tokens = tks.m_tokens;
 }
Ejemplo n.º 15
0
 public Tfactory(YyLexer tks, string cls_name, TCreator cr)
 {
     tks.types[cls_name] = cr;
 }
Ejemplo n.º 16
0
/// <exclude/>
public Exam(YyLexer tks):base(tks){}
Ejemplo n.º 17
0
 public Lexer(YyLexer tks)
 {
     this.m_state = "YYINITIAL";
     this.tokens  = tks;
 }
 /// <exclude/>
 public Tfactory(YyLexer tks,string cls_name,TCreator cr)
 {
     tks.types[cls_name] = cr;
 }
/// <exclude/>
public cs0tokens(YyLexer tks):base(tks){}
Ejemplo n.º 20
0
 public Tfactory(YyLexer tks, string cls_name, TCreator cr)
 {
     tks.types[(object)cls_name] = (object)cr;
 }