1 %option never-interactive
4 /* web2c-lexer.l -- lexical analysis for Tangle output. Public domain. */
7 #include "web2c-parser.h"
11 /* Hack to make it possible to compile the generated code with C++
12 Required if you use flex. */
14 #define webinput yyinput
16 #define webinput input
19 /* For some reason flex wants to do a system call, so we must lose our
20 definition of the Pascal read. */
23 char conditional[20], negbuf[2], temp[20];
24 extern boolean doing_statements;
27 /* We only read one input file. This is the default definition, but
28 giving it ourselves avoids the need to find -lfl or -ll at link time.
29 This is a good thing, since libfl.a is often installed somewhere that
30 the linker doesn't search by default. */
36 #define YY_SKIP_YYWRAP /* not that it matters */
40 ALPHANUM ({DIGIT}|{ALPHA}|"_")
41 IDENTIFIER ({ALPHA}{ALPHANUM}*)
44 SIGNED ({SIGN}?{NUMBER})
46 REAL ({NUMBER}"."{NUMBER}("e"{SIGNED})?)|({NUMBER}"e"{SIGNED})
47 COMMENT (("{"[^}]*"}")|("(*"([^*]|"*"[^)])*"*)"))
48 W ({WHITE}|"packed ")+
49 WW ({WHITE}|{COMMENT}|"packed ")*
50 HHB0 ("hh"{WW}"."{WW}"b0")
51 HHB1 ("hh"{WW}"."{WW}"b1")
55 "{" { while (webinput() != '}'); }
60 while ((c = webinput()) && c != ';')
65 "ifdef(" {register int c;
66 register char *cp=conditional;
68 while ((c = webinput()) != '\'')
70 while ((c = webinput()) != '\'')
74 if (doing_statements) fputs("\t;\n", out);
75 fprintf(out, "#ifdef %s\n", conditional);
78 "endif(" {register int c;
80 fputs("#endif /* ", out);
81 while ((c = webinput()) != '\'')
83 while ((c = webinput()) != '\'')
86 conditional[0] = '\0';
90 "ifndef(" {register int c;
91 register char *cp=conditional;
93 while ((c = webinput()) != '\'')
95 while ((c = webinput()) != '\'')
99 if (doing_statements) fputs("\t;\n", out);
100 fprintf(out, "#ifndef %s\n", conditional);
103 "endifn(" {register int c;
105 fputs("#endif /* not ", out);
106 while ((c = webinput()) != '\'')
108 while ((c = webinput()) != '\'')
111 conditional[0] = '\0';
116 "procedure "[a-z_]+";"[ \n\t]*"forward;" ;
118 "function "[(),:a-z_]+";"[ \n\t]*"forward;" ;
120 "@define" return last_tok=define_tok;
121 "@field" return last_tok=field_tok;
122 "and" return last_tok=and_tok;
123 "array" return last_tok=array_tok;
124 "begin" return last_tok=begin_tok;
125 "case" return last_tok=case_tok;
126 "const" return last_tok=const_tok;
127 "div" return last_tok=div_tok;
128 "break" return last_tok=break_tok;
129 "do" return last_tok=do_tok;
130 "downto" return last_tok=downto_tok;
131 "else" return last_tok=else_tok;
132 "end" return last_tok=end_tok;
133 "file" return last_tok=file_tok;
134 "for" return last_tok=for_tok;
135 "function" return last_tok=function_tok;
136 "goto" return last_tok=goto_tok;
137 "if" return last_tok=if_tok;
138 "label" return last_tok=label_tok;
139 "mod" return last_tok=mod_tok;
140 "noreturn" return last_tok=noreturn_tok;
141 "not" return last_tok=not_tok;
142 "of" return last_tok=of_tok;
143 "or" return last_tok=or_tok;
144 "procedure" return last_tok=procedure_tok;
145 "program" return last_tok=program_tok;
146 "record" return last_tok=record_tok;
147 "repeat" return last_tok=repeat_tok;
148 {HHB0} return last_tok=hhb0_tok;
149 {HHB1} return last_tok=hhb1_tok;
150 "then" return last_tok=then_tok;
151 "to" return last_tok=to_tok;
152 "type" return last_tok=type_tok;
153 "until" return last_tok=until_tok;
154 "var" return last_tok=var_tok;
155 "while" return last_tok=while_tok;
156 "others" return last_tok=others_tok;
159 sprintf (temp, "%s%s", negbuf, yytext);
161 return last_tok=r_num_tok;
165 sprintf (temp, "%s%s", negbuf, yytext);
167 return last_tok=i_num_tok;
170 ("'"([^']|"''")"'") return last_tok=single_char_tok;
172 ("'"([^']|"''")*"'") return last_tok=string_literal_tok;
174 "+" { if ((last_tok>=undef_id_tok &&
175 last_tok<=field_id_tok) ||
176 last_tok==i_num_tok ||
177 last_tok==r_num_tok ||
181 else return last_tok=unary_plus_tok; }
183 "-" { if ((last_tok>=undef_id_tok &&
184 last_tok<=field_id_tok) ||
185 last_tok==i_num_tok ||
186 last_tok==r_num_tok ||
192 while ((c = webinput()) == ' ' || c == '\t')
195 if (c < '0' || c > '9') {
196 return last_tok = unary_minus_tok;
201 "*" return last_tok='*';
202 "/" return last_tok='/';
203 "=" return last_tok='=';
204 "<>" return last_tok=not_eq_tok;
205 "<" return last_tok='<';
206 ">" return last_tok='>';
207 "<=" return last_tok=less_eq_tok;
208 ">=" return last_tok=great_eq_tok;
209 "(" return last_tok='(';
210 ")" return last_tok=')';
211 "[" return last_tok='[';
212 "]" return last_tok=']';
213 ":=" return last_tok=assign_tok;
214 ".." return last_tok=two_dots_tok;
215 "." return last_tok='.';
216 "," return last_tok=',';
217 ";" return last_tok=';';
218 ":" return last_tok=':';
219 "^" return last_tok='^';
221 {IDENTIFIER} { strcpy (last_id, yytext);
222 l_s = search_table (last_id);
224 last_tok = (l_s == -1 ? undef_id_tok : sym_table[l_s].typ);
228 . { /* Any bizarre token will do. */
229 return last_tok = two_dots_tok; }
231 /* Some helper routines. Defining these here means we don't have references
232 to yytext outside of this file. Which means we can omit one of the more
233 troublesome autoconf tests. */
235 get_string_literal (char *s)
240 for (i=1; yytext[i-1] != 0; i++) {
241 if (yytext[i] == '\\' || yytext[i] == '"')
243 else if (yytext[i] == '\'')
252 get_single_char (char *s)
255 if (yytext[1] == '\\' || yytext[1] == '\'') {
268 get_result_type (char *s)
274 /* Since a syntax error can never be recovered from, we exit here with
278 yyerror (const_string s)
280 /* This is so the convert script can delete the output file on error. */
284 fprintf (stderr, ": Last token = %d (%c), ", last_tok, last_tok);
285 fprintf (stderr, "error buffer = `%s',\n\t", yytext);
286 fprintf (stderr, "last id = `%s' (", last_id);
287 ii = search_table (last_id);
289 fputs ("not in symbol table", stderr);
291 switch (sym_table[ii].typ)
294 fputs ("undefined", stderr);
297 fputs ("variable", stderr);
300 fputs ("constant", stderr);
303 fputs ("type", stderr);
306 fputs ("parameterless procedure", stderr);
309 fputs ("procedure with parameters", stderr);
312 fputs ("parameterless function", stderr);
315 fputs ("function with parameters", stderr);
318 fputs ("unknown!", stderr);
321 fputs (").\n", stderr);
324 /* Avoid silly warnings. */