3 * Copyright (C) 1991,1992 Erik Schoenfelder (schoenfr@ibr.cs.tu-bs.de)
5 * This file is part of NASE A60.
7 * NASE A60 is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * NASE A60 is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with NASE A60; see the file COPYING. If not, write to the Free
19 * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Erik Schoenfelder (schoenfr@ibr.cs.tu-bs.de)
25 * this part is obsolete and replaced by a60-scan.[ch]
26 * if you like to use this, complete the keyword scanning (only
27 * 'begin' and 'end' are enclosed)
31 * special for including "comm.h" :
33 #define THIS_IS_A60_LEX
35 #undef THIS_IS_A60_LEX
40 * this should be ``a60-parse.tab.h'' but there are some systems ...
41 * so the names are still short...
47 * better use ctype.h ...
49 #define misupper(c) ((c) >= 'A' && (c) <= 'Z')
50 #define mtolower(c) ((c) - 'A' + 'a')
52 /* current line number. */
64 #else /* ! FLEX_SCANNER */
69 #endif /* ! FLEX_SCANNER */
73 /* if they use it - i'll provide it: */
79 * initalize lex-module.
91 * scan the real number from the buffer and return them.
105 if (sscanf (s, fmt, &x) < 1) {
106 a60_error (infname, lineno,
107 "INTERNAL: cannot scan from `%s'\n", s);
108 xabort ("INTERNAL ERROR");
112 printf ("** do_scan_real: `%s' -> %.10g\n", s, x);
119 * convert the scanned string from c-like notation.
130 tmp = NTALLOC(len - 1, char);
135 for (i=1, ptr=tmp; i < len-1; i++, ptr++) {
140 else if (s[i] == '\\')
142 else if (s[i] == '\0')
157 * handle this unknown char; skip input til end-of-line.
164 static int last_line = -1;
166 if (last_line == lineno)
171 if (ch >= ' ' && ch <= 'Z')
172 a60_error (infname, lineno,
173 "unknown char `%c' found - skipping to next line\n",
176 a60_error (infname, lineno,
177 "unknown char 0x%02x found - skipping to next line\n",
183 } while (ch && ch != '\n');
195 word [a-zA-Z][a-zA-Z0-9 ]*
197 string `[^']*'|"'('"[^']*"')'"|\"[^"]*\"
201 ureal {uint}"."{uint}|"."{uint}
203 white " "|"\t"|"\f"|"\r"|"\n"
205 single "+"|"-"|"*"|"/"|","|"."|";"|"("|")"
209 'begin' return TBEGIN;
214 {single} return *yytext;
221 ":="|".=" return TASSIGN;
226 "<=" return TNOTGREATER;
227 ">=" return TNOTLESS;
229 {white}* { char *s = (char *) yytext;
231 lineno += (*s == '\n');
234 {string} { yylval.str = scan_string (yytext);
238 {ureal} { yylval.rtype = scan_real (yytext);
242 {uint} { extern long atol ();
243 yylval.itype = atol (yytext);
247 {word} { char *str = xstrdup ((char *) yytext);
252 ^#!.* { if (lineno != 1)
253 yywarning ("directive ignored");
256 . handle_unknown (*yytext & 0xff);
271 * if there is a ``parse error'' or a ``syntax error''
272 * reported from the skeleton, print the scanned string too.
274 if (! strcmp (s, "parse error")
275 || ! strcmp (s, "syntax error")) {
276 a60_error (infname, lineno, "%s (scanned `%s')\n",
277 s, (yytext && *yytext) ? (char *) yytext : "EOF");
280 a60_error (infname, lineno, "%s\n", s);
287 a60_error (infname, lineno, "warning: %s\n", s);
302 #endif /* ! FLEX_SCANNER */
304 /* end of a60-lex.l */