home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / oberon / system1 / coco.mod (.txt) next >
Oberon Text  |  1977-12-31  |  7KB  |  169 lines

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