DEADSOFTWARE

Добавлены строки в отладочную информацию класса (быстрохак)
[dsw-obn.git] / tools / Coco / Coco.Tool
1 Coco/R - the Oberon scanner and parser generator
3 For a complete documentation see the postscript file Coco.Report.ps.
5 Compiler.Compile
6 Sets.Mod CRS.Mod CRT.Mod CRA.Mod CRX.Mod CRP.Mod Coco.Mod ~
8 NOTE: the option character should be changed to "\" in Coco.Mod for Unix implementations.
11 Coco.Compile *
12 Coco.Compile ~
13 Coco.Compile ^
14 Coco.Compile @
16 (*________________________ usage ________________________*)
18 Coco.Compile <filename> [options]
20 The file CR.ATG is an example of an input file to Coco. If the grammar in the input file has the name X
21 the generated scanner has the name XS.Mod and the generated parser has the name XP.Mod.
23 Options:
25 /X generates a cross reference list of all syntax symbols
26 /S generates a list of all terminal start symbols and successors of nonterminal symbols.
28 Interface of the generated scanner:
30 DEFINITION XS;
31 IMPORT Texts;
32 TYPE
33 ErrorProc = PROCEDURE (n: INTEGER; pos: LONGINT);
34 VAR
35 Error: ErrorProc;
36 col, errors, len, line, nextCol, nextLen, nextLine: INTEGER;
37 nextPos, pos: LONGINT;
38 src: Texts.Text;
39 PROCEDURE Reset (t: Texts.Text; pos: LONGINT; errProc: ErrorProc);
40 PROCEDURE Get(VAR sym: INTEGER);
41 PROCEDURE GetName(pos: LONGINT; len: INTEGER; VAR name: ARRAY OF CHAR);
42 PROCEDURE StdErrorProc (n: INTEGER; pos: LONGINT);
43 END XS.
45 Interface of the generated parser:
47 DEFINITION XP;
48 PROCEDURE Parse;
49 END XP.
51 Example how to use the generated parts;
53 Texts.OpenScanner(s, Oberon.Par.Text, Oberon.Par.Pos); Texts.Scan(s);
54 IF s.class = Texts.Name THEN
55 NEW(text); Texts.Open(text, s.s);
56 XS.Reset(text, 0, MyErrorHandler);
57 XP.Parse;
58 END
61 Error handling in the generated parser:
63 The grammar has to contain hints, from which Coco can generate appropriate error handling.
64 The hints can be placed arbitrarily on the right-hand side of a production:
66 SYNC Denotes a synchronisation point. At such points symbols are skipped until a symbol
67 is found which is a legal continuation symbol at that point (or eof). SYNC is usually
68 placed at points where particularly "safe" symbols are expected, i.e., symbols that
69 are rarely missing or misspelled.
71 WEAK s s is an arbitrary terminal symbol (e.g., ";") which is considered "weak", because it is
72 frequently missing or misspelled (e.g., a semicolon between statements).
74 Example:
76 Statement =
77 SYNC
78 ( ident WEAK ":=" Expression
79 | "IF" Expression "THEN" StatSeq ["ELSE" StatSeq] "END"
80 | "WHILE" Expression "DO" StatSeq "END"
81 ).
82 StatSeq =
83 Statement { WEAK ";" Statement}.þ