Beispiel #1
0
 public void Or(CharSet s)
 {
     for (Range p = s.head; p != null; p = p.next)
     for (int i = p.from; i <= p.to; i++) Set(i);
 }
Beispiel #2
0
 public void Subtract(CharSet s)
 {
     CharSet x = new CharSet();
     for (Range p = head; p != null; p = p.next)
     for (int i = p.from; i <= p.to; i++)
         if (!s[i]) x.Set(i);
     head = x.head;
 }
Beispiel #3
0
 public bool Equals(CharSet s)
 {
     Range p = head, q = s.head;
     while (p != null && q != null) {
     if (p.from != q.from || p.to != q.to) return false;
     p = p.next; q = q.next;
     }
     return p == q;
 }
Beispiel #4
0
 public bool Intersects(CharSet s)
 {
     for (Range p = s.head; p != null; p = p.next)
     for (int i = p.from; i <= p.to; i++)
         if (this[i]) return true;
     return false;
 }
Beispiel #5
0
 void ParseSet(out CharSet s)
 {
     CharSet s2;
     ParseSimSet(out s);
     while (la.kind == 22 || la.kind == 23) {
     if (la.kind == 22) {
         Get();
         ParseSimSet(out s2);
         s.Or(s2);
     } else {
         Get();
         ParseSimSet(out s2);
         s.Subtract(s2);
     }
     }
 }
Beispiel #6
0
 public CharSet Clone()
 {
     CharSet s = new CharSet();
     Range prev = null;
     for (Range cur = head; cur != null; cur = cur.next) {
     Range r = new Range(cur.from, cur.to);
     if (prev == null) s.head = r; else prev.next = r;
     prev = r;
     }
     return s;
 }
Beispiel #7
0
	public CharClass FindCharClass(CharSet s) {
		foreach (CharClass c in classes)
			if (s.Equals(c.set)) return c;
		return null;
	}
Beispiel #8
0
 void Set(out CharSet s)
 {
     CharSet s2;
     SimSet(out s);
     while (la.kind == 25 || la.kind == 26) {
     if (la.kind == 25) {
         Get();
         SimSet(out s2);
         s.Or(s2);
     } else {
         Get();
         SimSet(out s2);
         s.Subtract(s2);
     }
     }
 }
Beispiel #9
0
	public CharSet set;	// set representing the class

	public CharClass(string name, CharSet s) {
		this.name = name; this.set = s;
	}
Beispiel #10
0
	public CharClass NewCharClass(string name, CharSet s) {
		if (name == "#") name = "#" + (char)dummyName++;
		CharClass c = new CharClass(name, s);
		c.n = classes.Count;
		classes.Add(c);
		return c;
	}
Beispiel #11
0
	void SimSet(
#line 228 "Coco.atg" //SOURCE beg=9517,len=13,col=8
								out CharSet s
#line default //END SOURCE
) {

#line 228 "Coco.atg" //SOURCE beg=9545,len=12,col=36
																																				int n1, n2; 
#line default //END SOURCE

#line 229 "Coco.atg" //SOURCE beg=9596,len=19,col=36
																																				s = new CharSet(); 
#line default //END SOURCE
		if (la.kind == _ident) {
			Get();

#line 230 "Coco.atg" //SOURCE beg=9654,len=169,col=36
																																				CharClass c = tab.FindCharClass(t.val);
                                   if (c == null) SemErr("undefined name"); else s.Or(c.set);
                                 
#line default //END SOURCE
		} else if (la.kind == _string) {
			Get();

#line 233 "Coco.atg" //SOURCE beg=9862,len=311,col=36
																																				string name = t.val;
                                   name = tab.Unescape(name.Substring(1, name.Length-2));
                                   foreach (char ch in name)
                                     if (dfa.ignoreCase) s.Set(char.ToLower(ch));
                                     else s.Set(ch); 
#line default //END SOURCE
		} else if (la.kind == _char) {
			Char(
#line 238 "Coco.atg" //SOURCE beg=10184,len=6,col=8
								out n1
#line default //END SOURCE
);

#line 238 "Coco.atg" //SOURCE beg=10212,len=11,col=36
																																				s.Set(n1); 
#line default //END SOURCE
			if (la.kind == 23) {
				Get();
				Char(
#line 239 "Coco.atg" //SOURCE beg=10241,len=6,col=15
															out n2
#line default //END SOURCE
);

#line 239 "Coco.atg" //SOURCE beg=10262,len=41,col=36
																																				for (int i = n1; i <= n2; i++) s.Set(i); 
#line default //END SOURCE
			}
		} else if (la.kind == 24) {
			Get();

#line 241 "Coco.atg" //SOURCE beg=10347,len=29,col=36
																																				s = new CharSet(); s.Fill(); 
#line default //END SOURCE
		} else SynErr(49);
	}
Beispiel #12
0
	void Set(
#line 218 "Coco.atg" //SOURCE beg=9237,len=13,col=5
					out CharSet s
#line default //END SOURCE
) {

#line 218 "Coco.atg" //SOURCE beg=9268,len=12,col=36
																																				CharSet s2; 
#line default //END SOURCE
		SimSet(
#line 220 "Coco.atg" //SOURCE beg=9296,len=5,col=10
										out s
#line default //END SOURCE
);
		while (la.kind == 21 || la.kind == 22) {
			if (la.kind == 21) {
				Get();
				SimSet(
#line 221 "Coco.atg" //SOURCE beg=9319,len=6,col=16
																out s2
#line default //END SOURCE
);

#line 221 "Coco.atg" //SOURCE beg=9339,len=10,col=36
																																				s.Or(s2); 
#line default //END SOURCE
			} else {
				Get();
				SimSet(
#line 222 "Coco.atg" //SOURCE beg=9368,len=6,col=16
																out s2
#line default //END SOURCE
);

#line 222 "Coco.atg" //SOURCE beg=9388,len=16,col=36
																																				s.Subtract(s2); 
#line default //END SOURCE
			}
		}
	}
Beispiel #13
0
        BitArray visited; //!< mark list for graph traversals

        #endregion Fields

        #region Constructors

        public Tab(Parser parser)
        {
            this.parser = parser;
            errors = parser.errors;
            buffer = parser.scanner.buffer;
            eofSy = NewSym(Node.t, "EOF", 0);
            dummyNode = NewNode(Node.eps);
            ignored  = new CharSet();
            literals = new Hashtable();
        }
Beispiel #14
0
 private void PutRange(CharSet s)
 {
     for (CharSet.Range r = s.head; r != null; r = r.next) {
     if (r.from == r.to) { gen.Write("ch == " + Ch(r.from)); }
     else if (r.from == 0) { gen.Write("ch <= " + Ch(r.to)); }
     else { gen.Write("ch >= " + Ch(r.from) + " && ch <= " + Ch(r.to)); }
     if (r.next != null) gen.Write(" || ");
     }
 }
Beispiel #15
0
	void WriteCharSet(CharSet s) {
		for (CharSet.Range r = s.head; r != null; r = r.next)
			if (r.from < r.to) { trace.Write(Ch(r.from) + ".." + Ch(r.to) + " "); }
			else { trace.Write(Ch(r.from) + " "); }
	}
Beispiel #16
0
 public void ShiftWith(CharSet s, Tab tab)
 {
     if (s.Elements() == 1) {
     typ = Node.chr; sym = s.First();
     } else {
     CharClass c = tab.FindCharClass(s);
     if (c == null) c = tab.NewCharClass("#", s); // class with dummy name
     typ = Node.clas; sym = c.n;
     }
 }
Beispiel #17
0
 public CharSet Symbols(Tab tab)
 {
     CharSet s;
     if (typ == Node.clas)
     s = tab.CharClassSet(sym).Clone();
     else {
     s = new CharSet(); s.Set(sym);
     }
     return s;
 }
Beispiel #18
0
        void SimSet(out CharSet s)
        {
            int n1, n2; s = new CharSet();
            if (la.kind == 1) {
            Get();
            CharClass c = tab.FindCharClass(t.val);
              if (c == null) SemErr("undefined name"); else s.Or(c.set);

            } else if (la.kind == 3) {
            Get();
            string name = t.val;
            name = tab.Unescape(name.Substring(1, name.Length-2));
            foreach (char ch in name)
              if (dfa.ignoreCase) s.Set(char.ToLower(ch));
              else s.Set(ch);
            } else if (la.kind == 5) {
            Char(out n1);
            s.Set(n1);
            if (la.kind == 27) {
                Get();
                Char(out n2);
                for (int i = n1; i <= n2; i++) s.Set(i);
            }
            } else if (la.kind == 28) {
            Get();
            s = new CharSet(); s.Fill();
            } else SynErr(56);
        }
Beispiel #19
0
        String GenScan3()
        {
            MemoryStream insertion = new MemoryStream();
            StreamWriter oldGen = gen;
            gen = new StreamWriter(insertion);
            CharSet nt = new CharSet();
            CharSet tt = new CharSet();
            Comment com = firstComment;

            StreamReader reader = new StreamReader(insertion);
   
                    gen.Write(" ");
                    if (tab.ignored.Elements() > 0) { PutRange(tab.ignored); } else { gen.Write("false"); }
                    gen.Write(" ");
           gen.Flush();
            insertion.Seek(0, SeekOrigin.Begin);
            gen = oldGen;
            return reader.ReadToEnd();
        }