| 1 |
(* Copyright (C) 2005, 2006 Free Software Foundation, Inc. *) |
| 2 |
(* This file is part of GNU Modula-2. |
| 3 |
|
| 4 |
GNU Modula-2 is free software; you can redistribute it and/or modify it under |
| 5 |
the terms of the GNU General Public License as published by the Free |
| 6 |
Software Foundation; either version 2, or (at your option) any later |
| 7 |
version. |
| 8 |
|
| 9 |
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 |
for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License along |
| 15 |
with gm2; see the file COPYING. If not, write to the Free Software |
| 16 |
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *) |
| 17 |
|
| 18 |
MODULE sets3 ; |
| 19 |
|
| 20 |
FROM DynamicStrings IMPORT String, InitString, ConCat, Mark, ConCatChar ; |
| 21 |
FROM M2Printf IMPORT printf1, printf0 ; |
| 22 |
FROM M2LexBuf IMPORT GetToken ; |
| 23 |
(* FROM M2Reserved IMPORT toktype ; *) |
| 24 |
|
| 25 |
|
| 26 |
CONST |
| 27 |
Debugging = TRUE ; |
| 28 |
|
| 29 |
|
| 30 |
TYPE |
| 31 |
toktype = (eoftok, plustok, minustok, timestok, dividetok, becomestok, ambersandtok, periodtok, commatok, semicolontok, lparatok, rparatok, lsbratok, rsbratok, lcbratok, rcbratok, uparrowtok, singlequotetok, equaltok, hashtok, lesstok, greatertok, lessgreatertok, lessequaltok, greaterequaltok, periodperiodtok, colontok, doublequotestok, bartok, andtok, arraytok, begintok, bytok, casetok, consttok, definitiontok, divtok, dotok, elsetok, elsiftok, endtok, exittok, exporttok, fortok, fromtok, iftok, implementationtok, importtok, intok, looptok, modtok, moduletok, nottok, oftok, ortok, pointertok, proceduretok, qualifiedtok, unqualifiedtok, recordtok, repeattok, returntok, settok, thentok, totok, typetok, untiltok, vartok, whiletok, withtok, asmtok, volatiletok, periodperiodperiodtok, datetok, linetok, filetok, integertok, identtok, realtok, stringtok) ; |
| 32 |
|
| 33 |
|
| 34 |
SetOfStop0 = SET OF [eoftok..begintok] ; |
| 35 |
SetOfStop1 = SET OF [bytok..thentok] ; |
| 36 |
SetOfStop2 = SET OF [totok..stringtok] ; |
| 37 |
|
| 38 |
VAR |
| 39 |
currenttoken: toktype ; |
| 40 |
|
| 41 |
|
| 42 |
PROCEDURE ErrorString (s: String) ; |
| 43 |
BEGIN |
| 44 |
END ErrorString ; |
| 45 |
|
| 46 |
PROCEDURE DescribeError (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ; |
| 47 |
VAR |
| 48 |
str: String ; |
| 49 |
BEGIN |
| 50 |
str := InitString('') ; |
| 51 |
CASE currenttoken OF |
| 52 |
|
| 53 |
stringtok: str := ConCat(InitString("syntax error, found `string'"), Mark(str)) | |
| 54 |
realtok: str := ConCat(InitString("syntax error, found `real number'"), Mark(str)) | |
| 55 |
identtok: str := ConCat(InitString("syntax error, found `identifier'"), Mark(str)) | |
| 56 |
integertok: str := ConCat(InitString("syntax error, found `integer number'"), Mark(str)) | |
| 57 |
filetok: str := ConCat(InitString("syntax error, found `__FILE__'"), Mark(str)) | |
| 58 |
linetok: str := ConCat(InitString("syntax error, found `__LINE__'"), Mark(str)) | |
| 59 |
datetok: str := ConCat(InitString("syntax error, found `__DATE__'"), Mark(str)) | |
| 60 |
periodperiodperiodtok: str := ConCat(InitString("syntax error, found `...'"), Mark(str)) | |
| 61 |
volatiletok: str := ConCat(InitString("syntax error, found `VOLATILE'"), Mark(str)) | |
| 62 |
asmtok: str := ConCat(InitString("syntax error, found `ASM'"), Mark(str)) | |
| 63 |
withtok: str := ConCat(InitString("syntax error, found `WITH'"), Mark(str)) | |
| 64 |
whiletok: str := ConCat(InitString("syntax error, found `WHILE'"), Mark(str)) | |
| 65 |
vartok: str := ConCat(InitString("syntax error, found `VAR'"), Mark(str)) | |
| 66 |
untiltok: str := ConCat(InitString("syntax error, found `UNTIL'"), Mark(str)) | |
| 67 |
typetok: str := ConCat(InitString("syntax error, found `TYPE'"), Mark(str)) | |
| 68 |
totok: str := ConCat(InitString("syntax error, found `TO'"), Mark(str)) | |
| 69 |
thentok: str := ConCat(InitString("syntax error, found `THEN'"), Mark(str)) | |
| 70 |
settok: str := ConCat(InitString("syntax error, found `SET'"), Mark(str)) | |
| 71 |
returntok: str := ConCat(InitString("syntax error, found `RETURN'"), Mark(str)) | |
| 72 |
repeattok: str := ConCat(InitString("syntax error, found `REPEAT'"), Mark(str)) | |
| 73 |
recordtok: str := ConCat(InitString("syntax error, found `RECORD'"), Mark(str)) | |
| 74 |
unqualifiedtok: str := ConCat(InitString("syntax error, found `UNQUALIFIED'"), Mark(str)) | |
| 75 |
qualifiedtok: str := ConCat(InitString("syntax error, found `QUALIFIED'"), Mark(str)) | |
| 76 |
proceduretok: str := ConCat(InitString("syntax error, found `PROCEDURE'"), Mark(str)) | |
| 77 |
pointertok: str := ConCat(InitString("syntax error, found `POINTER'"), Mark(str)) | |
| 78 |
ortok: str := ConCat(InitString("syntax error, found `OR'"), Mark(str)) | |
| 79 |
oftok: str := ConCat(InitString("syntax error, found `OF'"), Mark(str)) | |
| 80 |
nottok: str := ConCat(InitString("syntax error, found `NOT'"), Mark(str)) | |
| 81 |
moduletok: str := ConCat(InitString("syntax error, found `MODULE'"), Mark(str)) | |
| 82 |
modtok: str := ConCat(InitString("syntax error, found `MOD'"), Mark(str)) | |
| 83 |
looptok: str := ConCat(InitString("syntax error, found `LOOP'"), Mark(str)) | |
| 84 |
intok: str := ConCat(InitString("syntax error, found `IN'"), Mark(str)) | |
| 85 |
importtok: str := ConCat(InitString("syntax error, found `IMPORT'"), Mark(str)) | |
| 86 |
implementationtok: str := ConCat(InitString("syntax error, found `IMPLEMENTATION'"), Mark(str)) | |
| 87 |
iftok: str := ConCat(InitString("syntax error, found `IF'"), Mark(str)) | |
| 88 |
fromtok: str := ConCat(InitString("syntax error, found `FROM'"), Mark(str)) | |
| 89 |
fortok: str := ConCat(InitString("syntax error, found `FOR'"), Mark(str)) | |
| 90 |
exporttok: str := ConCat(InitString("syntax error, found `EXPORT'"), Mark(str)) | |
| 91 |
exittok: str := ConCat(InitString("syntax error, found `EXIT'"), Mark(str)) | |
| 92 |
endtok: str := ConCat(InitString("syntax error, found `END'"), Mark(str)) | |
| 93 |
elsiftok: str := ConCat(InitString("syntax error, found `ELSIF'"), Mark(str)) | |
| 94 |
elsetok: str := ConCat(InitString("syntax error, found `ELSE'"), Mark(str)) | |
| 95 |
dotok: str := ConCat(InitString("syntax error, found `DO'"), Mark(str)) | |
| 96 |
divtok: str := ConCat(InitString("syntax error, found `DIV'"), Mark(str)) | |
| 97 |
definitiontok: str := ConCat(InitString("syntax error, found `DEFINITION'"), Mark(str)) | |
| 98 |
consttok: str := ConCat(InitString("syntax error, found `CONST'"), Mark(str)) | |
| 99 |
casetok: str := ConCat(InitString("syntax error, found `CASE'"), Mark(str)) | |
| 100 |
bytok: str := ConCat(InitString("syntax error, found `BY'"), Mark(str)) | |
| 101 |
begintok: str := ConCat(InitString("syntax error, found `BEGIN'"), Mark(str)) | |
| 102 |
arraytok: str := ConCat(InitString("syntax error, found `ARRAY'"), Mark(str)) | |
| 103 |
andtok: str := ConCat(InitString("syntax error, found `AND'"), Mark(str)) | |
| 104 |
colontok: str := ConCat(InitString("syntax error, found `:'"), Mark(str)) | |
| 105 |
periodperiodtok: str := ConCat(InitString("syntax error, found `..'"), Mark(str)) | |
| 106 |
greaterequaltok: str := ConCat(InitString("syntax error, found `>='"), Mark(str)) | |
| 107 |
lessequaltok: str := ConCat(InitString("syntax error, found `<='"), Mark(str)) | |
| 108 |
lessgreatertok: str := ConCat(InitString("syntax error, found `<>'"), Mark(str)) | |
| 109 |
hashtok: str := ConCat(InitString("syntax error, found `#'"), Mark(str)) | |
| 110 |
equaltok: str := ConCat(InitString("syntax error, found `='"), Mark(str)) | |
| 111 |
uparrowtok: str := ConCat(InitString("syntax error, found `^'"), Mark(str)) | |
| 112 |
semicolontok: str := ConCat(InitString("syntax error, found `;'"), Mark(str)) | |
| 113 |
commatok: str := ConCat(InitString("syntax error, found `,'"), Mark(str)) | |
| 114 |
periodtok: str := ConCat(InitString("syntax error, found `.'"), Mark(str)) | |
| 115 |
ambersandtok: str := ConCat(InitString("syntax error, found `&'"), Mark(str)) | |
| 116 |
dividetok: str := ConCat(InitString("syntax error, found `/'"), Mark(str)) | |
| 117 |
timestok: str := ConCat(InitString("syntax error, found `*'"), Mark(str)) | |
| 118 |
minustok: str := ConCat(InitString("syntax error, found `-'"), Mark(str)) | |
| 119 |
plustok: str := ConCat(InitString("syntax error, found `+'"), Mark(str)) | |
| 120 |
doublequotestok: str := ConCat(ConCatChar(ConCatChar(InitString("syntax error, found '"), '"'), "'"), Mark(str)) | |
| 121 |
singlequotetok: str := ConCat(ConCatChar(ConCatChar(InitString('syntax error, found "'), "'"), '"'), Mark(str)) | |
| 122 |
greatertok: str := ConCat(InitString("syntax error, found `>'"), Mark(str)) | |
| 123 |
lesstok: str := ConCat(InitString("syntax error, found `<'"), Mark(str)) | |
| 124 |
rparatok: str := ConCat(InitString("syntax error, found `)'"), Mark(str)) | |
| 125 |
lparatok: str := ConCat(InitString("syntax error, found `('"), Mark(str)) | |
| 126 |
rcbratok: str := ConCat(InitString("syntax error, found `}'"), Mark(str)) | |
| 127 |
lcbratok: str := ConCat(InitString("syntax error, found `{'"), Mark(str)) | |
| 128 |
rsbratok: str := ConCat(InitString("syntax error, found `]'"), Mark(str)) | |
| 129 |
lsbratok: str := ConCat(InitString("syntax error, found `['"), Mark(str)) | |
| 130 |
bartok: str := ConCat(InitString("syntax error, found `|'"), Mark(str)) | |
| 131 |
becomestok: str := ConCat(InitString("syntax error, found `:='"), Mark(str)) | |
| 132 |
eoftok: str := ConCat(InitString("syntax error, found `'"), Mark(str)) |
| 133 |
ELSE |
| 134 |
END ; |
| 135 |
ErrorString(str) ; |
| 136 |
END DescribeError ; |
| 137 |
|
| 138 |
|
| 139 |
(* |
| 140 |
SyntaxError - after a syntax error we skip all tokens up until we reach |
| 141 |
a stop symbol. |
| 142 |
*) |
| 143 |
(* |
| 144 |
PROCEDURE SyntaxError (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ; |
| 145 |
BEGIN |
| 146 |
DescribeError(stopset0, stopset1, stopset2) ; |
| 147 |
IF Debugging |
| 148 |
THEN |
| 149 |
printf0('\nskipping token *** ') |
| 150 |
END ; |
| 151 |
(* |
| 152 |
yes the ORD(currenttoken) looks ugly, but it is *much* safer than |
| 153 |
using currenttoken<sometok as a change to the ordering of the |
| 154 |
token declarations below would cause this to break. Using ORD() we are |
| 155 |
immune from such changes |
| 156 |
*) |
| 157 |
WHILE NOT (((ORD(currenttoken)<32) AND (currenttoken IN stopset0)) OR |
| 158 |
((ORD(currenttoken)>=32) AND (ORD(currenttoken)<64) AND (currenttoken IN stopset1)) OR |
| 159 |
((ORD(currenttoken)>=64) AND (currenttoken IN stopset2))) |
| 160 |
DO |
| 161 |
GetToken |
| 162 |
END ; |
| 163 |
IF Debugging |
| 164 |
THEN |
| 165 |
printf0(' ***\n') |
| 166 |
END |
| 167 |
END SyntaxError ; |
| 168 |
*) |
| 169 |
|
| 170 |
|
| 171 |
BEGIN |
| 172 |
END sets3. |