// *** end of global SYN and SEM declarations from ATG *** private static void NT_BinaryTree() { for (;;) { switch (Syn.Interpret()) { case 0: return; case 1: // SEM tree = new BTree(); break; case 2: NT_SubTree(ref tree); break; case 3: // SEM Console.WriteLine("Tree:"); Console.Write("("); if (tree.HasBeenAssigned()) { Console.Write(tree); } Console.WriteLine(")"); break; } // switch } // for } // NT_BinaryTree
} // NT_BinaryTree private static void NT_SubTree(ref BTree t) { BTree left = new BTree(); BTree right = new BTree(); for (;;) { switch (Syn.Interpret()) { case 0: return; case 1: NT_SubTree(ref left); break; case 2: Lex.GETnumberAttr(out num); break; case 3: // SEM t.Value = num; t.Left = left; t.Right = right; break; case 4: NT_SubTree(ref right); break; } // switch } // for } // NT_SubTree
public static void StartSem() { //-----------------------------------|---------------------------------------- for (;;) { switch (Syn.Interpret()) { case 0: return; case 1: NT_BinaryTree(); break; } // switch } // for } // StartSem
} // Abort private static int CompileFile(String srcFileName) { FileStream srcFs = null; try { srcFs = new FileStream(srcFileName, FileMode.Open); } catch (Exception) { Console.WriteLine("*** file \"{0}\" not found", srcFileName); return(Utils.EXIT_FAILURE); } // try/catch try { Lex.src = new StreamReader(srcFs); Console.WriteLine("parsing ..."); Syn.Parse(); Lex.src.Close(); Lex.src.Dispose(); Lex.src = null; if (Errors.NumOfErrors() > 0) { Console.WriteLine("listing ..."); String lstFileName = Path.ChangeExtension(srcFileName, ".lst"); FileStream lstFs = null; try { lstFs = new FileStream(lstFileName, FileMode.Create); } catch (Exception) { Utils.FatalError(NAME, "CompileFile", "file \"{0}\" not created", lstFileName); return(Utils.EXIT_FAILURE); } // try/catch StreamWriter lstWriter = null; try { lstWriter = new StreamWriter(lstFs); StreamReader srcFsReader = null; try { // open the source file a second time to generate the error listing srcFsReader = new StreamReader(new FileStream(srcFileName, FileMode.Open)); lstWriter.WriteLine(NAME + " (file: \"{0}\")", srcFileName); Errors.GenerateListing(srcFsReader, lstWriter, Errors.ListingShape.longListing); } finally { srcFsReader.Close(); srcFsReader.Dispose(); } // try/finally Console.WriteLine("{0} error(s) detected", Errors.NumOfErrors()); } finally { lstWriter.Close(); lstWriter.Dispose(); } // try/finally } else { Console.WriteLine("no errors detected"); } } finally { if (Lex.src != null) { Lex.src.Close(); Lex.src.Dispose(); Lex.src = null; } // if Utils.Modules(Utils.ModuleAction.resetModule); } // try/finally to make sure srcFs and srcReader are closed return(Utils.EXIT_SUCCESS); } // CompileFile