4 * (C) Copyright 1989-1995
13 * Extensions: P. Felber, M. Hope
24 * The module aslex.c includes the general lexical
25 * analysis routines for the assembler.
27 * aslex.c contains the following functions:
38 * aslex.c contains no local/static variables
41 /*)Function VOID getid(id,c)
43 * char * id a pointer to a string of
46 * >=0 this is first character to
47 * copy to the string buffer
48 * <0 skip white space, first
49 * character must be a LETTER
51 * The function getid() scans the current assembler-source text line
52 * from the current position copying the next LETTER | DIGIT string
53 * into the external string buffer (id). The string ends when a non
54 * LETTER or DIGIT character is found. The maximum number of
55 * characters copied is NCPS. If the input string is larger than
56 * NCPS characters then the string is truncated, if the input string
57 * is shorter than NCPS characters then the string is NULL filled.
58 * If the mode argument (c) is >=0 then (c) is the first character
59 * copied to the string buffer, if (c) is <0 then intervening white
60 * space (SPACES and TABS) are skipped and the first character found
61 * must be a LETTER else a 'q' error terminates the parse of this
62 * assembler-source text line.
65 * char * p pointer to external string buffer
66 * int c current character value
69 * char ctype[] a character array which defines the
70 * type of character being processed.
71 * This index is the character
76 * char getnb() aslex.c
77 * VOID unget() aslex.c
80 * use of getnb(), get(), and unget() updates the
81 * global pointer ip, the position in the current
82 * assembler-source text line.
94 if ((ctype[c] & LETTER) == 0)
101 } while (ctype[c=get()] & (LETTER|DIGIT));
103 while (p < &id[NCPS])
107 /*)Function VOID getst(id,c)
109 * char * id a pointer to a string of
110 * maximum length NCPS
112 * >=0 this is first character to
113 * copy to the string buffer
114 * <0 skip white space, first
115 * character must be a LETTER
117 * The function getnbid() scans the current assembler-source text line
118 * from the current position copying the next character string into
119 * the external string buffer (id). The string ends when a SPACE or
120 * ILL character is found. The maximum number of
121 * characters copied is NCPS. If the input string is larger than
122 * NCPS characters then the string is truncated, if the input string
123 * is shorter than NCPS characters then the string is NULL filled.
124 * If the mode argument (c) is >=0 then (c) is the first character
125 * copied to the string buffer, if (c) is <0 then intervening white
126 * space (SPACES and TABS) are skipped and the first character found
127 * must be a LETTER else a 'q' error terminates the parse of this
128 * assembler-source text line.
131 * char * p pointer to external string buffer
132 * int c current character value
135 * char ctype[] a character array which defines the
136 * type of character being processed.
137 * This index is the character
142 * char getnb() aslex.c
143 * VOID unget() aslex.c
146 * use of getnb(), get(), and unget() updates the
147 * global pointer ip, the position in the current
148 * assembler-source text line.
160 if ((ctype[c] & LETTER) == 0)
167 } while (ctype[c=get()] & (0xFF - (SPACE|ILL)));
169 while (p < &id[NCPS])
173 /*)Function char getnb()
175 * The function getnb() scans the current assembler-source
176 * text line returning the first character not a SPACE or TAB.
179 * int c current character from
180 * assembler-source text line
189 * use of get() updates the global pointer ip, the position
190 * in the current assembler-source text line
198 while ((c=get()) == ' ' || c == '\t')
203 /*)Function char get()
205 * The function get() returns the next character in the
206 * assembler-source text line, at the end of the line a
207 * NULL character is returned.
210 * int c current character from
211 * assembler-source text line
214 * char * ip pointer into the current
215 * assembler-source text line
221 * updates ip to the next character position in the
222 * assembler-source text line. If ip is at the end of the
223 * line, ip is not updated.
236 /*)Function VOID unget(c)
238 * int c value of last character read from
239 * assembler-source text line
241 * If (c) is not a NULL character then the global pointer ip
242 * is updated to point to the preceeding character in the
243 * assembler-source text line.
245 * NOTE: This function does not push the character (c)
246 * back into the assembler-source text line, only
247 * the pointer ip is changed.
250 * int c last character read from
251 * assembler-source text line
254 * char * ip position into the current
255 * assembler-source text line
261 * ip decremented by 1 character position
272 /*)Function int getmap(d)
274 * int d value to compare with the
275 * assembler-source text line character
277 * The function getmap() converts the 'C' style characters \b, \f,
278 * \n, \r, and \t to their equivalent ascii values and also
279 * converts 'C' style octal constants '\123' to their equivalent
280 * numeric values. If the first character is equivalent to (d) then
281 * a (-1) is returned, if the end of the line is detected then
282 * a 'q' error terminates the parse for this line, or if the first
283 * character is not a \ then the character value is returned.
286 * int c value of character from the
287 * assembler-source text line
288 * int n looping counter
289 * int v current value of numeric conversion
298 * use of get() updates the global pointer ip the position
299 * in the current assembler-source text line
305 register int c, n, v;
307 if ((c=get()) == '\0')
345 while (++n<=3 && c>='0' && c<='7') {
346 v = (v<<3) + c - '0';
357 /*)Function int as_getline()
359 * The function as_getline() reads a line of assembler-source text
360 * from an assembly source text file or an include file.
361 * Lines of text are processed from assembler-source files until
362 * all files have been read. If an include file is opened then
363 * lines of text are read from the include file (or nested
364 * include file) until the end of the include file is found.
365 * The input text line is copied into the global string ib[]
366 * and converted to a NULL terminated string. The function
367 * as_getline() returns a (1) after succesfully reading a line
368 * or a (0) if all files have been read.
371 * int i string length
374 * char ib[] string buffer containing
375 * assembler-source text line
376 * char ifp[] array of file handles for
378 * int incfil index for ifp[] specifies
379 * active include file
380 * int incline[] array of include file
382 * char sfp[] array of file handles for
383 * assembler source files
384 * int cfile index for sfp[] specifies
386 * int srcline[] array of source file
388 * int inpfil maximum input file index
391 * int fclose() c-library
392 * char * fgets() c-library
393 * int strlen() c-library
396 * include file will be closed at detection of end of file.
397 * the next sequential source file may be selected.
398 * the global file indexes incfil or cfile may be changed.
399 * The respective source line or include line counter
408 loop: if (incfil >= 0) {
409 if (fgets(ib, sizeof ib, ifp[incfil]) == NULL) {
412 ifp[incfil--] = NULL;
414 fclose(ifp[incfil--]);
422 if (fgets(ib, sizeof ib, sfp[cfile]) == NULL) {
423 if (++cfile <= inpfil) {
435 if (i >= 1 && ib[i-1] == '\r')
440 /*)Function int more()
442 * The function more() scans the assembler-source text line
443 * skipping white space (SPACES and TABS) and returns a (0)
444 * if the end of the line or a comment delimeter (;) is found,
445 * or a (1) if their are additional characters in the line.
448 * int c next character from the
449 * assembler-source text line
455 * char getnb() aslex.c
456 * VOID unget() aslex.c
459 * use of getnb() and unget() updates the global pointer ip
460 * the position in the current assembler-source text line
470 return( (c == '\0' || c == ';') ? 0 : 1 );
473 /*)Function char endline()
475 * The function endline() scans the assembler-source text line
476 * skipping white space (SPACES and TABS) and returns the next
477 * character or a (0) if the end of the line is found or a
478 * comment delimiter (;) is found.
481 * int c next character from the
482 * assembler-source text line
488 * char getnb() aslex.c
491 * use of getnb() updates the global pointer ip the
492 * position in the current assembler-source text line
501 return( (c == '\0' || c == ';') ? 0 : c );