4 * (C) Copyright 1989-1995
13 * Extensions: P. Felber, M. Hope
20 #if !defined(_MSC_VER)
28 * The module aslex.c includes the general lexical
29 * analysis routines for the assembler.
31 * aslex.c contains the following functions:
42 * aslex.c contains no local/static variables
45 /*)Function VOID getid(id,c)
47 * char * id a pointer to a string of
50 * >=0 this is first character to
51 * copy to the string buffer
52 * <0 skip white space, first
53 * character must be a LETTER
55 * The function getid() scans the current assembler-source text line
56 * from the current position copying the next LETTER | DIGIT string
57 * into the external string buffer (id). The string ends when a non
58 * LETTER or DIGIT character is found. The maximum number of
59 * characters copied is NCPS. If the input string is larger than
60 * NCPS characters then the string is truncated, if the input string
61 * is shorter than NCPS characters then the string is NULL filled.
62 * If the mode argument (c) is >=0 then (c) is the first character
63 * copied to the string buffer, if (c) is <0 then intervening white
64 * space (SPACES and TABS) are skipped and the first character found
65 * must be a LETTER else a 'q' error terminates the parse of this
66 * assembler-source text line.
69 * char * p pointer to external string buffer
70 * int c current character value
73 * char ctype[] a character array which defines the
74 * type of character being processed.
75 * This index is the character
80 * char getnb() aslex.c
81 * VOID unget() aslex.c
84 * use of getnb(), get(), and unget() updates the
85 * global pointer ip, the position in the current
86 * assembler-source text line.
98 if ((ctype[c] & LETTER) == 0)
105 } while (ctype[c=get()] & (LETTER|DIGIT));
107 while (p < &id[NCPS])
111 /*)Function VOID getst(id,c)
113 * char * id a pointer to a string of
114 * maximum length NCPS
116 * >=0 this is first character to
117 * copy to the string buffer
118 * <0 skip white space, first
119 * character must be a LETTER
121 * The function getnbid() scans the current assembler-source text line
122 * from the current position copying the next character string into
123 * the external string buffer (id). The string ends when a SPACE or
124 * ILL character is found. The maximum number of
125 * characters copied is NCPS. If the input string is larger than
126 * NCPS characters then the string is truncated, if the input string
127 * is shorter than NCPS characters then the string is NULL filled.
128 * If the mode argument (c) is >=0 then (c) is the first character
129 * copied to the string buffer, if (c) is <0 then intervening white
130 * space (SPACES and TABS) are skipped and the first character found
131 * must be a LETTER else a 'q' error terminates the parse of this
132 * assembler-source text line.
135 * char * p pointer to external string buffer
136 * int c current character value
139 * char ctype[] a character array which defines the
140 * type of character being processed.
141 * This index is the character
146 * char getnb() aslex.c
147 * VOID unget() aslex.c
150 * use of getnb(), get(), and unget() updates the
151 * global pointer ip, the position in the current
152 * assembler-source text line.
164 if ((ctype[c] & LETTER) == 0)
171 } while (ctype[c=get()] & ~(SPACE|ILL));
173 while (p < &id[NCPS])
177 /*)Function char getnb()
179 * The function getnb() scans the current assembler-source
180 * text line returning the first character not a SPACE or TAB.
183 * int c current character from
184 * assembler-source text line
193 * use of get() updates the global pointer ip, the position
194 * in the current assembler-source text line
202 while ((c=get()) == ' ' || c == '\t')
207 /*)Function char get()
209 * The function get() returns the next character in the
210 * assembler-source text line, at the end of the line a
211 * NULL character is returned.
214 * int c current character from
215 * assembler-source text line
218 * char * ip pointer into the current
219 * assembler-source text line
225 * updates ip to the next character position in the
226 * assembler-source text line. If ip is at the end of the
227 * line, ip is not updated.
240 /*)Function VOID unget(c)
242 * int c value of last character read from
243 * assembler-source text line
245 * If (c) is not a NULL character then the global pointer ip
246 * is updated to point to the preceeding character in the
247 * assembler-source text line.
249 * NOTE: This function does not push the character (c)
250 * back into the assembler-source text line, only
251 * the pointer ip is changed.
254 * int c last character read from
255 * assembler-source text line
258 * char * ip position into the current
259 * assembler-source text line
265 * ip decremented by 1 character position
276 /*)Function int getmap(d)
278 * int d value to compare with the
279 * assembler-source text line character
281 * The function getmap() converts the 'C' style characters \b, \f,
282 * \n, \r, and \t to their equivalent ascii values and also
283 * converts 'C' style octal constants '\123' to their equivalent
284 * numeric values. If the first character is equivalent to (d) then
285 * a (-1) is returned, if the end of the line is detected then
286 * a 'q' error terminates the parse for this line, or if the first
287 * character is not a \ then the character value is returned.
290 * int c value of character from the
291 * assembler-source text line
292 * int n looping counter
293 * int v current value of numeric conversion
302 * use of get() updates the global pointer ip the position
303 * in the current assembler-source text line
309 register int c, n, v;
311 if ((c=get()) == '\0')
349 while (++n<=3 && c>='0' && c<='7') {
350 v = (v<<3) + c - '0';
361 /*)Function int getline()
363 * The function getline() reads a line of assembler-source text
364 * from an assembly source text file or an include file.
365 * Lines of text are processed from assembler-source files until
366 * all files have been read. If an include file is opened then
367 * lines of text are read from the include file (or nested
368 * include file) until the end of the include file is found.
369 * The input text line is copied into the global string ib[]
370 * and converted to a NULL terminated string. The function
371 * getline() returns a (1) after succesfully reading a line
372 * or a (0) if all files have been read.
375 * int i string length
378 * char ib[] string buffer containing
379 * assembler-source text line
380 * char ifp[] array of file handles for
382 * int incfil index for ifp[] specifies
383 * active include file
384 * int incline[] array of include file
386 * char sfp[] array of file handles for
387 * assembler source files
388 * int cfile index for sfp[] specifies
390 * int srcline[] array of source file
392 * int inpfil maximum input file index
395 * int fclose() c-library
396 * char * fgets() c-library
397 * int strlen() c-library
400 * include file will be closed at detection of end of file.
401 * the next sequential source file may be selected.
402 * the global file indexes incfil or cfile may be changed.
403 * The respective source line or include line counter
412 loop: if (incfil >= 0) {
413 if (fgets(ib, sizeof ib, ifp[incfil]) == NULL) {
416 ifp[incfil--] = NULL;
418 fclose(ifp[incfil--]);
426 if (fgets(ib, sizeof ib, sfp[cfile]) == NULL) {
427 if (++cfile <= inpfil) {
439 if (i >= 1 && ib[i-1] == '\r')
444 /*)Function int more()
446 * The function more() scans the assembler-source text line
447 * skipping white space (SPACES and TABS) and returns a (0)
448 * if the end of the line or a comment delimeter (;) is found,
449 * or a (1) if their are additional characters in the line.
452 * int c next character from the
453 * assembler-source text line
459 * char getnb() aslex.c
460 * VOID unget() aslex.c
463 * use of getnb() and unget() updates the global pointer ip
464 * the position in the current assembler-source text line
474 return( (c == '\0' || c == ';') ? 0 : 1 );
477 /*)Function char endline()
479 * The function endline() scans the assembler-source text line
480 * skipping white space (SPACES and TABS) and returns the next
481 * character or a (0) if the end of the line is found or a
482 * comment delimiter (;) is found.
485 * int c next character from the
486 * assembler-source text line
492 * char getnb() aslex.c
495 * use of getnb() updates the global pointer ip the
496 * position in the current assembler-source text line
505 return( (c == '\0' || c == ';') ? 0 : c );