1987-04-29 10:22:07 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*
|
|
|
|
* Author: Ceriel J.H. Jacobs
|
|
|
|
*/
|
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
/* L E X I C A L A N A L Y S E R F O R M O D U L A - 2 */
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1987-04-29 10:22:07 +00:00
|
|
|
/* $Header$ */
|
|
|
|
|
1986-05-01 19:06:53 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "idfsize.h"
|
|
|
|
#include "numsize.h"
|
|
|
|
#include "strsize.h"
|
1986-03-26 15:11:02 +00:00
|
|
|
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <em_arith.h>
|
1986-04-15 17:51:53 +00:00
|
|
|
#include <em_label.h>
|
1986-04-02 17:34:21 +00:00
|
|
|
#include <assert.h>
|
1986-04-17 09:28:09 +00:00
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
#include "LLlex.h"
|
1986-03-26 15:11:02 +00:00
|
|
|
#include "input.h"
|
|
|
|
#include "f_info.h"
|
|
|
|
#include "Lpars.h"
|
|
|
|
#include "class.h"
|
|
|
|
#include "idf.h"
|
1987-06-18 15:46:08 +00:00
|
|
|
#include "def.h"
|
1986-04-15 17:51:53 +00:00
|
|
|
#include "type.h"
|
|
|
|
#include "const.h"
|
1986-11-05 14:33:00 +00:00
|
|
|
#include "warning.h"
|
1986-03-26 15:11:02 +00:00
|
|
|
|
1986-03-20 14:52:03 +00:00
|
|
|
long str2long();
|
|
|
|
|
1987-09-23 16:39:43 +00:00
|
|
|
t_token dot,
|
1986-09-25 19:39:06 +00:00
|
|
|
aside;
|
1987-09-23 16:39:43 +00:00
|
|
|
t_type *toktype;
|
1987-04-29 10:22:07 +00:00
|
|
|
int idfsize = IDFSIZE;
|
|
|
|
int ForeignFlag;
|
1986-06-06 09:35:11 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
extern int cntlines;
|
|
|
|
#endif
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-11-05 14:33:00 +00:00
|
|
|
static int eofseen;
|
1987-08-11 10:50:30 +00:00
|
|
|
extern char options[];
|
1986-11-05 14:33:00 +00:00
|
|
|
|
1986-06-17 12:04:05 +00:00
|
|
|
STATIC
|
1986-03-24 17:29:57 +00:00
|
|
|
SkipComment()
|
1986-03-20 14:52:03 +00:00
|
|
|
{
|
1986-04-03 17:41:26 +00:00
|
|
|
/* Skip Modula-2 comments (* ... *).
|
|
|
|
Note that comments may be nested (par. 3.5).
|
|
|
|
*/
|
1986-03-24 17:29:57 +00:00
|
|
|
register int ch;
|
1986-10-06 20:36:30 +00:00
|
|
|
register int CommentLevel = 0;
|
1986-03-24 17:29:57 +00:00
|
|
|
|
1986-10-06 20:36:30 +00:00
|
|
|
LoadChar(ch);
|
1987-04-29 10:22:07 +00:00
|
|
|
if (ch == '$') {
|
|
|
|
LoadChar(ch);
|
|
|
|
switch(ch) {
|
|
|
|
case 'F':
|
|
|
|
/* Foreign; This definition module has an
|
|
|
|
implementation in another language.
|
|
|
|
In this case, don't generate prefixes in front
|
1987-05-27 10:16:03 +00:00
|
|
|
of the names. Also, don't generate call to
|
|
|
|
initialization routine.
|
1987-04-29 10:22:07 +00:00
|
|
|
*/
|
1987-06-18 15:46:08 +00:00
|
|
|
ForeignFlag = D_FOREIGN;
|
1987-04-29 10:22:07 +00:00
|
|
|
break;
|
1987-08-11 10:50:30 +00:00
|
|
|
case 'R':
|
|
|
|
/* Range checks, on or off */
|
|
|
|
LoadChar(ch);
|
|
|
|
if (ch == '-') {
|
|
|
|
options['R'] = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ch == '+') {
|
|
|
|
options['R'] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
PushBack();
|
|
|
|
break;
|
1987-04-29 10:22:07 +00:00
|
|
|
}
|
|
|
|
}
|
1986-03-24 17:29:57 +00:00
|
|
|
for (;;) {
|
|
|
|
if (class(ch) == STNL) {
|
|
|
|
LineNumber++;
|
1986-06-06 09:35:11 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
cntlines++;
|
|
|
|
#endif
|
1986-03-24 17:29:57 +00:00
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
else if (ch == '(') {
|
1986-03-24 17:29:57 +00:00
|
|
|
LoadChar(ch);
|
1986-10-06 20:36:30 +00:00
|
|
|
if (ch == '*') CommentLevel++;
|
|
|
|
else continue;
|
1986-03-24 17:29:57 +00:00
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
else if (ch == '*') {
|
1986-03-24 17:29:57 +00:00
|
|
|
LoadChar(ch);
|
1986-10-06 20:36:30 +00:00
|
|
|
if (ch == ')') {
|
|
|
|
CommentLevel--;
|
|
|
|
if (CommentLevel < 0) break;
|
|
|
|
}
|
|
|
|
else continue;
|
1986-03-24 17:29:57 +00:00
|
|
|
}
|
1986-10-06 20:36:30 +00:00
|
|
|
else if (ch == EOI) {
|
|
|
|
lexerror("unterminated comment");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
LoadChar(ch);
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
1986-03-24 17:29:57 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-09-25 19:39:06 +00:00
|
|
|
STATIC struct string *
|
1986-03-24 17:29:57 +00:00
|
|
|
GetString(upto)
|
|
|
|
{
|
1986-04-03 17:41:26 +00:00
|
|
|
/* Read a Modula-2 string, delimited by the character "upto".
|
|
|
|
*/
|
1986-03-24 17:29:57 +00:00
|
|
|
register int ch;
|
1986-11-17 11:41:28 +00:00
|
|
|
register struct string *str = (struct string *)
|
|
|
|
Malloc((unsigned) sizeof(struct string));
|
1986-04-04 13:47:04 +00:00
|
|
|
register char *p;
|
1986-11-17 11:41:28 +00:00
|
|
|
register int len;
|
1986-03-24 17:29:57 +00:00
|
|
|
|
1986-11-17 11:41:28 +00:00
|
|
|
len = ISTRSIZE;
|
1986-10-06 20:36:30 +00:00
|
|
|
str->s_str = p = Malloc((unsigned int) ISTRSIZE);
|
1986-09-25 19:39:06 +00:00
|
|
|
while (LoadChar(ch), ch != upto) {
|
1986-03-24 17:29:57 +00:00
|
|
|
if (class(ch) == STNL) {
|
|
|
|
lexerror("newline in string");
|
|
|
|
LineNumber++;
|
1986-06-06 09:35:11 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
cntlines++;
|
|
|
|
#endif
|
1986-03-24 17:29:57 +00:00
|
|
|
break;
|
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
if (ch == EOI) {
|
1986-03-24 17:29:57 +00:00
|
|
|
lexerror("end-of-file in string");
|
|
|
|
break;
|
|
|
|
}
|
1986-04-04 13:47:04 +00:00
|
|
|
*p++ = ch;
|
1986-11-17 11:41:28 +00:00
|
|
|
if (p - str->s_str == len) {
|
1987-08-10 13:01:54 +00:00
|
|
|
str->s_str = Realloc(str->s_str,
|
1986-11-17 11:41:28 +00:00
|
|
|
(unsigned int) len + RSTRSIZE);
|
|
|
|
p = str->s_str + len;
|
|
|
|
len += RSTRSIZE;
|
1986-03-24 17:29:57 +00:00
|
|
|
}
|
|
|
|
}
|
1986-04-04 13:47:04 +00:00
|
|
|
str->s_length = p - str->s_str;
|
1986-11-17 11:41:28 +00:00
|
|
|
while (p - str->s_str < len) *p++ = '\0';
|
1986-11-26 16:40:45 +00:00
|
|
|
if (str->s_length == 0) str->s_length = 1;
|
|
|
|
/* ??? string length at least 1 ??? */
|
1986-09-25 19:39:06 +00:00
|
|
|
return str;
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
|
|
|
|
1986-11-05 14:33:00 +00:00
|
|
|
static char *s_error = "illegal line directive";
|
|
|
|
|
|
|
|
STATIC int
|
|
|
|
getch()
|
|
|
|
{
|
|
|
|
register int ch;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
LoadChar(ch);
|
|
|
|
if ((ch & 0200) && ch != EOI) {
|
|
|
|
error("non-ascii '\\%03o' read", ch & 0377);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ch == EOI) {
|
|
|
|
eofseen = 1;
|
|
|
|
return '\n';
|
|
|
|
}
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
1987-04-29 10:22:07 +00:00
|
|
|
CheckForLineDirective()
|
|
|
|
{
|
|
|
|
register int ch = getch();
|
1986-11-05 14:33:00 +00:00
|
|
|
register int i = 0;
|
|
|
|
char buf[IDFSIZE + 2];
|
|
|
|
register char *c = buf;
|
|
|
|
|
1987-04-29 10:22:07 +00:00
|
|
|
|
|
|
|
if (ch != '#') {
|
|
|
|
PushBack();
|
|
|
|
return;
|
|
|
|
}
|
1986-11-05 14:33:00 +00:00
|
|
|
do { /*
|
|
|
|
* Skip to next digit
|
|
|
|
* Do not skip newlines
|
|
|
|
*/
|
|
|
|
ch = getch();
|
|
|
|
if (class(ch) == STNL) {
|
|
|
|
LineNumber++;
|
|
|
|
error(s_error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} while (class(ch) != STNUM);
|
1987-04-29 10:22:07 +00:00
|
|
|
while (class(ch) == STNUM) {
|
1986-11-05 14:33:00 +00:00
|
|
|
i = i*10 + (ch - '0');
|
|
|
|
ch = getch();
|
1987-04-29 10:22:07 +00:00
|
|
|
}
|
1986-11-05 14:33:00 +00:00
|
|
|
while (ch != '"' && class(ch) != STNL) ch = getch();
|
|
|
|
if (ch == '"') {
|
|
|
|
c = buf;
|
|
|
|
do {
|
|
|
|
*c++ = ch = getch();
|
|
|
|
if (class(ch) == STNL) {
|
|
|
|
LineNumber++;
|
|
|
|
error(s_error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} while (ch != '"');
|
|
|
|
*--c = '\0';
|
|
|
|
do {
|
|
|
|
ch = getch();
|
|
|
|
} while (class(ch) != STNL);
|
|
|
|
/*
|
|
|
|
* Remember the file name
|
|
|
|
*/
|
|
|
|
if (!eofseen && strcmp(FileName,buf)) {
|
1986-11-17 11:41:28 +00:00
|
|
|
FileName = Salloc(buf,(unsigned) strlen(buf) + 1);
|
1986-11-05 14:33:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (eofseen) {
|
|
|
|
error(s_error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LineNumber = i;
|
|
|
|
}
|
|
|
|
|
1986-03-20 14:52:03 +00:00
|
|
|
int
|
1986-03-24 17:29:57 +00:00
|
|
|
LLlex()
|
1986-03-20 14:52:03 +00:00
|
|
|
{
|
1986-04-17 09:28:09 +00:00
|
|
|
/* LLlex() is the Lexical Analyzer.
|
1986-04-03 17:41:26 +00:00
|
|
|
The putting aside of tokens is taken into account.
|
|
|
|
*/
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_token *tk = ˙
|
1986-06-04 09:01:48 +00:00
|
|
|
char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 2];
|
1986-03-20 14:52:03 +00:00
|
|
|
register int ch, nch;
|
|
|
|
|
1986-06-04 09:01:48 +00:00
|
|
|
toktype = error_type;
|
1986-06-17 12:04:05 +00:00
|
|
|
|
1986-03-24 17:29:57 +00:00
|
|
|
if (ASIDE) { /* a token is put aside */
|
|
|
|
*tk = aside;
|
|
|
|
ASIDE = 0;
|
|
|
|
return tk->tk_symb;
|
|
|
|
}
|
1986-06-17 12:04:05 +00:00
|
|
|
|
1987-04-29 10:22:07 +00:00
|
|
|
again1:
|
1986-10-22 15:38:24 +00:00
|
|
|
if (eofseen) {
|
|
|
|
eofseen = 0;
|
|
|
|
ch = EOI;
|
|
|
|
}
|
|
|
|
else {
|
1986-03-20 14:52:03 +00:00
|
|
|
again:
|
1986-10-22 15:38:24 +00:00
|
|
|
LoadChar(ch);
|
|
|
|
if ((ch & 0200) && ch != EOI) {
|
1986-11-05 14:33:00 +00:00
|
|
|
error("non-ascii '\\%03o' read", ch & 0377);
|
|
|
|
goto again;
|
1986-10-22 15:38:24 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
1986-04-04 13:47:04 +00:00
|
|
|
|
1987-06-18 15:46:08 +00:00
|
|
|
tk->tk_lineno = LineNumber;
|
|
|
|
|
1986-03-20 14:52:03 +00:00
|
|
|
switch (class(ch)) {
|
|
|
|
|
|
|
|
case STNL:
|
|
|
|
LineNumber++;
|
1986-06-06 09:35:11 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
cntlines++;
|
|
|
|
#endif
|
1987-04-29 10:22:07 +00:00
|
|
|
CheckForLineDirective();
|
|
|
|
goto again1;
|
1986-09-25 19:39:06 +00:00
|
|
|
|
|
|
|
case STSKIP:
|
1986-03-20 14:52:03 +00:00
|
|
|
goto again;
|
|
|
|
|
|
|
|
case STGARB:
|
1986-11-26 16:40:45 +00:00
|
|
|
if ((unsigned) ch - 040 < 0137) {
|
1986-03-20 14:52:03 +00:00
|
|
|
lexerror("garbage char %c", ch);
|
|
|
|
}
|
1986-11-26 16:40:45 +00:00
|
|
|
else lexerror("garbage char \\%03o", ch);
|
1986-03-20 14:52:03 +00:00
|
|
|
goto again;
|
|
|
|
|
|
|
|
case STSIMP:
|
|
|
|
if (ch == '(') {
|
|
|
|
LoadChar(nch);
|
|
|
|
if (nch == '*') {
|
|
|
|
SkipComment();
|
|
|
|
goto again;
|
|
|
|
}
|
1986-10-22 15:38:24 +00:00
|
|
|
else if (nch == EOI) eofseen = 1;
|
1986-12-09 17:41:06 +00:00
|
|
|
else PushBack();
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
1987-07-30 13:37:39 +00:00
|
|
|
if (ch == '&') return tk->tk_symb = AND;
|
|
|
|
if (ch == '~') return tk->tk_symb = NOT;
|
1986-03-20 14:52:03 +00:00
|
|
|
return tk->tk_symb = ch;
|
|
|
|
|
|
|
|
case STCOMP:
|
|
|
|
LoadChar(nch);
|
|
|
|
switch (ch) {
|
|
|
|
|
|
|
|
case '.':
|
|
|
|
if (nch == '.') {
|
|
|
|
return tk->tk_symb = UPTO;
|
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
break;
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
case ':':
|
|
|
|
if (nch == '=') {
|
|
|
|
return tk->tk_symb = BECOMES;
|
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
break;
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
case '<':
|
|
|
|
if (nch == '=') {
|
|
|
|
return tk->tk_symb = LESSEQUAL;
|
|
|
|
}
|
1986-05-30 18:48:00 +00:00
|
|
|
if (nch == '>') {
|
|
|
|
return tk->tk_symb = '#';
|
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
break;
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
case '>':
|
|
|
|
if (nch == '=') {
|
|
|
|
return tk->tk_symb = GREATEREQUAL;
|
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
break;
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
default :
|
1986-06-06 02:22:09 +00:00
|
|
|
crash("(LLlex, STCOMP)");
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
1986-10-22 15:38:24 +00:00
|
|
|
if (nch == EOI) eofseen = 1;
|
1986-12-09 17:41:06 +00:00
|
|
|
else PushBack();
|
1986-09-25 19:39:06 +00:00
|
|
|
return tk->tk_symb = ch;
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
case STIDF:
|
|
|
|
{
|
1986-09-25 19:39:06 +00:00
|
|
|
register char *tag = &buf[0];
|
1987-09-23 16:39:43 +00:00
|
|
|
register t_idf *id;
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
do {
|
1986-09-25 19:39:06 +00:00
|
|
|
if (tag - buf < idfsize) *tag++ = ch;
|
1986-03-20 14:52:03 +00:00
|
|
|
LoadChar(ch);
|
|
|
|
} while(in_idf(ch));
|
|
|
|
|
1986-10-22 15:38:24 +00:00
|
|
|
if (ch == EOI) eofseen = 1;
|
1986-12-09 17:41:06 +00:00
|
|
|
else PushBack();
|
1986-09-25 19:39:06 +00:00
|
|
|
*tag++ = '\0';
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-03-26 22:46:48 +00:00
|
|
|
tk->TOK_IDF = id = str2idf(buf, 1);
|
1986-03-20 14:52:03 +00:00
|
|
|
return tk->tk_symb = id->id_reserved ? id->id_reserved : IDENT;
|
|
|
|
}
|
|
|
|
|
1986-09-25 19:39:06 +00:00
|
|
|
case STSTR: {
|
|
|
|
register struct string *str = GetString(ch);
|
|
|
|
|
|
|
|
if (str->s_length == 1) {
|
|
|
|
tk->TOK_INT = *(str->s_str) & 0377;
|
1986-06-04 09:01:48 +00:00
|
|
|
toktype = char_type;
|
1986-09-25 19:39:06 +00:00
|
|
|
free(str->s_str);
|
|
|
|
free((char *) str);
|
1986-06-04 09:01:48 +00:00
|
|
|
}
|
|
|
|
else {
|
1986-09-25 19:39:06 +00:00
|
|
|
tk->tk_data.tk_str = str;
|
|
|
|
toktype = standard_type(T_STRING, 1, str->s_length);
|
1986-06-04 09:01:48 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
return tk->tk_symb = STRING;
|
1986-09-25 19:39:06 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
case STNUM:
|
|
|
|
{
|
|
|
|
/* The problem arising with the "parsing" of a number
|
|
|
|
is that we don't know the base in advance so we
|
|
|
|
have to read the number with the help of a rather
|
|
|
|
complex finite automaton.
|
|
|
|
*/
|
1987-05-27 10:16:03 +00:00
|
|
|
enum statetp {Oct,OptHex,Hex,Dec,OctEndOrHex,End,OptReal,Real};
|
1986-09-25 19:39:06 +00:00
|
|
|
register enum statetp state;
|
|
|
|
register int base;
|
1986-03-20 14:52:03 +00:00
|
|
|
register char *np = &buf[1];
|
|
|
|
/* allow a '-' to be added */
|
|
|
|
|
1986-04-08 18:15:46 +00:00
|
|
|
buf[0] = '-';
|
1986-03-20 14:52:03 +00:00
|
|
|
*np++ = ch;
|
1986-09-25 19:39:06 +00:00
|
|
|
state = is_oct(ch) ? Oct : Dec;
|
1986-03-20 14:52:03 +00:00
|
|
|
LoadChar(ch);
|
1986-09-25 19:39:06 +00:00
|
|
|
for (;;) {
|
|
|
|
switch(state) {
|
|
|
|
case Oct:
|
|
|
|
while (is_oct(ch)) {
|
|
|
|
if (np < &buf[NUMSIZE]) *np++ = ch;
|
|
|
|
LoadChar(ch);
|
|
|
|
}
|
|
|
|
if (ch == 'B' || ch == 'C') {
|
|
|
|
base = 8;
|
|
|
|
state = OctEndOrHex;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Fall Through */
|
|
|
|
case Dec:
|
|
|
|
base = 10;
|
|
|
|
while (is_dig(ch)) {
|
|
|
|
if (np < &buf[NUMSIZE]) {
|
|
|
|
*np++ = ch;
|
|
|
|
}
|
|
|
|
LoadChar(ch);
|
|
|
|
}
|
1987-05-27 10:16:03 +00:00
|
|
|
if (ch == 'D') state = OptHex;
|
|
|
|
else if (is_hex(ch)) state = Hex;
|
1986-09-25 19:39:06 +00:00
|
|
|
else if (ch == '.') state = OptReal;
|
|
|
|
else {
|
|
|
|
state = End;
|
|
|
|
if (ch == 'H') base = 16;
|
1986-10-22 15:38:24 +00:00
|
|
|
else if (ch == EOI) eofseen = 1;
|
1986-12-09 17:41:06 +00:00
|
|
|
else PushBack();
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
break;
|
|
|
|
|
1987-05-27 10:16:03 +00:00
|
|
|
case OptHex:
|
|
|
|
LoadChar(ch);
|
|
|
|
if (is_hex(ch)) {
|
|
|
|
if (np < &buf[NUMSIZE]) *np++ = 'D';
|
|
|
|
state = Hex;
|
|
|
|
}
|
|
|
|
else state = End;
|
|
|
|
break;
|
|
|
|
|
1986-09-25 19:39:06 +00:00
|
|
|
case Hex:
|
|
|
|
while (is_hex(ch)) {
|
|
|
|
if (np < &buf[NUMSIZE]) *np++ = ch;
|
|
|
|
LoadChar(ch);
|
|
|
|
}
|
|
|
|
base = 16;
|
|
|
|
state = End;
|
|
|
|
if (ch != 'H') {
|
|
|
|
lexerror("H expected after hex number");
|
1986-10-22 15:38:24 +00:00
|
|
|
if (ch == EOI) eofseen = 1;
|
1986-12-09 17:41:06 +00:00
|
|
|
else PushBack();
|
1986-09-25 19:39:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OctEndOrHex:
|
|
|
|
if (np < &buf[NUMSIZE]) *np++ = ch;
|
1986-03-20 14:52:03 +00:00
|
|
|
LoadChar(ch);
|
1986-09-25 19:39:06 +00:00
|
|
|
if (ch == 'H') {
|
|
|
|
base = 16;
|
|
|
|
state = End;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (is_hex(ch)) {
|
|
|
|
state = Hex;
|
|
|
|
break;
|
|
|
|
}
|
1986-10-22 15:38:24 +00:00
|
|
|
if (ch == EOI) eofseen = 1;
|
1986-12-09 17:41:06 +00:00
|
|
|
else PushBack();
|
1986-09-25 19:39:06 +00:00
|
|
|
ch = *--np;
|
|
|
|
*np++ = '\0';
|
|
|
|
base = 8;
|
|
|
|
/* Fall through */
|
|
|
|
|
|
|
|
case End:
|
1986-12-01 10:06:53 +00:00
|
|
|
*np = '\0';
|
|
|
|
if (np >= &buf[NUMSIZE]) {
|
|
|
|
tk->TOK_INT = 1;
|
|
|
|
lexerror("constant too long");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
np = &buf[1];
|
|
|
|
while (*np == '0') np++;
|
|
|
|
tk->TOK_INT = str2long(np, base);
|
|
|
|
if (strlen(np) > 14 /* ??? */ ||
|
|
|
|
tk->TOK_INT < 0) {
|
|
|
|
lexwarning(W_ORDINARY, "overflow in constant");
|
|
|
|
}
|
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
if (ch == 'C' && base == 8) {
|
|
|
|
toktype = char_type;
|
|
|
|
if (tk->TOK_INT<0 || tk->TOK_INT>255) {
|
1986-11-05 14:33:00 +00:00
|
|
|
lexwarning(W_ORDINARY, "character constant out of range");
|
1986-09-25 19:39:06 +00:00
|
|
|
}
|
1986-04-25 10:14:08 +00:00
|
|
|
}
|
1987-05-27 10:16:03 +00:00
|
|
|
else if (ch == 'D' && base == 10) {
|
|
|
|
toktype = longint_type;
|
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
else if (tk->TOK_INT>=0 &&
|
|
|
|
tk->TOK_INT<=max_int) {
|
|
|
|
toktype = intorcard_type;
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
else toktype = card_type;
|
|
|
|
return tk->tk_symb = INTEGER;
|
|
|
|
|
|
|
|
case OptReal:
|
|
|
|
/* The '.' could be the first of the '..'
|
|
|
|
token. At this point, we need a
|
|
|
|
look-ahead of two characters.
|
|
|
|
*/
|
1986-03-20 14:52:03 +00:00
|
|
|
LoadChar(ch);
|
1986-09-25 19:39:06 +00:00
|
|
|
if (ch == '.') {
|
|
|
|
/* Indeed the '..' token
|
|
|
|
*/
|
1986-12-09 17:41:06 +00:00
|
|
|
PushBack();
|
|
|
|
PushBack();
|
1986-09-25 19:39:06 +00:00
|
|
|
state = End;
|
|
|
|
base = 10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
state = Real;
|
|
|
|
break;
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
if (state == Real) break;
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-09-25 19:39:06 +00:00
|
|
|
/* a real real constant */
|
|
|
|
if (np < &buf[NUMSIZE]) *np++ = '.';
|
|
|
|
|
1987-05-27 10:16:03 +00:00
|
|
|
toktype = real_type;
|
|
|
|
|
1986-09-25 19:39:06 +00:00
|
|
|
while (is_dig(ch)) {
|
|
|
|
/* Fractional part
|
1986-03-20 14:52:03 +00:00
|
|
|
*/
|
1986-09-25 19:39:06 +00:00
|
|
|
if (np < &buf[NUMSIZE]) *np++ = ch;
|
1986-03-20 14:52:03 +00:00
|
|
|
LoadChar(ch);
|
1986-09-25 19:39:06 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1987-05-27 10:16:03 +00:00
|
|
|
if (ch == 'E' || ch == 'D') {
|
1986-09-25 19:39:06 +00:00
|
|
|
/* Scale factor
|
|
|
|
*/
|
1987-05-27 10:16:03 +00:00
|
|
|
if (ch == 'D') {
|
|
|
|
toktype = longreal_type;
|
|
|
|
LoadChar(ch);
|
|
|
|
if (!(ch == '+' || ch == '-' || is_dig(ch)))
|
|
|
|
goto noscale;
|
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
if (np < &buf[NUMSIZE]) *np++ = 'E';
|
|
|
|
LoadChar(ch);
|
|
|
|
if (ch == '+' || ch == '-') {
|
|
|
|
/* Signed scalefactor
|
|
|
|
*/
|
|
|
|
if (np < &buf[NUMSIZE]) *np++ = ch;
|
|
|
|
LoadChar(ch);
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
|
|
|
if (is_dig(ch)) {
|
|
|
|
do {
|
1986-09-25 19:39:06 +00:00
|
|
|
if (np < &buf[NUMSIZE]) *np++ = ch;
|
1986-03-20 14:52:03 +00:00
|
|
|
LoadChar(ch);
|
|
|
|
} while (is_dig(ch));
|
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
else {
|
|
|
|
lexerror("bad scale factor");
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
1986-09-25 19:39:06 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1987-05-27 10:16:03 +00:00
|
|
|
noscale:
|
1986-10-21 14:45:43 +00:00
|
|
|
*np++ = '\0';
|
1986-10-22 15:38:24 +00:00
|
|
|
if (ch == EOI) eofseen = 1;
|
1986-12-09 17:41:06 +00:00
|
|
|
else PushBack();
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-09-25 19:39:06 +00:00
|
|
|
if (np >= &buf[NUMSIZE]) {
|
|
|
|
tk->TOK_REL = Salloc("0.0", 5);
|
1987-11-03 12:44:09 +00:00
|
|
|
lexerror("real constant too long");
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
1987-05-18 15:57:33 +00:00
|
|
|
else tk->TOK_REL = Salloc(buf, (unsigned) (np - buf)) + 1;
|
1986-09-25 19:39:06 +00:00
|
|
|
return tk->tk_symb = REAL;
|
|
|
|
|
1986-03-20 14:52:03 +00:00
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
|
|
|
case STEOI:
|
1986-03-24 17:29:57 +00:00
|
|
|
return tk->tk_symb = -1;
|
1986-03-20 14:52:03 +00:00
|
|
|
|
|
|
|
case STCHAR:
|
|
|
|
default:
|
1986-06-06 02:22:09 +00:00
|
|
|
crash("(LLlex) Impossible character class");
|
1986-10-06 20:36:30 +00:00
|
|
|
/*NOTREACHED*/
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|
1986-03-24 17:29:57 +00:00
|
|
|
/*NOTREACHED*/
|
1986-03-20 14:52:03 +00:00
|
|
|
}
|