4 * (C) Copyright 1989-1995
11 * 28-Oct-97 JLH bug in getst(): sign extend on ~(SPACE|ILL)
12 * causes infinite loop
23 * The module aslex.c includes the general lexical
24 * analysis routines for the assembler.
26 * aslex.c contains the following functions:
37 * aslex.c contains no local/static variables
40 /*)Function VOID getid(id,c)
42 * char * id a pointer to a string of
45 * >=0 this is first character to
46 * copy to the string buffer
47 * <0 skip white space, first
48 * character must be a LETTER
50 * The function getid() scans the current assembler-source text line
51 * from the current position copying the next LETTER | DIGIT string
52 * into the external string buffer (id). The string ends when a non
53 * LETTER or DIGIT character is found. The maximum number of
54 * characters copied is NCPS. If the input string is larger than
55 * NCPS characters then the string is truncated, if the input string
56 * is shorter than NCPS characters then the string is NULL filled.
57 * If the mode argument (c) is >=0 then (c) is the first character
58 * copied to the string buffer, if (c) is <0 then intervening white
59 * space (SPACES and TABS) are skipped and the first character found
60 * must be a LETTER else a 'q' error terminates the parse of this
61 * assembler-source text line.
64 * char * p pointer to external string buffer
65 * int c current character value
68 * char ctype[] a character array which defines the
69 * type of character being processed.
70 * This index is the character
75 * char getnb() aslex.c
76 * VOID unget() aslex.c
79 * use of getnb(), get(), and unget() updates the
80 * global pointer ip, the position in the current
81 * assembler-source text line.
93 if ((ctype[c] & LETTER) == 0)
100 } while (ctype[c=get()] & (LETTER|DIGIT));
102 while (p < &id[NCPS])
106 /*)Function VOID getst(id,c)
108 * char * id a pointer to a string of
109 * maximum length NCPS
111 * >=0 this is first character to
112 * copy to the string buffer
113 * <0 skip white space, first
114 * character must be a LETTER
116 * The function getnbid() scans the current assembler-source text line
117 * from the current position copying the next character string into
118 * the external string buffer (id). The string ends when a SPACE or
119 * ILL character is found. The maximum number of
120 * characters copied is NCPS. If the input string is larger than
121 * NCPS characters then the string is truncated, if the input string
122 * is shorter than NCPS characters then the string is NULL filled.
123 * If the mode argument (c) is >=0 then (c) is the first character
124 * copied to the string buffer, if (c) is <0 then intervening white
125 * space (SPACES and TABS) are skipped and the first character found
126 * must be a LETTER else a 'q' error terminates the parse of this
127 * assembler-source text line.
130 * char * p pointer to external string buffer
131 * int c current character value
134 * char ctype[] a character array which defines the
135 * type of character being processed.
136 * This index is the character
141 * char getnb() aslex.c
142 * VOID unget() aslex.c
145 * use of getnb(), get(), and unget() updates the
146 * global pointer ip, the position in the current
147 * assembler-source text line.
159 if ((ctype[c] & LETTER) == 0)
166 } while (ctype[c=get()] & (0xFF - (SPACE|ILL)));
168 while (p < &id[NCPS])
172 /*)Function char getnb()
174 * The function getnb() scans the current assembler-source
175 * text line returning the first character not a SPACE or TAB.
178 * int c current character from
179 * assembler-source text line
188 * use of get() updates the global pointer ip, the position
189 * in the current assembler-source text line
197 while ((c=get()) == ' ' || c == '\t')
202 /*)Function char get()
204 * The function get() returns the next character in the
205 * assembler-source text line, at the end of the line a
206 * NULL character is returned.
209 * int c current character from
210 * assembler-source text line
213 * char * ip pointer into the current
214 * assembler-source text line
220 * updates ip to the next character position in the
221 * assembler-source text line. If ip is at the end of the
222 * line, ip is not updated.
235 /*)Function VOID unget(c)
237 * int c value of last character read from
238 * assembler-source text line
240 * If (c) is not a NULL character then the global pointer ip
241 * is updated to point to the preceeding character in the
242 * assembler-source text line.
244 * NOTE: This function does not push the character (c)
245 * back into the assembler-source text line, only
246 * the pointer ip is changed.
249 * int c last character read from
250 * assembler-source text line
253 * char * ip position into the current
254 * assembler-source text line
260 * ip decremented by 1 character position
271 /*)Function int getmap(d)
273 * int d value to compare with the
274 * assembler-source text line character
276 * The function getmap() converts the 'C' style characters \b, \f,
277 * \n, \r, and \t to their equivalent ascii values and also
278 * converts 'C' style octal constants '\123' to their equivalent
279 * numeric values. If the first character is equivalent to (d) then
280 * a (-1) is returned, if the end of the line is detected then
281 * a 'q' error terminates the parse for this line, or if the first
282 * character is not a \ then the character value is returned.
285 * int c value of character from the
286 * assembler-source text line
287 * int n looping counter
288 * int v current value of numeric conversion
297 * use of get() updates the global pointer ip the position
298 * in the current assembler-source text line
304 register int c, n, v;
306 if ((c=get()) == '\0')
344 while (++n<=3 && c>='0' && c<='7') {
345 v = (v<<3) + c - '0';
356 /*)Function int getline()
358 * The function getline() reads a line of assembler-source text
359 * from an assembly source text file or an include file.
360 * Lines of text are processed from assembler-source files until
361 * all files have been read. If an include file is opened then
362 * lines of text are read from the include file (or nested
363 * include file) until the end of the include file is found.
364 * The input text line is copied into the global string ib[]
365 * and converted to a NULL terminated string. The function
366 * getline() returns a (1) after succesfully reading a line
367 * or a (0) if all files have been read.
370 * int i string length
373 * char ib[] string buffer containing
374 * assembler-source text line
375 * char ifp[] array of file handles for
377 * int incfil index for ifp[] specifies
378 * active include file
379 * int incline[] array of include file
381 * char sfp[] array of file handles for
382 * assembler source files
383 * int cfile index for sfp[] specifies
385 * int srcline[] array of source file
387 * int inpfil maximum input file index
390 * int fclose() c-library
391 * char * fgets() c-library
392 * int strlen() c-library
395 * include file will be closed at detection of end of file.
396 * the next sequential source file may be selected.
397 * the global file indexes incfil or cfile may be changed.
398 * The respective source line or include line counter
407 loop: if (incfil >= 0) {
408 if (fgets(ib, sizeof ib, ifp[incfil]) == NULL) {
409 fclose(ifp[incfil--]);
416 if (fgets(ib, sizeof ib, sfp[cfile]) == NULL) {
417 if (++cfile <= inpfil) {
432 /*)Function int more()
434 * The function more() scans the assembler-source text line
435 * skipping white space (SPACES and TABS) and returns a (0)
436 * if the end of the line or a comment delimeter (;) is found,
437 * or a (1) if their are additional characters in the line.
440 * int c next character from the
441 * assembler-source text line
447 * char getnb() aslex.c
448 * VOID unget() aslex.c
451 * use of getnb() and unget() updates the global pointer ip
452 * the position in the current assembler-source text line
462 return( (c == '\0' || c == ';') ? 0 : 1 );
465 /*)Function char endline()
467 * The function endline() scans the assembler-source text line
468 * skipping white space (SPACES and TABS) and returns the next
469 * character or a (0) if the end of the line is found or a
470 * comment delimiter (;) is found.
473 * int c next character from the
474 * assembler-source text line
480 * char getnb() aslex.c
483 * use of getnb() updates the global pointer ip the
484 * position in the current assembler-source text line
493 return( (c == '\0' || c == ';') ? 0 : c );