CRQ.mod 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. (* CR Main Module of Coco/R
  2. == =====================
  3. This is a compiler generator that produces a scanner and a parser
  4. from an attributed grammar, and optionally a complete small compiler.
  5. Original code in Oberon by Hanspeter Moessenboeck, ETH Zurich
  6. Ported at ETH to Apple Modula, and thence to JPI-2 Modula.
  7. JPI version of 27 January 1991 was then modified to make more
  8. portable by Pat Terry, January - October 1992
  9. This is the WinTel version
  10. This version outputs error messages in "standard" form for use with editors
  11. Usage:
  12. COCOR [-options] GrammarName[.atg] [$options]
  13. Input:
  14. attributed grammar input grammar
  15. scanner.frm frame file
  16. parser.frm frame file
  17. compiler.frm frame file (optional)
  18. (Frame files must be in the sme directory as the grammar, or may be
  19. found on a path specified by DOS environment variable CRFRAMES).
  20. Output:
  21. <GrammarName>S.def + mod generated scanner
  22. <GrammarName>P.def + mod generated parser
  23. <GrammarName>.err error numbers and corresponding error messages
  24. <GrammarName>.lst source listing with error messages and trace output
  25. Optionally
  26. <GrammarName>G.def + mod generated symbolic names
  27. <GrammarName>.mod generated compiler main module
  28. Implementation restrictions
  29. 1 too many nodes in graph (>1500) CRT.NewNode
  30. 2 too many symbols (>500) CRT.NewSym, MovePragmas
  31. 3 too many sets (>256 ANY-syms or SYNC syms) CRT.NewSet,
  32. 4 too many character classes (>250) CRT.NewClass
  33. 5 too many conditions in generated code (>100) CRX.NewCondSet
  34. 6 too many token names in "NAMES" (>100) CRT.NewName
  35. 7 too many states in automata (>500) CRA.NewState
  36. Trace output
  37. (To activate a trace switch, write "${letter}" in the input grammar, or
  38. invoke Coco with a second command line parameter)
  39. A Prints states of automaton
  40. C Generates complete compiler module
  41. D Suppresses Def Mod generation
  42. F Prints start symbols and followers of nonterminals.
  43. G Prints the top-down graph.
  44. I Trace of start symbol set computation.
  45. L Forces a listing (otherwise a listing is only printed if errors are found).
  46. M Suppresses FORWARD declarations in parser (for multipass compilers).
  47. N Uses default names for symbol value constants. This generates an
  48. extra module <grammar name>G, and corresponding import statements
  49. using constant names instead of numbers for symbols in parser and
  50. scanner.
  51. The constants are used unqualified and hence all needed constants
  52. have to be imported; so a complete import list for these constants
  53. is generated.
  54. There is no decision whether a constant is actually needed.
  55. The default conventions are (only terminals or pragmas can have names):
  56. single character --> <ASCII name (lowercase)>Sym
  57. eg. "+" --> plusSym
  58. character string --> <string>Sym
  59. eg. "PROGRAM" --> PROGRAMSym
  60. scanner token --> <token name>Sym
  61. eg. ident --> identSym
  62. O Trace of follow set computation (not yet implemented).
  63. P Generates parser only
  64. S Prints the symbol list.
  65. T Suppresses generation of def and mod files (grammar tests only).
  66. X Prints a cross reference list.
  67. ==========================================================================*)
  68. MODULE CR;
  69. FROM CRS IMPORT lst, src, errors, directory, Error, CharAt;
  70. FROM CRP IMPORT Parse;
  71. IMPORT CRC, CRT, CRA, CRP, CRS, CRX, FileIO, Storage;
  72. IMPORT SYSTEM (* for TSIZE only *);
  73. CONST
  74. ATGExt = ".atg";
  75. LSTExt = ".lst";
  76. Version = "1.53q";
  77. ReleaseDate = "17 September 2002";
  78. TYPE
  79. INT32 = FileIO.INT32;
  80. VAR
  81. Options,
  82. GrammarName,
  83. ATGFileName,
  84. lstFileName: ARRAY [0 .. 63] OF CHAR;
  85. ll1: BOOLEAN; (* TRUE, if grammar is LL(1) *)
  86. IDE,
  87. ok: BOOLEAN; (* TRUE, if grammar tests ok so far *)
  88. MODULE ListHandler;
  89. (* ------------------- Source Listing and Error handler -------------- *)
  90. IMPORT FileIO, Storage, SYSTEM;
  91. IMPORT lst, CharAt, ATGFileName, IDE, errors, INT32;
  92. EXPORT StoreError, PrintListing;
  93. TYPE
  94. Err = POINTER TO ErrDesc;
  95. ErrDesc = RECORD
  96. nr, line, col: INTEGER;
  97. next: Err
  98. END;
  99. CONST
  100. tab = 11C;
  101. VAR
  102. firstErr, lastErr: Err;
  103. Extra: INTEGER;
  104. PROCEDURE StoreError (nr, line, col: INTEGER; pos: INT32);
  105. (* Store an error message for later printing *)
  106. VAR
  107. nextErr: Err;
  108. BEGIN
  109. Storage.ALLOCATE(nextErr, SYSTEM.TSIZE(ErrDesc));
  110. nextErr^.nr := nr; nextErr^.line := line; nextErr^.col := col;
  111. nextErr^.next := NIL;
  112. IF firstErr = NIL
  113. THEN firstErr := nextErr
  114. ELSE lastErr^.next := nextErr
  115. END;
  116. lastErr := nextErr;
  117. INC(errors)
  118. END StoreError;
  119. PROCEDURE GetLine (VAR pos: INT32;
  120. VAR line: ARRAY OF CHAR;
  121. VAR eof: BOOLEAN);
  122. (* Read a source line. Return empty line if eof *)
  123. VAR
  124. ch: CHAR;
  125. i: CARDINAL;
  126. BEGIN
  127. i := 0; eof := FALSE; ch := CharAt(pos); INC(pos);
  128. WHILE (ch # FileIO.CR) & (ch # FileIO.LF) & (ch # FileIO.EOF) DO
  129. line[i] := ch; INC(i); ch := CharAt(pos); INC(pos);
  130. END;
  131. eof := (i = 0) & (ch = FileIO.EOF); line[i] := 0C;
  132. IF ch = FileIO.CR THEN (* check for MsDos *)
  133. ch := CharAt(pos);
  134. IF ch = FileIO.LF THEN INC(pos); Extra := 0 END
  135. END
  136. END GetLine;
  137. PROCEDURE PrintErr (line: ARRAY OF CHAR; nr, col: INTEGER);
  138. (* Print an error message *)
  139. PROCEDURE Msg (s: ARRAY OF CHAR);
  140. BEGIN
  141. FileIO.WriteString(lst, s)
  142. END Msg;
  143. PROCEDURE Pointer;
  144. VAR
  145. i: INTEGER;
  146. BEGIN
  147. FileIO.WriteString(lst, "***** ");
  148. i := 0;
  149. WHILE i < col + Extra - 2 DO
  150. IF line[i] = tab
  151. THEN FileIO.Write(lst, tab)
  152. ELSE FileIO.Write(lst, ' ')
  153. END;
  154. INC(i)
  155. END;
  156. FileIO.WriteString(lst, "^ ")
  157. END Pointer;
  158. BEGIN
  159. IF ~ IDE THEN Pointer END;
  160. CASE nr OF
  161. 0: Msg("EOF expected")
  162. | 1: Msg("ident expected")
  163. | 2: Msg("string expected")
  164. | 3: Msg("badstring expected")
  165. | 4: Msg("number expected")
  166. | 5: Msg("'COMPILER' expected")
  167. | 6: Msg("'PRODUCTIONS' expected")
  168. | 7: Msg("'=' expected")
  169. | 8: Msg("'.' expected")
  170. | 9: Msg("'END' expected")
  171. | 10: Msg("'CHARACTERS' expected")
  172. | 11: Msg("'TOKENS' expected")
  173. | 12: Msg("'NAMES' expected")
  174. | 13: Msg("'PRAGMAS' expected")
  175. | 14: Msg("'COMMENTS' expected")
  176. | 15: Msg("'FROM' expected")
  177. | 16: Msg("'TO' expected")
  178. | 17: Msg("'NESTED' expected")
  179. | 18: Msg("'IGNORE' expected")
  180. | 19: Msg("'CASE' expected")
  181. | 20: Msg("'+' expected")
  182. | 21: Msg("'-' expected")
  183. | 22: Msg("'..' expected")
  184. | 23: Msg("'ANY' expected")
  185. | 24: Msg("'CHR' expected")
  186. | 25: Msg("'(' expected")
  187. | 26: Msg("')' expected")
  188. | 27: Msg("'|' expected")
  189. | 28: Msg("'WEAK' expected")
  190. | 29: Msg("'[' expected")
  191. | 30: Msg("']' expected")
  192. | 31: Msg("'{' expected")
  193. | 32: Msg("'}' expected")
  194. | 33: Msg("'SYNC' expected")
  195. | 34: Msg("'CONTEXT' expected")
  196. | 35: Msg("'<' expected")
  197. | 36: Msg("'>' expected")
  198. | 37: Msg("'<.' expected")
  199. | 38: Msg("'.>' expected")
  200. | 39: Msg("'(.' expected")
  201. | 40: Msg("'.)' expected")
  202. | 41: Msg("not expected")
  203. | 42: Msg("invalid TokenFactor")
  204. | 43: Msg("invalid Factor")
  205. | 44: Msg("invalid Factor")
  206. | 45: Msg("invalid Term")
  207. | 46: Msg("invalid Symbol")
  208. | 47: Msg("invalid SingleChar")
  209. | 48: Msg("invalid SimSet")
  210. | 49: Msg("invalid NameDecl")
  211. | 50: Msg("this symbol not expected in TokenDecl")
  212. | 51: Msg("invalid TokenDecl")
  213. | 52: Msg("invalid Attribs")
  214. | 53: Msg("invalid Declaration")
  215. | 54: Msg("invalid Declaration")
  216. | 55: Msg("invalid Declaration")
  217. | 56: Msg("this symbol not expected in CR")
  218. | 57: Msg("invalid CR")
  219. | 101: Msg("character set may not be empty")
  220. | 102: Msg("string literal may not extend over line end")
  221. | 103: Msg("a literal must not have attributes")
  222. | 104: Msg("this symbol kind not allowed in production")
  223. | 105: Msg("attribute mismatch between declaration and use")
  224. | 106: Msg("undefined string in production")
  225. | 107: Msg("name declared twice")
  226. | 108: Msg("this type not allowed on left side of production")
  227. | 109: Msg("earlier semantic action was not terminated")
  228. | 111: Msg("no production found for grammar name")
  229. | 112: Msg("grammar symbol must not have attributes")
  230. | 113: Msg("a literal must not be declared with a structure")
  231. | 114: Msg("semantic action not allowed here")
  232. | 115: Msg("undefined name")
  233. | 116: Msg("attributes not allowed in token declaration")
  234. | 117: Msg("name does not match grammar name")
  235. | 118: Msg("unacceptable constant value")
  236. | 119: Msg("may not ignore CHR(0)")
  237. | 120: Msg("token might be empty")
  238. | 121: Msg("token must not start with an iteration")
  239. | 122: Msg("comment delimiters may not be structured")
  240. | 123: Msg("only terminals may be weak")
  241. | 124: Msg("literal tokens may not contain white space")
  242. | 125: Msg("comment delimiter must be 1 or 2 characters long")
  243. | 126: Msg("character set contains more than one character")
  244. | 127: Msg("could not make deterministic automaton")
  245. | 128: Msg("semantic action text too long - please split it")
  246. | 129: Msg("literal tokens may not be empty")
  247. | 130: Msg("IGNORE CASE must appear earlier")
  248. ELSE Msg("Error: "); FileIO.WriteInt(lst, nr, 1);
  249. END;
  250. FileIO.WriteLn(lst)
  251. END PrintErr;
  252. PROCEDURE PrintListing;
  253. (* Print a source listing with error messages *)
  254. VAR
  255. nextErr: Err;
  256. eof: BOOLEAN;
  257. lnr, errC: INTEGER;
  258. srcPos: INT32;
  259. line: ARRAY [0 .. 255] OF CHAR;
  260. BEGIN
  261. IF ~ IDE THEN
  262. FileIO.WriteString(lst, "Listing:");
  263. FileIO.WriteLn(lst); FileIO.WriteLn(lst);
  264. END;
  265. srcPos := FileIO.Long0; nextErr := firstErr;
  266. GetLine(srcPos, line, eof); lnr := 1; errC := 0;
  267. WHILE ~ eof DO
  268. IF ~ IDE THEN
  269. FileIO.WriteInt(lst, lnr, 5); FileIO.WriteString(lst, " ");
  270. FileIO.WriteString(lst, line); FileIO.WriteLn(lst)
  271. END;
  272. WHILE (nextErr # NIL) & (nextErr^.line = lnr) DO
  273. IF IDE THEN
  274. FileIO.WriteString(lst, ATGFileName);
  275. FileIO.WriteString(lst, " (");
  276. FileIO.WriteCard(lst, lnr, 1);
  277. FileIO.WriteString(lst, ",");
  278. FileIO.WriteCard(lst, nextErr^.col-1, 0);
  279. FileIO.WriteString(lst, ") ")
  280. END;
  281. PrintErr(line, nextErr^.nr, nextErr^.col); INC(errC);
  282. nextErr := nextErr^.next
  283. END;
  284. GetLine(srcPos, line, eof); INC(lnr);
  285. END;
  286. IF nextErr # NIL THEN
  287. IF ~ IDE THEN FileIO.WriteInt(lst, lnr, 5); FileIO.WriteLn(lst) END;
  288. WHILE nextErr # NIL DO
  289. IF IDE THEN
  290. FileIO.WriteString(lst, ATGFileName);
  291. FileIO.WriteString(lst, " (");
  292. FileIO.WriteCard(lst, lnr, 1);
  293. FileIO.WriteString(lst, ",");
  294. FileIO.WriteCard(lst, nextErr^.col-1, 0);
  295. FileIO.WriteString(lst, ") ")
  296. END;
  297. PrintErr(line, nextErr^.nr, nextErr^.col); INC(errC);
  298. nextErr := nextErr^.next
  299. END
  300. END;
  301. IF ~ IDE AND (errC > 0) THEN
  302. FileIO.WriteLn(lst);
  303. FileIO.WriteInt(lst, errC, 5); FileIO.WriteString(lst, " error");
  304. IF errC # 1 THEN FileIO.Write(lst, "s") END;
  305. FileIO.WriteLn(lst); FileIO.WriteLn(lst); FileIO.WriteLn(lst);
  306. END
  307. END PrintListing;
  308. BEGIN
  309. firstErr := NIL; Extra := 1;
  310. END ListHandler;
  311. PROCEDURE SetOption (s: ARRAY OF CHAR);
  312. (* Set compiler options *)
  313. VAR
  314. i: CARDINAL;
  315. BEGIN
  316. i := 1;
  317. WHILE s[i] # 0C DO
  318. s[i] := CAP(s[i]);
  319. IF (s[i] >= "A") AND (s[i] <= "Z") THEN CRT.ddt[s[i]] := TRUE END;
  320. INC(i);
  321. END;
  322. END SetOption;
  323. PROCEDURE Msg (S: ARRAY OF CHAR);
  324. BEGIN
  325. FileIO.WriteString(FileIO.StdOut, S); FileIO.WriteLn(FileIO.StdOut);
  326. END Msg;
  327. (* --------------------------- Help ------------------------------- *)
  328. PROCEDURE Help;
  329. BEGIN
  330. Msg("Usage: COCOR [-Options] [Grammar[.atg]] [-Options]");
  331. Msg("Example: COCOR -mcs Test");
  332. Msg("");
  333. Msg("Options are");
  334. Msg("a - Trace automaton");
  335. Msg("c - Generate compiler module");
  336. Msg("d - Suppress generation of Definition Modules");
  337. Msg("f - Give Start and Follower sets");
  338. Msg("g - Print top-down graph");
  339. Msg("i - Trace start set computations");
  340. Msg("l - Force listing");
  341. Msg("m - (Multipass) Suppress FORWARD declarations");
  342. Msg("n - Generate symbolic names");
  343. Msg("p - Generate parser only");
  344. Msg("q - Generate error messages to interface with editor");
  345. Msg("s - Print symbol table");
  346. Msg("t - Grammar tests only - no code generated");
  347. Msg("x - Print cross reference list");
  348. Msg("COMPILER.FRM, SCANNER.FRM and PARSER.FRM must be in the working directory,");
  349. Msg("or on the path specified by the environment variable CRFRAMES");
  350. END Help;
  351. BEGIN (* CR *)
  352. FileIO.WriteString(FileIO.StdOut, "Coco/R (WinTel) - Compiler-Compiler V");
  353. FileIO.WriteString(FileIO.StdOut, Version);
  354. FileIO.WriteLn(FileIO.StdOut);
  355. FileIO.WriteString(FileIO.StdOut, "Released by Pat Terry ");
  356. FileIO.WriteString(FileIO.StdOut, ReleaseDate);
  357. FileIO.WriteLn(FileIO.StdOut);
  358. FileIO.NextParameter(GrammarName);
  359. IF (GrammarName[0] = "?")
  360. OR (GrammarName[0] = "/") AND (GrammarName[1] = "?") THEN
  361. Help; FileIO.QuitExecution
  362. END;
  363. IF GrammarName[0] = 0C THEN
  364. FileIO.WriteString(FileIO.StdOut, "(COCOR ? gives short help screen)");
  365. FileIO.WriteLn(FileIO.StdOut);
  366. END;
  367. WHILE (GrammarName[0] = "-") OR (GrammarName[0] = "/") DO
  368. (* accept options before filename *)
  369. SetOption(GrammarName); FileIO.NextParameter(GrammarName)
  370. END;
  371. ok := GrammarName[0] # 0C;
  372. REPEAT
  373. IF ~ ok THEN
  374. FileIO.WriteString(FileIO.StdOut, "Grammar[.atg] ? : ");
  375. FileIO.ReadString(FileIO.StdIn, GrammarName);
  376. IF ~ FileIO.Okay THEN FileIO.QuitExecution END;
  377. FileIO.ReadLn(FileIO.StdIn);
  378. END;
  379. FileIO.AppendExtension(GrammarName, ATGExt, ATGFileName);
  380. GrammarName := ATGFileName;
  381. FileIO.Open(src, GrammarName, FALSE);
  382. ok := FileIO.Okay;
  383. IF ~ ok THEN
  384. FileIO.WriteString(FileIO.StdOut, "File <");
  385. FileIO.WriteString(FileIO.StdOut, GrammarName);
  386. FileIO.WriteString(FileIO.StdOut, "> not found.");
  387. FileIO.WriteLn(FileIO.StdOut);
  388. END
  389. UNTIL ok;
  390. FileIO.NextParameter(Options);
  391. IF Options[0] # 0C THEN SetOption(Options) END;
  392. IDE := CRT.ddt["Q"];
  393. FileIO.ExtractDirectory(GrammarName, directory);
  394. FileIO.ChangeExtension(GrammarName, LSTExt, lstFileName);
  395. IF IDE
  396. THEN
  397. lst := FileIO.StdOut
  398. ELSE
  399. FileIO.Open(lst, lstFileName, TRUE);
  400. FileIO.WriteString(lst, "Coco/R - Compiler-Compiler V");
  401. FileIO.WriteString(lst, Version);
  402. FileIO.WriteLn(lst);
  403. FileIO.WriteString(lst, "Released by Pat Terry ");
  404. FileIO.WriteString(lst, ReleaseDate);
  405. FileIO.WriteLn(lst);
  406. FileIO.WriteString(lst, "Source file: ");
  407. FileIO.WriteString(lst, GrammarName);
  408. FileIO.WriteLn(lst); FileIO.WriteLn(lst);
  409. FileIO.WriteLn(FileIO.StdOut);
  410. FileIO.WriteString(FileIO.StdOut, "parsing file ");
  411. FileIO.WriteString(FileIO.StdOut, GrammarName);
  412. FileIO.WriteLn(FileIO.StdOut);
  413. END;
  414. CRS.Error := StoreError;
  415. CRP.Parse;
  416. (*
  417. IF ~ IDE THEN
  418. FileIO.WriteLn(FileIO.StdOut); FileIO.WriteElapsedTime(FileIO.StdOut)
  419. END;
  420. *)
  421. IF errors = 0 THEN
  422. IF ~ IDE
  423. THEN
  424. Msg("testing grammar");
  425. FileIO.WriteString(lst, "Grammar Tests:");
  426. FileIO.WriteLn(lst); FileIO.WriteLn(lst)
  427. ELSE
  428. FileIO.WriteLn(lst); FileIO.WriteString(lst, ATGFileName);
  429. FileIO.WriteString(lst, " (0, 0) Grammar tests"); FileIO.WriteLn(lst)
  430. END;
  431. CRT.CompSymbolSets;
  432. IF IDE THEN
  433. FileIO.WriteLn(lst); FileIO.WriteString(lst, ATGFileName);
  434. FileIO.WriteString(lst, " (0, 0) Undefined tests"); FileIO.WriteLn(lst)
  435. END;
  436. CRT.TestCompleteness(ok);
  437. IF ok
  438. THEN
  439. IF IDE THEN
  440. FileIO.WriteLn(lst); FileIO.WriteString(lst, ATGFileName);
  441. FileIO.WriteString(lst, " (0, 0) Unreachable tests"); FileIO.WriteLn(lst)
  442. END;
  443. CRT.TestIfAllNtReached(ok)
  444. END;
  445. IF ok THEN
  446. IF IDE THEN
  447. FileIO.WriteLn(lst); FileIO.WriteString(lst, ATGFileName);
  448. FileIO.WriteString(lst, " (0, 0) Circular tests"); FileIO.WriteLn(lst)
  449. END;
  450. CRT.FindCircularProductions(ok)
  451. END;
  452. IF ok THEN
  453. IF IDE THEN
  454. FileIO.WriteLn(lst); FileIO.WriteString(lst, ATGFileName);
  455. FileIO.WriteString(lst, " (0, 0) Underivable tests"); FileIO.WriteLn(lst)
  456. END;
  457. CRT.TestIfNtToTerm(ok)
  458. END;
  459. IF ok THEN
  460. IF IDE THEN
  461. FileIO.WriteLn(lst); FileIO.WriteString(lst, ATGFileName);
  462. FileIO.WriteString(lst, " (0, 0) LL(1) tests"); FileIO.WriteLn(lst)
  463. END;
  464. CRT.LL1Test(ll1)
  465. END;
  466. (*
  467. IF ~ IDE THEN
  468. FileIO.WriteLn(FileIO.StdOut); FileIO.WriteElapsedTime(FileIO.StdOut);
  469. FileIO.WriteLn(lst)
  470. END;
  471. *)
  472. IF ~ ok OR ~ ll1 OR CRT.ddt["L"] OR CRT.ddt["X"] THEN
  473. IF ~ IDE THEN Msg("listing") END;
  474. PrintListing; IF CRT.ddt["X"] THEN CRT.XRef; END;
  475. (*
  476. IF ~ IDE THEN
  477. FileIO.WriteLn(FileIO.StdOut); FileIO.WriteElapsedTime(FileIO.StdOut)
  478. END;
  479. *)
  480. END;
  481. IF CRT.ddt["N"] OR CRT.symNames THEN
  482. IF ~ IDE THEN Msg("symbol name assignment") END;
  483. CRT.AssignSymNames(CRT.ddt["N"], CRT.symNames);
  484. END;
  485. IF ok AND ~ CRT.ddt["T"] THEN
  486. IF ~ IDE THEN Msg("generating parser") END;
  487. CRX.GenCompiler;
  488. (*
  489. IF ~ IDE THEN
  490. FileIO.WriteLn(FileIO.StdOut); FileIO.WriteElapsedTime(FileIO.StdOut)
  491. END;
  492. *)
  493. IF CRT.genScanner AND ~ CRT.ddt["P"] THEN
  494. IF ~ IDE THEN Msg("generating scanner") END;
  495. CRA.WriteScanner(ok);
  496. IF CRT.ddt["A"] THEN CRA.PrintStates END;
  497. (*
  498. IF ~ IDE THEN
  499. FileIO.WriteLn(FileIO.StdOut); FileIO.WriteElapsedTime(FileIO.StdOut)
  500. END;
  501. *)
  502. END;
  503. IF CRT.ddt["C"] THEN
  504. IF ~ IDE THEN Msg("generating compiler") END;
  505. CRC.WriteDriver;
  506. (*
  507. IF ~ IDE THEN
  508. FileIO.WriteLn(FileIO.StdOut); FileIO.WriteElapsedTime(FileIO.StdOut);
  509. END;
  510. *)
  511. END;
  512. IF ~ IDE THEN CRX.WriteStatistics END;
  513. END;
  514. IF ~ ok THEN
  515. FileIO.WriteLn(FileIO.StdOut);
  516. IF IDE THEN
  517. FileIO.WriteString(lst, ATGFileName);
  518. FileIO.WriteString(lst, " (0, 0) ")
  519. END;
  520. FileIO.WriteString(FileIO.StdOut, "Compilation ended with errors in grammar tests.");
  521. ELSIF ~ ll1 THEN
  522. FileIO.WriteLn(FileIO.StdOut);
  523. IF IDE THEN
  524. FileIO.WriteString(lst, ATGFileName);
  525. FileIO.WriteString(lst, " (0, 0) ")
  526. END;
  527. FileIO.WriteString(FileIO.StdOut, "Compilation ended with LL(1) errors.");
  528. ELSE
  529. Msg("Compilation completed. No errors detected.");
  530. END;
  531. ELSE
  532. IF ~ IDE THEN Msg("listing") END;
  533. PrintListing; IF CRT.ddt["X"] THEN CRT.XRef END;
  534. IF ~ IDE THEN Msg("*** errors detected ***") END;
  535. END;
  536. FileIO.WriteLn(FileIO.StdOut);
  537. IF CRT.ddt["G"] THEN CRT.PrintGraph END;
  538. IF CRT.ddt["S"] THEN CRT.PrintSymbolTable END;
  539. FileIO.Close(lst); FileIO.Close(src);
  540. (*
  541. IF ~ IDE THEN
  542. FileIO.WriteLn(FileIO.StdOut); FileIO.WriteExecutionTime(FileIO.StdOut)
  543. END
  544. *)
  545. END CR.