ð#Syntax10.Scn.Fntï(ï((* scanner module generated by Coco-R *) MODULE PFS; IMPORT Texts, SYSTEM; CONST EOL = 0DX; EOF = 0X; maxLexLen = 127; noSym = 66; TYPE ErrorProc* = PROCEDURE (n: INTEGER; pos: LONGINT); StartTable = ARRAY 128 OF INTEGER; VAR src*: Texts.Text; (*source text. To be set by the main pgm*) pos*: LONGINT; (*position of current symbol*) line*, col*, len*: INTEGER; (*line, column, length of current symbol*) nextPos*: LONGINT; (*position of lookahead symbol*) nextLine*, nextCol*, nextLen*: INTEGER; (*line, column, length of lookahead symbol*) errors*: INTEGER; (*number of errors detected*) Error*: ErrorProc; ch: CHAR; (*current input character*) r: Texts.Reader; (*global reader*) chPos: LONGINT; (*position of current character*) chLine: INTEGER; (*current line number*) lineStart: LONGINT; (*start position of current line*) apx: INTEGER; (*length of appendix*) oldEols: INTEGER; (*nr. of EOLs in a comment*) start: StartTable; (*start state for every character*) PROCEDURE NextCh; (*return global variable ch*) BEGIN IF oldEols > 0 THEN DEC(oldEols); ch := EOL ELSE Texts.Read(r, ch); INC(chPos); IF ch = EOL THEN INC(chLine); lineStart := chPos + 1 END END END NextCh; PROCEDURE Comment(): BOOLEAN; VAR level, startLine: INTEGER; oldLineStart: LONGINT; BEGIN (*Comment*) level := 1; startLine := chLine; oldLineStart := lineStart; IF (ch ="(") THEN NextCh; IF (ch ="*") THEN NextCh; LOOP IF (ch ="*") THEN NextCh; IF (ch =")") THEN DEC(level); IF level=0 THEN oldEols := chLine - startLine; NextCh; RETURN TRUE END; NextCh; END; ELSIF (ch ="(") THEN NextCh; IF (ch ="*") THEN INC(level); NextCh; END; ELSIF ch = EOF THEN RETURN FALSE ELSE NextCh END; END; ELSE IF ch = EOL THEN DEC(chLine); lineStart := oldLineStart END; DEC(chPos, 2); Texts.OpenReader(r, src, chPos+1); NextCh; RETURN FALSE END END; END Comment; PROCEDURE Get*(VAR sym: INTEGER); VAR state: INTEGER; lexeme: ARRAY maxLexLen+1 OF CHAR; PROCEDURE CheckLiteral; BEGIN IF nextLen < maxLexLen THEN lexeme[nextLen] := 0X END; IF (lexeme[0] >= "A") & (lexeme[0] <= "W") THEN CASE lexeme[0] OF | "A": IF lexeme = "ARRAY" THEN sym := 23 END | "B": IF lexeme = "BEGIN" THEN sym := 8 ELSIF lexeme = "BY" THEN sym := 39 END | "C": IF lexeme = "CASE" THEN sym := 32 ELSIF lexeme = "CONST" THEN sym := 14 END | "D": IF lexeme = "DIV" THEN sym := 61 ELSIF lexeme = "DO" THEN sym := 35 END | "E": IF lexeme = "ELSE" THEN sym := 31 ELSIF lexeme = "ELSIF" THEN sym := 30 ELSIF lexeme = "END" THEN sym := 9 ELSIF lexeme = "EXIT" THEN sym := 42 END | "F": IF lexeme = "FOR" THEN sym := 38 END | "I": IF lexeme = "IF" THEN sym := 28 ELSIF lexeme = "IMPORT" THEN sym := 11 ELSIF lexeme = "IN" THEN sym := 56 ELSIF lexeme = "IS" THEN sym := 57 END | "L": IF lexeme = "LOOP" THEN sym := 40 END | "M": IF lexeme = "MOD" THEN sym := 62 ELSIF lexeme = "MODULE" THEN sym := 6 END | "N": IF lexeme = "NIL" THEN sym := 47 END | "O": IF lexeme = "OF" THEN sym := 24 ELSIF lexeme = "OR" THEN sym := 58 END | "P": IF lexeme = "POINTER" THEN sym := 26 ELSIF lexeme = "PROCEDURE" THEN sym := 17 END | "R": IF lexeme = "RECORD" THEN sym := 25 ELSIF lexeme = "REPEAT" THEN sym := 36 ELSIF lexeme = "RETURN" THEN sym := 43 END | "T": IF lexeme = "THEN" THEN sym := 29 ELSIF lexeme = "TO" THEN sym := 27 ELSIF lexeme = "TYPE" THEN sym := 15 END | "U": IF lexeme = "UNTIL" THEN sym := 37 END | "V": IF lexeme = "VAR" THEN sym := 16 END | "W": IF lexeme = "WHILE" THEN sym := 34 ELSIF lexeme = "WITH" THEN sym := 41 END ELSE END END; END CheckLiteral; BEGIN WHILE (ch=20X) OR (ch>=CHR(1)) & (ch<=CHR(31)) DO NextCh END; IF ((ch ="(")) & Comment() THEN Get(sym); RETURN END; IF ch > 7FX THEN ch := " " END; pos := nextPos; col := nextCol; line := nextLine; len := nextLen; nextPos := chPos; nextCol := SHORT(chPos - lineStart); nextLine := chLine; nextLen := 0; state := start[ORD(ch)]; apx := 0; LOOP IF nextLen < maxLexLen THEN lexeme[nextLen] := ch END; INC(nextLen); NextCh; IF state > 0 THEN CASE state OF | 1: IF (ch>="0") & (ch<="9") OR (ch>="A") & (ch<="Z") OR (ch>="a") & (ch<="z") THEN ELSE sym := 1; CheckLiteral; RETURN END; | 2: IF (ch<=CHR(12)) OR (ch>=CHR(14)) & (ch<="!") OR (ch>="#") THEN ELSIF (ch =CHR(34)) THEN state := 3; ELSE sym := noSym; RETURN END; | 3: sym := 2; RETURN | 4: IF (ch<=CHR(12)) OR (ch>=CHR(14)) & (ch<="&") OR (ch>="(") THEN ELSIF (ch ="'") THEN state := 3; ELSE sym := noSym; RETURN END; | 5: sym := 3; RETURN | 6: chPos := chPos - apx - 1; Texts.OpenReader(r, src, chPos+1); NextCh; sym := 4; RETURN | 7: IF (ch =".") THEN state := 8; INC(apx) ELSE sym := noSym; RETURN END; | 8: chPos := chPos - apx - 1; Texts.OpenReader(r, src, chPos+1); NextCh; sym := 4; RETURN | 9: IF (ch>="0") & (ch<="9") THEN ELSIF (ch>="D") & (ch<="E") THEN state := 10; ELSE sym := 5; RETURN END; | 10: IF (ch>="0") & (ch<="9") THEN state := 12; ELSIF (ch="+") OR (ch="-") THEN state := 11; ELSE sym := noSym; RETURN END; | 11: IF (ch>="0") & (ch<="9") THEN state := 12; ELSE sym := noSym; RETURN END; | 12: IF (ch>="0") & (ch<="9") THEN ELSE sym := 5; RETURN END; | 13: IF (ch>="A") & (ch<="F") THEN state := 14; ELSIF (ch>="0") & (ch<="9") THEN ELSIF (ch ="X") THEN state := 5; ELSIF (ch ="H") THEN state := 15; ELSIF (ch =".") THEN state := 16; INC(apx) ELSE sym := 4; RETURN END; | 14: IF (ch>="0") & (ch<="9") OR (ch>="A") & (ch<="F") THEN ELSIF (ch ="X") THEN state := 5; ELSIF (ch ="H") THEN state := 15; ELSE sym := noSym; RETURN END; | 15: IF (ch =".") THEN state := 7; INC(apx) ELSE sym := 4; RETURN END; | 16: IF (ch>="0") & (ch<="9") THEN state := 9; apx := 0 ELSIF (ch =".") THEN state := 6; INC(apx) ELSIF (ch>="D") & (ch<="E") THEN state := 10; apx := 0 ELSE sym := 5; RETURN END; | 17: sym := 7; RETURN | 18: IF (ch =".") THEN state := 27; ELSE sym := 10; RETURN END; | 19: IF (ch ="=") THEN state := 20; ELSE sym := 19; RETURN END; | 20: sym := 12; RETURN | 21: sym := 13; RETURN | 22: sym := 18; RETURN | 23: sym := 20; RETURN | 24: sym := 21; RETURN | 25: sym := 22; RETURN | 26: sym := 33; RETURN | 27: sym := 44; RETURN | 28: sym := 45; RETURN | 29: sym := 46; RETURN | 30: sym := 48; RETURN | 31: sym := 49; RETURN | 32: sym := 50; RETURN | 33: sym := 51; RETURN | 34: IF (ch ="=") THEN state := 35; ELSE sym := 52; RETURN END; | 35: sym := 53; RETURN | 36: IF (ch ="=") THEN state := 37; ELSE sym := 54; RETURN END; | 37: sym := 55; RETURN | 38: sym := 59; RETURN | 39: sym := 60; RETURN | 40: sym := 63; RETURN | 41: sym := 64; RETURN | 42: sym := 65; RETURN | 43: sym := 0; ch := 0X; RETURN END (*CASE*) ELSE sym := noSym; RETURN (*NextCh already done*) END (*IF*) END (*LOOP*) END Get; PROCEDURE GetName*(pos: LONGINT; len: INTEGER; VAR s: ARRAY OF CHAR); VAR i: INTEGER; r: Texts.Reader; BEGIN Texts.OpenReader(r, src, pos); IF len >= LEN(s) THEN len := SHORT(LEN(s)) - 1 END; i := 0; WHILE i < len DO Texts.Read(r, s[i]); INC(i) END; s[i] := 0X END GetName; PROCEDURE StdErrorProc* (n: INTEGER; pos: LONGINT); BEGIN INC(errors) END StdErrorProc; PROCEDURE Reset* (t: Texts.Text; pos: LONGINT; errProc: ErrorProc); BEGIN src := t; Error := errProc; Texts.OpenReader(r, src, pos); chPos := pos - 1; chLine := 1; lineStart := 0; oldEols := 0; apx := 0; errors := 0; NextCh END Reset; BEGIN start[0]:=43; start[1]:=0; start[2]:=0; start[3]:=0; start[4]:=0; start[5]:=0; start[6]:=0; start[7]:=0; start[8]:=0; start[9]:=0; start[10]:=0; start[11]:=0; start[12]:=0; start[13]:=0; start[14]:=0; start[15]:=0; start[16]:=0; start[17]:=0; start[18]:=0; start[19]:=0; start[20]:=0; start[21]:=0; start[22]:=0; start[23]:=0; start[24]:=0; start[25]:=0; start[26]:=0; start[27]:=0; start[28]:=0; start[29]:=0; start[30]:=0; start[31]:=0; start[32]:=0; start[33]:=0; start[34]:=2; start[35]:=33; start[36]:=0; start[37]:=0; start[38]:=40; start[39]:=4; start[40]:=24; start[41]:=25; start[42]:=38; start[43]:=28; start[44]:=21; start[45]:=29; start[46]:=18; start[47]:=39; start[48]:=13; start[49]:=13; start[50]:=13; start[51]:=13; start[52]:=13; start[53]:=13; start[54]:=13; start[55]:=13; start[56]:=13; start[57]:=13; start[58]:=19; start[59]:=17; start[60]:=34; start[61]:=22; start[62]:=36; start[63]:=0; start[64]:=0; start[65]:=1; start[66]:=1; start[67]:=1; start[68]:=1; start[69]:=1; start[70]:=1; start[71]:=1; start[72]:=1; start[73]:=1; start[74]:=1; start[75]:=1; start[76]:=1; start[77]:=1; start[78]:=1; start[79]:=1; start[80]:=1; start[81]:=1; start[82]:=1; start[83]:=1; start[84]:=1; start[85]:=1; start[86]:=1; start[87]:=1; start[88]:=1; start[89]:=1; start[90]:=1; start[91]:=41; start[92]:=0; start[93]:=42; start[94]:=23; start[95]:=0; start[96]:=0; start[97]:=1; start[98]:=1; start[99]:=1; start[100]:=1; start[101]:=1; start[102]:=1; start[103]:=1; start[104]:=1; start[105]:=1; start[106]:=1; start[107]:=1; start[108]:=1; start[109]:=1; start[110]:=1; start[111]:=1; start[112]:=1; start[113]:=1; start[114]:=1; start[115]:=1; start[116]:=1; start[117]:=1; start[118]:=1; start[119]:=1; start[120]:=1; start[121]:=1; start[122]:=1; start[123]:=31; start[124]:=26; start[125]:=32; start[126]:=30; start[127]:=0; END PFS.