Example #1
0
 public CsReader(CsReader inf, Encoding enc)
 {
     this.fname    = inf.fname;
     this.m_stream = !(inf.m_stream is StreamReader) ? (TextReader) new StreamReader(inf.m_stream.ReadToEnd()) : (TextReader) new StreamReader(((StreamReader)inf.m_stream).BaseStream, enc);
     this.state    = CsReader.State.copy;
     this.back     = -1;
 }
Example #2
0
		public int EmitClassDefin(string b,ref int p,int max,CsReader inf,string defbas,out string bas, out string name,bool lx) 
		{
			name = ""; 
			bas = defbas;
			NonWhite(b,ref p,max);
			White(b,ref p,max);
			for(;p<max&&b[p]!=':'&&b[p]!=';';p++)
				name += b[p];
			if (b[p]==':') 
				for(p++,bas="";p<max&&b[p]!=';';p++)
					bas += b[p];
			if (b[p]!=';')
				Error(48,p,"Bad script");
			int num = new TokClassDef(this,name,bas).m_yynum;
			m_outFile.WriteLine("//%+{0}+{1}",name,num);
			m_outFile.Write("public class ");
			m_outFile.Write(name);
			m_outFile.Write(" : "+bas);
			m_outFile.WriteLine("{");
			m_outFile.WriteLine("public override string yyname { get { return \""+name+"\"; }}");
			m_outFile.WriteLine("public override int yynum { get { return "+num+"; }}");
			if (lx) 
				m_outFile.WriteLine("public "+name+"(Lexer yym):base(yym){ }}");
			else 
				m_outFile.WriteLine("public "+name+"(Parser yyq):base(yyq){ }}");
			return num;
		}
Example #3
0
 public CsReader(CsReader inf, Encoding enc)
 {
     if (inf.m_stream is StreamReader)
     {
         m_stream = new StreamReader(((StreamReader)inf.m_stream).BaseStream, enc);
     }
     else
     {
         m_stream = new StreamReader(inf.m_stream.ReadToEnd());
     }
     state = State.copy; back = -1;
 }
Example #4
0
 public void Start(CsReader inFile)
 {
     m_state       = "YYINITIAL"; // 4.3e
     inFile        = new CsReader(inFile, m_tokens.m_encoding);
     m_LineManager = inFile.lm;
     if (!inFile.Eof())
     {
         for (m_buf = inFile.ReadLine(); !inFile.Eof(); m_buf += inFile.ReadLine())
         {
             m_buf += "\n";
         }
     }
     if (m_tokens.toupper)
     {
         m_buf = m_buf.ToUpper();
     }
     m_pch = 0;
 }
Example #5
0
		protected string ToBraceIfFound(ref string buf,ref int p,ref int max,CsReader inf)
		{
			int q = p;
			int brack = Braces(0,buf,ref p,max);
			string rv = buf.Substring(q,p-q);
			while (inf!=null && brack>0) 
			{
				buf=inf.ReadLine();
				max=buf.Length;
				if (max==0)
					Error(47,q,"EOF in action or class def??");
				p=0; 
				rv += '\n';
				brack = Braces(brack,buf,ref p,max);
				rv += buf.Substring(0,p);
			}
			return rv;
		}
Example #6
0
 public void Start(CsReader inFile)
 {
     this.m_state       = "YYINITIAL";
     inFile             = new CsReader(inFile, this.m_tokens.m_encoding);
     this.m_LineManager = inFile.lm;
     if (!inFile.Eof())
     {
         this.m_buf = inFile.ReadLine();
         while (!inFile.Eof())
         {
             this.m_buf += "\n";
             this.m_buf += inFile.ReadLine();
         }
     }
     if (this.m_tokens.toupper)
     {
         this.m_buf = this.m_buf.ToUpper();
     }
     this.m_pch = 0;
 }
Example #7
0
        protected string ToBraceIfFound(ref string buf, ref int p, ref int max, CsReader inf)
        {
            int    q     = p;
            int    brack = Braces(0, buf, ref p, max);
            string rv    = buf.Substring(q, p - q);

            while (inf != null && brack > 0)
            {
                buf = inf.ReadLine();
                max = buf.Length;
                if (max == 0)
                {
                    Error(47, q, "EOF in action or class def??");
                }
                p     = 0;
                rv   += '\n';
                brack = Braces(brack, buf, ref p, max);
                rv   += buf.Substring(0, p);
            }
            return(rv);
        }
        protected string ToBraceIfFound(ref string buf, ref int p, ref int max, CsReader inf)
        {
            int    num  = p;
            int    a    = this.Braces(0, buf, ref p, max);
            string str1 = buf.Substring(num, p - num);

            while (inf != null && a > 0)
            {
                buf = inf.ReadLine();
                if (buf == null || p == 0)
                {
                    this.Error(47, num, "EOF in action or class def??");
                }
                max = buf.Length;
                p   = 0;
                string str2 = str1 + (object)'\n';
                a    = this.Braces(a, buf, ref p, max);
                str1 = str2 + buf.Substring(0, p);
            }
            return(str1);
        }
Example #9
0
        public int EmitClassDefin(string b, ref int p, int max, CsReader inf, string defbas, out string bas, out string name, bool lx)
        {
            name = "";
            bas  = defbas;
            NonWhite(b, ref p, max);
            White(b, ref p, max);
            for (; p < max && b[p] != ':' && b[p] != ';'; p++)
            {
                name += b[p];
            }
            if (b[p] == ':')
            {
                for (p++, bas = ""; p < max && b[p] != ';'; p++)
                {
                    bas += b[p];
                }
            }
            if (b[p] != ';')
            {
                Error(48, p, "Bad script");
            }
            int num = new TokClassDef(this, name, bas).m_yynum;

            m_outFile.WriteLine("//%+{0}+{1}", name, num);
            m_outFile.Write("public class ");
            m_outFile.Write(name);
            m_outFile.Write(" : " + bas);
            m_outFile.WriteLine("{");
            m_outFile.WriteLine("public override string yyname { get { return \"" + name + "\"; }}");
            m_outFile.WriteLine("public override int yynum { get { return " + num + "; }}");
            if (lx)
            {
                m_outFile.WriteLine("public " + name + "(Lexer yym):base(yym){ }}");
            }
            else
            {
                m_outFile.WriteLine("public " + name + "(Parser yyq):base(yyq){ }}");
            }
            return(num);
        }
        public int EmitClassDefin(
            string b,
            ref int p,
            int max,
            CsReader inf,
            string defbas,
            out string bas,
            out string name,
            bool lx)
        {
            bool flag = false;

            name = "";
            bas  = defbas;
            if (lx)
            {
                this.NonWhite(b, ref p, max);
            }
            this.White(b, ref p, max);
            while (p < max && b[p] != '{' && (b[p] != ':' && b[p] != ';') && (b[p] != ' ' && b[p] != '\t' && b[p] != '\n'))
            {
                name += (string)(object)b[p];
                ++p;
            }
            this.White(b, ref p, max);
            if (b[p] == ':')
            {
                ++p;
                this.White(b, ref p, max);
                bas = "";
                while (p < max && b[p] != ' ' && (b[p] != '{' && b[p] != '\t') && (b[p] != ';' && b[p] != '\n'))
                {
                    bas += (string)(object)b[p];
                    ++p;
                }
            }
            int yynum = new TokClassDef(this, name, bas).m_yynum;

            this.m_outFile.WriteLine("//%+{0}+{1}", (object)name, (object)yynum);
            this.m_outFile.Write("public class ");
            this.m_outFile.Write(name);
            this.m_outFile.Write(" : " + bas);
            this.m_outFile.WriteLine("{");
            do
            {
                if (p >= max)
                {
                    b  += inf.ReadLine();
                    max = b.Length;
                }
                this.White(b, ref p, max);
            }while (p >= max);
            if (b[p] != ';')
            {
                cs0syntax cs0syntax = new cs0syntax((YyParser) new yycs0syntax(), this.erh);
                ((cs0tokens)cs0syntax.m_lexer).Out = this.m_outname;
                cs0syntax.Cls = name;
                cs0syntax.Out = this.m_outname;
                if (lx)
                {
                    cs0syntax.Ctx = "Lexer yyl";
                    cs0syntax.Par = "yym";
                }
                else
                {
                    cs0syntax.Ctx = "Parser yyp";
                    cs0syntax.Par = "yyq";
                }
                string braceIfFound = this.ToBraceIfFound(ref b, ref p, ref max, inf);
                TOKEN  token        = (TOKEN)null;
                try
                {
                    token = (TOKEN)cs0syntax.Parse(braceIfFound);
                }
                catch (Exception)
                {
                }
                if (token == null)
                {
                    this.Error(48, p, "Bad class definition for " + name);
                    return(-1);
                }
                token.yytext = token.yytext.Replace("yyq", "((" + this.m_outname + ")yyp)");
                token.yytext = token.yytext.Replace("yym", "((" + this.m_outname + ")yyl)");
                string yytext  = token.yytext;
                char[] chArray = new char[1] {
                    '\n'
                };
                foreach (string str in yytext.Split(chArray))
                {
                    this.m_outFile.WriteLine(str);
                }
                flag = cs0syntax.defconseen;
            }
            this.m_outFile.WriteLine("public override string yyname { get { return \"" + name + "\"; }}");
            this.m_outFile.WriteLine("public override int yynum { get { return " + (object)yynum + "; }}");
            if (!flag)
            {
                if (lx)
                {
                    this.m_outFile.Write("public " + name + "(Lexer yyl):base(yyl){}");
                }
                else
                {
                    this.m_outFile.Write("public " + name + "(Parser yyp):base(yyp){}");
                }
            }
            this.m_outFile.WriteLine("}");
            return(yynum);
        }
Example #11
0
	public void Create(string infname)
	{
		try
		{
			m_inFile = new CsReader(infname,m_scriptEncoding);
		}
		catch(Exception ex)
		{
			erh.Error(new CSToolsFatalException(28,0,0,"","Could not open input file "+infname+" ("+ex.Message+")."));
			return;
		}
		if (infname.EndsWith(".txt"))
			infname = infname.Substring(0,infname.Length-4);
		try
		{
			m_outFile = new StreamWriter(infname+".cs",false);
		}
		catch (Exception ex)
		{
			erh.Error(new CSToolsFatalException(29,0,0,"","Could not create output file "+infname+".cs ("+ex.Message+")."));
			return;
		}
		_Create();
		m_outFile.Close();
	}
Example #12
0
 public SYMBOL Parse(CsReader inFile)
 {
     this.m_lexer.Start(inFile);
     return(this.Parse());
 }
 /// <exclude/>
 public CsReader(CsReader inf,Encoding enc)
 {
     fname = inf.fname;
     if (inf.m_stream is StreamReader)
         m_stream = new StreamReader(((StreamReader)inf.m_stream).BaseStream,enc);
     else
         m_stream = new StreamReader(inf.m_stream.ReadToEnd());
     state= State.copy; back = -1;
 }
Example #14
0
        /// <summary/>
        public void EmitClassDefin(string b, ref int p, int max, CsReader inf, string defbas, out string bas, out string name, bool lx)
        {
            bool defconseen = false;

            name = "";
            bas  = defbas;
            if (lx)
            {
                NonWhite(b, ref p, max);
            }
            White(b, ref p, max);
            for (; p < max && b[p] != '{' && b[p] != ':' && b[p] != ';' && b[p] != ' ' && b[p] != '\t' && b[p] != '\n'; p++)
            {
                name += b[p];
            }
            m_outFile.WriteLine("//%+{0}", name);
            m_outFile.WriteLine(@"/// <summary/>");
            m_outFile.Write("public class ");
            m_outFile.Write(name);
            White(b, ref p, max);
            if (b[p] == ':')
            {
                p++;
                White(b, ref p, max);
                for (bas = ""; p < max && b[p] != ' ' && b[p] != '{' && b[p] != '\t' && b[p] != ';' && b[p] != '\n'; p++)
                {
                    bas += b[p];
                }
            }
            new TokClassDef(this, name, bas);
            m_outFile.Write(" : " + bas);
            m_outFile.WriteLine("{");
            do
            {
                if (p >= max)
                {
                    b  += inf.ReadLine();
                    max = b.Length;
                }
                White(b, ref p, max);
            } while (p >= max);
            if (b[p] != ';')
            {
                cs0syntax syms = new cs0syntax(new yycs0syntax(), erh);
                cs0tokens tks  = (cs0tokens)syms.m_lexer;
                tks.Out = m_outname;
//				syms.m_debug = true;
                syms.Cls = name;
                syms.Out = m_outname;
                if (lx)
                {
                    syms.Ctx = "Lexer yyl";
                    syms.Par = "yym";
                }
                else
                {
                    syms.Ctx = "Parser yyp";
                    syms.Par = "yyq";
                }
                string str = ToBraceIfFound(ref b, ref p, ref max, inf);
                TOKEN  s   = (TOKEN)syms.Parse(str);
                if (s == null)
                {
                    Error(48, p, "Bad class definition for " + name);
                    return;
                }
                s.yytext = s.yytext.Replace("yyq", "((" + m_outname + ")yyp)");
                s.yytext = s.yytext.Replace("yym", "((" + m_outname + ")yyl)");
                string[] ss = s.yytext.Split('\n');
                for (int j = 0; j < ss.Length; j++)
                {
                    m_outFile.WriteLine(ss[j]);
                }
                defconseen = syms.defconseen;
            }
            m_outFile.WriteLine(@"/// <summary/>");
            m_outFile.WriteLine("public override string yyname() { return \"" + name + "\"; }");
            if (!defconseen)
            {
                if (lx)
                {
                    m_outFile.WriteLine(@"/// <summary/>");
                    m_outFile.WriteLine(@"/// <param name='yyl'></param>");
                    m_outFile.Write("public " + name + "(Lexer yyl):base(yyl){}");
                }
                else
                {
                    m_outFile.WriteLine(@"/// <summary/>");
                    m_outFile.WriteLine(@"/// <param name='yyp'></param>");
                    m_outFile.Write("public " + name + "(Parser yyp):base(yyp){}");
                }
            }
            m_outFile.WriteLine("}");
        }
Example #15
0
		public int EmitClassDefin(string b,ref int p,int max,CsReader inf,string defbas,out string bas, out string name,bool lx) 
		{
			bool defconseen = false;
			name = ""; 
			bas = defbas;
			if (lx)
				NonWhite(b,ref p,max);
			White(b,ref p,max);
			for(;p<max&&b[p]!='{'&&b[p]!=':'&&b[p]!=';'&&b[p]!=' '&&b[p]!='\t'&&b[p]!='\n';p++)
				name += b[p];
			White(b,ref p,max);
			if (b[p]==':') 
			{
				p++;
				White(b,ref p,max);
				for(bas="";p<max&&b[p]!=' '&&b[p]!='{'&&b[p]!='\t'&&b[p]!=';'&&b[p]!='\n';p++)
					bas += b[p];
			}
			int num = new TokClassDef(this,name,bas).m_yynum;
			m_outFile.WriteLine("//%+{0}+{1}",name,num);
			m_outFile.Write("public class ");
			m_outFile.Write(name);
			m_outFile.Write(" : "+bas);
			m_outFile.WriteLine("{");
			do 
			{
				if (p>=max) 
				{
					b += inf.ReadLine();
					max = b.Length;
				}
				White(b,ref p,max);
			} while (p>=max);
			if (b[p]!=';') 
			{
				cs0syntax syms = new cs0syntax(new yycs0syntax(),erh);
				cs0tokens tks = (cs0tokens)syms.m_lexer;
				tks.Out = m_outname;
//				syms.m_debug = true;
				syms.Cls = name;
				syms.Out = m_outname;
				if (lx) 
				{	
					syms.Ctx = "Lexer yyl"; 
					syms.Par = "yym";
				} 
				else 
				{
					syms.Ctx = "Parser yyp";
					syms.Par = "yyq";
				}
				string str = ToBraceIfFound(ref b,ref p, ref max,inf);
				TOKEN s = null;
				try									// 4.7c
				{
					s = (TOKEN)syms.Parse(str);
				} 
				catch (Exception)
				{}
				if (s==null) 
				{
					Error(48,p,"Bad class definition for "+name);
					return -1;
				}
				s.yytext = s.yytext.Replace("yyq","(("+m_outname+")yyp)");
				s.yytext = s.yytext.Replace("yym","(("+m_outname+")yyl)");
				string[] ss = s.yytext.Split('\n');
				for (int j=0;j<ss.Length;j++) 
					m_outFile.WriteLine(ss[j]);
				defconseen = syms.defconseen;
			}
			m_outFile.WriteLine("public override string yyname { get { return \""+name+"\"; }}");
			m_outFile.WriteLine("public override int yynum { get { return "+num+"; }}");
			if (!defconseen) 
			{
				if (lx)
					m_outFile.Write("public "+name+"(Lexer yyl):base(yyl){}");
				else
					m_outFile.Write("public "+name+"(Parser yyp):base(yyp){}");
			}
			m_outFile.WriteLine("}");
			return num;
		}
Example #16
0
	public void Create(string fname) 
	{
		try 
		{
			m_inFile = new CsReader(fname,m_scriptEncoding);
		} 
		catch (Exception e) 
		{
			if (m_tokens!=null)
			{
				m_tokens.erh.Error(new CSToolsFatalException(4,String.Format("could not open {0} for reading [{1}]",fname,e.Message)));
				return;
			}
			throw(e);
		}
		if (fname.EndsWith(".txt"))
			fname = fname.Substring(0,fname.Length-4);
		try 
		{
			m_outFile = new StreamWriter(fname+".cs",false);
		} 
		catch (Exception e) 
		{
			if (m_tokens!=null)
			{
				m_tokens.erh.Error(new CSToolsFatalException(5,String.Format("could not open {0}.cs for writing [{1}]",fname,e.Message)));
				return;
			}
			throw(e);
		}
		_Create();
		m_outFile.Close();
	}
Example #17
0
		public SYMBOL Parse(CsReader inFile) 
		{
			m_lexer.Start(inFile);
			return Parse();
		}
 /// <exclude/>
 public void Start(CsReader inFile)
 {
     m_state="YYINITIAL"; // 4.3e
     inFile = new CsReader(inFile,m_tokens.m_encoding);
     m_LineManager = inFile.lm;
     if (!inFile.Eof())
         for (m_buf = inFile.ReadLine(); !inFile.Eof(); m_buf += inFile.ReadLine())
             m_buf+="\n";
     if (m_tokens.toupper)
         m_buf = m_buf.ToUpper();
     m_pch = 0;
 }