DEADSOFTWARE

Coco/R возвращает коды ошибок
[dsw-obn.git] / tools / Coco / Coco.obn
1 (* Implementation restrictions
2 3 too many nodes in graph (>1500) CRG.NewNode
3 4 too many sets (ANY-symbols or SYNC symbols) CRT.NewAnySet,
4 CRT.ComputeSyncSet
5 6 too many symbols (>300) CRT.NewSym
6 7 too many character classes (>50) CRT.NewClass
7 9 too many conditions in generated code (>100) CRX.NewCondSet
9 Trace output (ddt settings: ${digit})
10 0 Prints states of automaton
11 1 Prints start symbols and followers of nonterminals (also option /s)
12 2 Prints the internal graph
13 3 Trace of start symbol set computation
14 4 Trace of follow set computation
15 5 suppresses FORWARD declarations in parser (for multipass compilers)
16 6 Prints the symbol list
17 7 Prints a cross reference list (also option /x)
18 8 Write statistics
19 ==========================================================================*)
20 MODULE Coco;
22 IMPORT Oberon, Texts, CRS, CRP, CRT;
24 CONST minErrDist = 8;
26 VAR w: Texts.Writer; lastErrPos: LONGINT;
29 PROCEDURE Error (n: INTEGER; pos: LONGINT);
31 PROCEDURE Msg (s: ARRAY OF CHAR);
32 BEGIN Texts.WriteString(w, s)
33 END Msg;
35 BEGIN
36 INC(CRS.errors);
37 IF pos < lastErrPos + minErrDist THEN lastErrPos := pos; RETURN END;
38 lastErrPos := pos;
39 Texts.WriteInt(w, pos, 3); Texts.WriteString(w, ": ");
40 IF n < 200 THEN
41 CASE n OF
42 | 0: Msg("EOF expected")
43 | 1: Msg("ident expected")
44 | 2: Msg("string expected")
45 | 3: Msg("number expected")
46 | 4: Msg("'COMPILER' expected")
47 | 5: Msg("'IMPORT' expected")
48 | 6: Msg("';' expected")
49 | 7: Msg("'PRODUCTIONS' expected")
50 | 8: Msg("'=' expected")
51 | 9: Msg("'.' expected")
52 | 10: Msg("'END' expected")
53 | 11: Msg("'CHARACTERS' expected")
54 | 12: Msg("'TOKENS' expected")
55 | 13: Msg("'PRAGMAS' expected")
56 | 14: Msg("'COMMENTS' expected")
57 | 15: Msg("'FROM' expected")
58 | 16: Msg("'TO' expected")
59 | 17: Msg("'NESTED' expected")
60 | 18: Msg("'IGNORE' expected")
61 | 19: Msg("'CASE' expected")
62 | 20: Msg("'+' expected")
63 | 21: Msg("'-' expected")
64 | 22: Msg("'CHR' expected")
65 | 23: Msg("'(' expected")
66 | 24: Msg("')' expected")
67 | 25: Msg("'ANY' expected")
68 | 26: Msg("'|' expected")
69 | 27: Msg("'WEAK' expected")
70 | 28: Msg("'[' expected")
71 | 29: Msg("']' expected")
72 | 30: Msg("'{' expected")
73 | 31: Msg("'}' expected")
74 | 32: Msg("'SYNC' expected")
75 | 33: Msg("'CONTEXT' expected")
76 | 34: Msg("'<' expected")
77 | 35: Msg("'>' expected")
78 | 36: Msg("'(.' expected")
79 | 37: Msg("'.)' expected")
80 | 38: Msg("??? expected")
81 | 39: Msg("invalid TokenFactor")
82 | 40: Msg("invalid Factor")
83 | 41: Msg("invalid Factor")
84 | 42: Msg("invalid Term")
85 | 43: Msg("invalid Symbol")
86 | 44: Msg("invalid SimSet")
87 | 45: Msg("this symbol not expected in TokenDecl")
88 | 46: Msg("invalid TokenDecl")
89 | 47: Msg("invalid Declaration")
90 | 48: Msg("invalid Declaration")
91 | 49: Msg("invalid Declaration")
92 | 50: Msg("this symbol not expected in Coco")
93 | 51: Msg("invalid start of the program")
94 ELSE Texts.WriteString(w, "error "); Texts.WriteInt(w, n, 0)
95 END
96 ELSE
97 CASE n OF
98 | 201: Msg("unexpected end of file");
99 | 202: Msg("string terminator not on this line");
100 | 203: Msg("a literal must not have attributes");
101 | 204: Msg("this symbol kind not allowed in production");
102 | 205: Msg("symbol declared without attributes");
103 | 206: Msg("symbol declared with attributes");
104 | 207: Msg("name declared twice");
105 | 208: Msg("this type not allowed on left side of production");
106 | 209: Msg("symbol earlier referenced without attributes");
107 | 210: Msg("symbol earlier referenced with attributes");
108 | 211: Msg("missing production for grammar name");
109 | 212: Msg("grammar symbol must not have attributes");
110 | 213: Msg("a literal must not be declared with a structure")
111 | 214: Msg("semantic action not allowed here")
112 | 215: Msg("undefined name")
113 | 216: Msg("attributes not allowed in token declaration")
114 | 217: Msg("name does not match name in heading")
115 | 220: Msg("token may be empty")
116 | 221: Msg("token must not start with an iteration")
117 | 222: Msg("only characters allowed in comment declaration")
118 | 223: Msg("only terminals may be weak")
119 | 224:
120 | 225: Msg("comment delimiter must not exceed 2 characters")
121 | 226: Msg("character set contains more than one character")
122 ELSE Texts.WriteString(w, "error "); Texts.WriteInt(w, n, 0)
123 END
124 END;
125 Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf)
126 END Error;
128 PROCEDURE Options(VAR s: Texts.Scanner);
129 VAR i: INTEGER;
130 BEGIN
131 IF s.nextCh = "/" THEN Texts.Scan(s); Texts.Scan(s);
132 IF s.class = Texts.Name THEN i := 0;
133 WHILE s.s[i] # 0X DO
134 IF CAP(s.s[i]) = "X" THEN CRT.ddt[7] := TRUE
135 ELSIF CAP(s.s[i]) = "S" THEN CRT.ddt[1] := TRUE
136 END;
137 INC(i)
138 END
139 END
140 END;
141 END Options;
144 PROCEDURE Compile*;
145 VAR s: Texts.Scanner; src, t: Texts.Text;
146 pos, beg, end, time: LONGINT; i: INTEGER;
147 BEGIN
148 Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
149 src := NIL; pos := 0;
150 IF (s.class = Texts.Char) & (s.c = "^") THEN
151 Oberon.GetSelection(t, beg, end, time);
152 IF time >= 0 THEN Texts.OpenScanner(s, t, beg); Texts.Scan(s) END
153 END;
154 IF s.class = Texts.Name THEN
155 NEW(src); Texts.Open(src, s.s);
156 ELSIF (s.class = Texts.Char) & (s.c = "@") THEN
157 Oberon.GetSelection(t, beg, end, time);
158 IF time >= 0 THEN src := t; pos := beg; s.s := " " END
159 END;
160 IF src # NIL THEN
161 Texts.WriteString(w, "Coco/R - Compiler-Compiler V2.2"); Texts.WriteLn(w); Texts.Append(Oberon.Log, w.buf);
162 i := 0; WHILE i < 10 DO CRT.ddt[i] := FALSE; INC(i) END;
163 Options(s);
164 CRS.Reset(src, pos, Error); lastErrPos := -10;
165 CRP.Parse
166 ELSE
167 INC(CRS.errors);
168 END;
169 IF CRS.errors # 0 THEN HALT(1) END
170 END Compile;
172 BEGIN
173 Texts.OpenWriter(w)
174 END Coco.