2
/* web2c.l -- lexical analysis for Tangle output. Public domain. */
7
/* Hack to make it possible to compile the generated code with C++
8
Required if you use flex. */
10
#define webinput yyinput
12
#define webinput input
15
/* For some reason flex wants to do a system call, so we must lose our
16
definition of the Pascal read. */
19
char conditional[20], negbuf[2], temp[20];
20
extern boolean doing_statements;
23
/* We only read one input file. This is the default definition, but
24
giving it ourselves avoids the need to find -lfl or -ll at link time.
25
This is a good thing, since libfl.a is often installed somewhere that
26
the linker doesn't search by default. */
32
#define YY_SKIP_YYWRAP /* not that it matters */
36
ALPHANUM ({DIGIT}|{ALPHA})
37
IDENTIFIER ({ALPHA}{ALPHANUM}*)
40
SIGNED ({SIGN}?{NUMBER})
42
REAL ({NUMBER}"."{NUMBER}("e"{SIGNED})?)|({NUMBER}"e"{SIGNED})
43
COMMENT (("{"[^}]*"}")|("(*"([^*]|"*"[^)])*"*)"))
44
W ({WHITE}|"packed ")+
45
WW ({WHITE}|{COMMENT}|"packed ")*
46
HHB0 ("hh"{WW}"."{WW}"b0")
47
HHB1 ("hh"{WW}"."{WW}"b1")
51
"{" { while (webinput() != '}'); }
56
while ((c = webinput()) && c != ';')
61
"ifdef(" {register int c;
62
register char *cp=conditional;
64
while ((c = webinput()) != '\'')
66
while ((c = webinput()) != '\'')
70
if (doing_statements) fputs("\t;\n", out);
71
fprintf(out, "#ifdef %s\n", conditional);
74
"endif(" {register int c;
76
fputs("#endif /* ", out);
77
while ((c = webinput()) != '\'')
79
while ((c = webinput()) != '\'')
82
conditional[0] = '\0';
86
"ifndef(" {register int c;
87
register char *cp=conditional;
89
while ((c = webinput()) != '\'')
91
while ((c = webinput()) != '\'')
95
if (doing_statements) fputs("\t;\n", out);
96
fprintf(out, "#ifndef %s\n", conditional);
99
"endifn(" {register int c;
101
fputs("#endif /* not ", out);
102
while ((c = webinput()) != '\'')
104
while ((c = webinput()) != '\'')
107
conditional[0] = '\0';
112
"procedure "[a-z]+";"[ \n\t]*"forward;" ;
114
"function "[(),:a-z]+";"[ \n\t]*"forward;" ;
116
"@define" return last_tok=define_tok;
117
"@field" return last_tok=field_tok;
118
"and" return last_tok=and_tok;
119
"array" return last_tok=array_tok;
120
"begin" return last_tok=begin_tok;
121
"case" return last_tok=case_tok;
122
"const" return last_tok=const_tok;
123
"div" return last_tok=div_tok;
124
"break" return last_tok=break_tok;
125
"do" return last_tok=do_tok;
126
"downto" return last_tok=downto_tok;
127
"else" return last_tok=else_tok;
128
"end" return last_tok=end_tok;
129
"file" return last_tok=file_tok;
130
"for" return last_tok=for_tok;
131
"function" return last_tok=function_tok;
132
"goto" return last_tok=goto_tok;
133
"if" return last_tok=if_tok;
134
"label" return last_tok=label_tok;
135
"mod" return last_tok=mod_tok;
136
"not" return last_tok=not_tok;
137
"of" return last_tok=of_tok;
138
"or" return last_tok=or_tok;
139
"procedure" return last_tok=procedure_tok;
140
"program" return last_tok=program_tok;
141
"record" return last_tok=record_tok;
142
"repeat" return last_tok=repeat_tok;
143
{HHB0} return last_tok=hhb0_tok;
144
{HHB1} return last_tok=hhb1_tok;
145
"then" return last_tok=then_tok;
146
"to" return last_tok=to_tok;
147
"type" return last_tok=type_tok;
148
"until" return last_tok=until_tok;
149
"var" return last_tok=var_tok;
150
"while" return last_tok=while_tok;
151
"others" return last_tok=others_tok;
154
sprintf (temp, "%s%s", negbuf, yytext);
156
return last_tok=r_num_tok;
160
sprintf (temp, "%s%s", negbuf, yytext);
162
return last_tok=i_num_tok;
165
("'"([^']|"''")"'") return last_tok=single_char_tok;
167
("'"([^']|"''")*"'") return last_tok=string_literal_tok;
169
"+" { if ((last_tok>=undef_id_tok &&
170
last_tok<=field_id_tok) ||
171
last_tok==i_num_tok ||
172
last_tok==r_num_tok ||
176
else return last_tok=unary_plus_tok; }
178
"-" { if ((last_tok>=undef_id_tok &&
179
last_tok<=field_id_tok) ||
180
last_tok==i_num_tok ||
181
last_tok==r_num_tok ||
187
while ((c = webinput()) == ' ' || c == '\t')
190
if (c < '0' || c > '9') {
191
return last_tok = unary_minus_tok;
196
"*" return last_tok='*';
197
"/" return last_tok='/';
198
"=" return last_tok='=';
199
"<>" return last_tok=not_eq_tok;
200
"<" return last_tok='<';
201
">" return last_tok='>';
202
"<=" return last_tok=less_eq_tok;
203
">=" return last_tok=great_eq_tok;
204
"(" return last_tok='(';
205
")" return last_tok=')';
206
"[" return last_tok='[';
207
"]" return last_tok=']';
208
":=" return last_tok=assign_tok;
209
".." return last_tok=two_dots_tok;
210
"." return last_tok='.';
211
"," return last_tok=',';
212
";" return last_tok=';';
213
":" return last_tok=':';
214
"^" return last_tok='^';
216
{IDENTIFIER} { strcpy (last_id, yytext);
217
l_s = search_table (last_id);
219
last_tok = (l_s == -1 ? undef_id_tok : sym_table[l_s].typ);
223
. { /* Any bizarre token will do. */
224
return last_tok = two_dots_tok; }
226
/* Some helper routines. Defining these here means we don't have references
227
to yytext outside of this file. Which means we can omit one of the more
228
troublesome autoconf tests. */
230
get_string_literal P1C(char *, s)
235
for (i=1; yytext[i-1] != 0; i++) {
236
if (yytext[i] == '\\' || yytext[i] == '"')
238
else if (yytext[i] == '\'')
247
get_single_char P1C(char *, s)
250
if (yytext[1] == '\\' || yytext[1] == '\'') {
263
get_result_type P1C(char *, s)
269
/* Since a syntax error can never be recovered from, we exit here with
273
yyerror P1C(string, s)
275
/* This is so the convert script can delete the output file on error. */
279
fprintf (stderr, ": Last token = %d (%c), ", last_tok, last_tok);
280
fprintf (stderr, "error buffer = `%s',\n\t", yytext);
281
fprintf (stderr, "last id = `%s' (", last_id);
282
ii = search_table (last_id);
284
fputs ("not in symbol table", stderr);
286
switch (sym_table[ii].typ)
289
fputs ("undefined", stderr);
292
fputs ("variable", stderr);
295
fputs ("constant", stderr);
298
fputs ("type", stderr);
301
fputs ("parameterless procedure", stderr);
304
fputs ("procedure with parameters", stderr);
307
fputs ("parameterless function", stderr);
310
fputs ("function with parameters", stderr);
313
fputs ("unknown!", stderr);
316
fputs (").\n", stderr);
319
/* Avoid silly warnings. */