Beispiel #1
0
	public static void XRef() {
		SortedList tab = new SortedList();
		// collect lines where symbols have been defined
		foreach (Symbol sym in Symbol.nonterminals) {
			ArrayList list = (ArrayList)tab[sym];
			if (list == null) {list = new ArrayList(); tab[sym] = list;}
			list.Add(- sym.line);
		}
		// collect lines where symbols have been referenced
		foreach (Node n in Node.nodes) {
			if (n.typ == Node.t || n.typ == Node.wt || n.typ == Node.nt) {
				ArrayList list = (ArrayList)tab[n.sym];
				if (list == null) {list = new ArrayList(); tab[n.sym] = list;}
				list.Add(n.line);
			}
		}
		// print cross reference list
		Trace.WriteLine();
		Trace.WriteLine("Cross reference list:");
		Trace.WriteLine("--------------------"); Trace.WriteLine();
		foreach (Symbol sym in tab.Keys) {
			Trace.Write("  {0,-12}", Node.Name(sym.name));
			ArrayList list = (ArrayList)tab[sym];
			int col = 14;
			foreach (int line in list) {
				if (col + 5 > 80) {
					Trace.WriteLine();
					for (col = 1; col <= 14; col++) Trace.Write(" ");
				}
				Trace.Write("{0,5}", line); col += 5;
			}
			Trace.WriteLine();
		}
		Trace.WriteLine(); Trace.WriteLine();
	}
Beispiel #2
0
	static void PrintSym(Symbol sym) {
		Trace.Write("{0,3} {1,-14} {2}", sym.n, Node.Name(sym.name), Node.nTyp[sym.typ]);
		if (sym.attrPos==null) Trace.Write(" false "); else Trace.Write(" true  ");
		if (sym.typ == Node.nt) {
			Trace.Write("{0,5}", Num(sym.graph));
			if (sym.deletable) Trace.Write(" true  "); else Trace.Write(" false ");
		} else
			Trace.Write("            ");
		Trace.WriteLine("{0,5}", sym.line);
	}
Beispiel #3
0
 public static void PrintStates()
 {
     Trace.WriteLine("\n---------- states ----------");
     for (State state = firstState; state != null; state = state.next)
     {
         bool first = true;
         if (state.endOf == null)
         {
             Trace.Write("               ");
         }
         else
         {
             Trace.Write("E({0,12})", Node.Name(state.endOf.name));
         }
         Trace.Write("{0,3}:", state.nr);
         if (state.firstAction == null)
         {
             Trace.WriteLine();
         }
         for (Action action = state.firstAction; action != null; action = action.next)
         {
             if (first)
             {
                 Trace.Write(" ");
                 first = false;
             }
             else
             {
                 Trace.Write("                    ");
             }
             if (action.typ == Node.clas)
             {
                 Trace.Write(((CharClass)CharClass.classes[action.sym]).name);
             }
             else
             {
                 Trace.Write("{0, 3}", Ch((char)action.sym));
             }
             for (Target targ = action.target; targ != null; targ = targ.next)
             {
                 Trace.Write(" {0, 3}", targ.state.nr);
             }
             if (action.tc == Node.contextTrans)
             {
                 Trace.WriteLine(" context");
             }
             else
             {
                 Trace.WriteLine();
             }
         }
     }
     Trace.WriteLine("\n---------- character classes ----------");
     CharClass.WriteClasses();
 }