2 /* $Id: lex.l,v 1.8 1994/06/24 12:27:04 ceriel Exp $ */
4 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
5 * See the copyright notice in the ACK home directory, in the file "Copyright".
11 # define TAB 8 /* Size of a acsii tab (\t) in spaces */
13 # define TABSTOP(ind) ((ind)+TAB-(ind)%TAB)
15 # define TABSTOP(ind) (((ind)+TAB)&(~(TAB-1)))
18 char *Malloc(), *strcpy();
21 int ind=0; /* Indentation level of current line */
22 static int tab=0; /* First indentation found */
24 int included=0; /* Is current file included? */
29 '((\*[^\n])|([^'\n*]))*' {
30 if ((token.t_lval=char_constant(yytext+1))== -1L)
31 report("%s not a character constant", yytext);
41 \"((\*[^\n])|([^"\n*]))*\" {
44 token.t_sval=string(yytext);
49 report("missing \".");
54 #[ \t]*"line"?[ \t]*[0-9]+[ \t]*\"[^"\n]*\" {
55 set_line_file(yytext);
61 token.t_lval=hex_number(yytext+1);
68 token.t_lval=number(yytext);
72 [A-Za-z][A-Za-z0-9.]* {
75 if ((key=keyword(yytext))==IDENTIFIER)
76 token.t_sval=strcpy(Malloc(yyleng+1), yytext);
80 \n[ \f\t]*/"--" {/* Line with only a comment, don't set tab */
87 ind=indentation(yytext+1);
92 warning("indentation not on a %d space boundary", tab);
94 [ \f\t] { /* Nothing */ }
95 [-=<>:,;+*/\[\]()?!&] return yytext[0];
108 "--"[^\n]* { /* Comment is skipped */ }
110 warning((' '<=yytext[0] && yytext[0]<0177) ? "%s'%c')" : "%soctal: %o)",
111 "bad character seen (", yytext[0]&0377);
114 char *string(s) char *s;
121 while (*str != '"') {
122 if ((c=character(&str)) != -1)
133 long number(s) register char *s;
135 static char max_str[]="2147483647";
136 int maxlen=sizeof max_str-1;
140 while (*s=='0') { /* skip leading nulls */
148 if ((yyleng>maxlen) || (yyleng==maxlen && strcmp(s, max_str)>0))
149 warning("integer constant overflow.");
157 long hex_number(s) register char *s;
162 number=(number<<4)+hextoint(*s++);
167 int hextoint(c) register c;
182 int character(S) register char **S;
184 register char *s= *S;
187 if ((c= *s++)=='*') {
202 if (isxdigit(c= *s++) && isxdigit(*s)) {
203 cc= (hextoint(c)<<4)+hextoint(*s++);
206 report("two digit hexadecimal const expected.");
220 int char_constant(s) char *s;
226 return (*s=='\'' && cc!= -1) ? cc : -1;
229 int indentation(s) register char *s;
246 int tabulated(oind, ind) register oind, ind;
248 if (tab>0 && ind>oind+tab)
249 warning("process' indentation too large (changed to %d tab%s)",
250 oind/tab+1, oind>=tab ? "s" : "");
255 struct token rep_token;
257 void repeat_token(tk)
276 char *tokenname(tk, inst) register tk, inst;
281 if (' '<tk && tk<='~')
282 sprint(c, "'%c'", tk);
284 sprint(c, "'*#%02x'", tk);
289 char fake_id[1+sizeof(int)*3+1];
295 sprint(fake_id, "_%d", ++fake_cnt);
296 token.t_sval=strcpy(Malloc(strlen(fake_id)+1),
307 token.t_sval=Malloc(1);
312 case AS: case LE: case GE: case NE:
313 case LS: case RS: case BA: case BO:
316 AS, LE, GE, NE, LS, RS, BA, BO, BX, BS
318 static char *opc[]= {
319 ":=", "<=", ">=", "<>", "<<", ">>", "/\\",
325 for (i=0; op[i]!=tk; i++) ;
326 sprint(qopc, "'%s'", opc[i]);
333 set_line_file(l) register char *l;
337 while (*l<'0' || *l>'9') l++;
340 while ('0'<=*l && *l<='9')
341 lineno=lineno*10+(*l++ - '0');
351 included=set_file(file);