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

  1. Syntax10.Scn.Fnt
  2. Coco/R - the Oberon scanner and parser generator
  3. For a complete documentation see the postscript file Coco.Report.ps.
  4. Coco.Compile *
  5. Coco.Compile ~
  6. Coco.Compile ^
  7. Coco.Compile @
  8. (*________________________ usage ________________________*)
  9. Coco.Compile <filename> [options]
  10. The file CR.ATG is an example of an input file to Coco. If the grammar in the input file has the name X
  11. the generated scanner has the name XS.Mod and the generated parser has the name XP.Mod.
  12. Options:
  13.     \X    generates a cross reference list of all syntax symbols
  14.     \S    generates a list of all terminal start symbols and successors of nonterminal symbols.
  15. Interface of the generated scanner:
  16.     DEFINITION XS;
  17.         IMPORT Texts;
  18.         TYPE
  19.             ErrorProc = PROCEDURE (n: INTEGER; pos: LONGINT);
  20.         VAR
  21.             Error: ErrorProc;
  22.             col, errors, len, line, nextCol, nextLen, nextLine: INTEGER;
  23.             nextPos, pos: LONGINT;
  24.             src: Texts.Text;
  25.         PROCEDURE Reset (t: Texts.Text; pos: LONGINT; errProc: ErrorProc);
  26.         PROCEDURE Get(VAR sym: INTEGER);
  27.         PROCEDURE GetName(pos: LONGINT; len: INTEGER; VAR name: ARRAY OF CHAR);
  28.         PROCEDURE StdErrorProc (n: INTEGER; pos: LONGINT);
  29.     END XS.
  30. Interface of the generated parser:
  31.     DEFINITION XP;
  32.         PROCEDURE Parse;
  33.     END XP.
  34. Example how to use the generated parts;
  35.     Texts.OpenScanner(s, Oberon.Par.Text, Oberon.Par.Pos); Texts.Scan(s);
  36.     IF s.class = Texts.Name THEN
  37.         NEW(text); Texts.Open(text, s.s);
  38.         XS.Reset(text, 0, MyErrorHandler);
  39.         XP.Parse;
  40. Error handling in the generated parser:
  41. The grammar has to contain hints, from which Coco can generate appropriate error handling.
  42. The hints can be placed arbitrarily on the right-hand side of a production:
  43.     SYNC        Denotes a synchronisation point. At such points symbols are skipped until a symbol
  44.                     is found which is a legal continuation symbol at that point (or eof). SYNC is usually
  45.                     placed at points where particularly "safe" symbols are expected, i.e., symbols that
  46.                     are rarely missing or misspelled.
  47.     WEAK s    s is an arbitrary terminal symbol (e.g., ";") which is considered "weak", because it is
  48.                     frequently missing or misspelled (e.g., a semicolon between statements).
  49. Example:
  50.     Statement =
  51.         SYNC
  52.         ( ident WEAK ":=" Expression
  53.         | "IF" Expression "THEN" StatSeq ["ELSE" StatSeq] "END"
  54.         | "WHILE" Expression "DO" StatSeq "END"
  55.     StatSeq =
  56.         Statement { WEAK ";" Statement}.
  57. Compiler.Compile
  58.     Sets.Mod CRS.Mod CRT.Mod CRA.Mod CRX.Mod CRP.Mod Coco.Mod ~
  59.