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

  1. Syntax10.Scn.Fnt
  2. (*  scanner module generated by Coco-R *)
  3. MODULE -->modulename;
  4. IMPORT Texts, SYSTEM;
  5. CONST
  6.     EOL = 0DX;
  7.     EOF = 0X;
  8.     maxLexLen = 127;
  9. -->declarations
  10.     ErrorProc* = PROCEDURE (n: INTEGER; pos: LONGINT);
  11.     StartTable = ARRAY 128 OF INTEGER;
  12.     src*: Texts.Text;  (*source text. To be set by the main pgm*)
  13.     pos*: LONGINT;  (*position of current symbol*)
  14.     line*, col*, len*: INTEGER;  (*line, column, length of current symbol*)
  15.     nextPos*: LONGINT;  (*position of lookahead symbol*)
  16.     nextLine*, nextCol*, nextLen*: INTEGER;  (*line, column, length of lookahead symbol*)
  17.     errors*: INTEGER;  (*number of errors detected*)
  18.     Error*: ErrorProc;
  19.     ch: CHAR;        (*current input character*)
  20.     r: Texts.Reader;    (*global reader*)
  21.     chPos: LONGINT;    (*position of current character*)
  22.     chLine: INTEGER;  (*current line number*)
  23.     lineStart: LONGINT;  (*start position of current line*)
  24.     apx: INTEGER;     (*length of appendix*)
  25.     oldEols: INTEGER;     (*nr. of EOLs in a comment*)
  26.     start: StartTable;  (*start state for every character*)
  27. PROCEDURE NextCh; (*return global variable ch*)
  28. BEGIN
  29.     Texts.Read(r, ch); INC(chPos);
  30.     IF ch = EOL THEN INC(chLine); lineStart := chPos + 1 END
  31. END NextCh;
  32. PROCEDURE Comment(): BOOLEAN;
  33.     VAR level, startLine: INTEGER; oldLineStart: LONGINT;
  34. BEGIN (*Comment*)
  35.     level := 1; startLine := chLine; oldLineStart := lineStart;
  36. -->comment
  37. END Comment;
  38. PROCEDURE Get*(VAR sym: INTEGER);
  39. VAR state: INTEGER; lexeme: ARRAY maxLexLen+1 OF CHAR;
  40.     PROCEDURE CheckLiteral;
  41.     BEGIN
  42.         IF nextLen < maxLexLen THEN lexeme[nextLen] := 0X END;
  43. -->literals
  44.     END CheckLiteral;
  45. BEGIN
  46. -->GetSy1
  47.     IF ch > 7FX THEN ch := " " END;
  48.     pos := nextPos; col := nextCol; line := nextLine; len := nextLen;
  49.     nextPos := chPos; nextCol := SHORT(chPos - lineStart); nextLine := chLine; nextLen := 0;
  50.     state := start[ORD(ch)]; apx := 0;
  51.     LOOP
  52.         IF nextLen < maxLexLen THEN lexeme[nextLen] := ch END;
  53.         INC(nextLen);
  54.         NextCh;
  55.         IF state > 0 THEN
  56.             CASE state OF
  57. -->GetSy2
  58.             END (*CASE*)
  59.         ELSE sym := noSym; RETURN (*NextCh already done*)
  60.         END (*IF*)
  61.     END (*LOOP*)
  62. END Get;
  63. PROCEDURE GetName*(pos: LONGINT; len: INTEGER; VAR s: ARRAY OF CHAR);
  64.     VAR i: INTEGER; r: Texts.Reader;
  65. BEGIN
  66.     Texts.OpenReader(r, src, pos);
  67.     IF len >= LEN(s) THEN len := SHORT(LEN(s)) - 1 END;
  68.     i := 0; WHILE i < len DO Texts.Read(r, s[i]); INC(i) END;
  69.     s[i] := 0X
  70. END GetName;
  71. PROCEDURE StdErrorProc* (n: INTEGER; pos: LONGINT);
  72. BEGIN INC(errors) END StdErrorProc;
  73. PROCEDURE Reset* (t: Texts.Text; pos: LONGINT; errProc: ErrorProc);
  74. BEGIN
  75.     src := t; Error := errProc;
  76.     Texts.OpenReader(r, src, pos);
  77.     chPos := pos - 1; chLine := 1; lineStart := 0;
  78.     oldEols := 0; apx := 0; errors := 0;
  79.     NextCh
  80. END Reset;
  81. BEGIN
  82. -->initialization
  83. END -->modulename.
  84.