This commit is contained in:
Oliver Lehmann 1989-10-31 17:51:02 +00:00
parent ad48565153
commit 61d1ec1ff6
3 changed files with 265 additions and 0 deletions

View File

@ -0,0 +1,95 @@
/*
** --- RC_GTCHR.C ------ SCANNER I/O ----------------------------------------
**
** GTCHAR
** If 'Lcase' is set, all upper-case alphabetics are
** mapped into lower-case.
** The correct return is > 0; a return = 0 indicates end-of-file.
**
** BACKUP
** Saves the character argument in the global stack 'Pchar'
**
** Version: @(#)rc_gtchr.c 4.0 02/05/89
**
*/
# include <stdio.h>
# include "rc.h"
/* INPUT FILE */
FILE *Input;
/* TWO CHARACTER STACK FOR 'UNGETC' BACKUP */
static char Pchar[2];
static int Pctr;
rc_gtchar()
{
register int chr;
/* USE STACKED CHARACTERS IF POSSIBLE */
if (Pctr)
chr = Pchar[--Pctr];
else
{
if ((chr = getc(Input)) <= 0)
chr = 0;
else
{
if (chr == '\n')
ungetc(chr = '\r', Input);
else
{
if (chr != '\r')
{
if (!Iflag && Sflag)
putchar(chr);
}
else
{
chr = '\n';
if (Sflag)
{
if (!Iflag)
putchar('\n');
fflush(stdout);
printf("%4d: ",Line+1);
}
}
}
}
}
/* UPDATE LINE COUNTER */
if (chr == '\n')
Line++;
if (Lcase && ((chr >= 'A'
# ifdef EBCDIC
&& chr <= 'I') || (chr >= 'J'
&& chr <= 'R') || (chr >= 'S'
# endif
&& chr <= 'Z')))
chr += 'a' - 'A';
# ifdef RC_TRACE
if (TR_INPUT)
printf("GTCHAR: ret %c (0%o)\n", chr, chr);
# endif
return (chr);
}
rc_backup(chr)
register int chr;
{
if (Pctr == 2)
{
/* "BACKUP: overflow" */
rc_error(18);
return;
}
Pchar[Pctr++] = chr;
if (chr == '\n')
Line--;
}

View File

@ -0,0 +1,78 @@
/*
** --- RC_LEX.C -------- SCANNER --------------------------------------------
**
** Each call to rc_lex() returns a token for the next
** syntactic unit. If the object is of type LCONST
** RCONST or SCONST that object will also be entered
** in the symbol table, indexed by `yylval'. If the
** object is not one of these types, `yylval' is the
** opcode field of the operator or keyword tables.
** The end_of_file `EOF' token is zero.
**
** Version: @(#)rc_lex.c 4.0 02/05/89
**
*/
# include "rc.h"
rc_lex()
{
register int chr;
register int rtval;
rtval = -1;
do /* GET NEXT TOKEN */
{
if (!(chr = rc_gtchar()))
{
# ifdef RC_TRACE
if (TR_LEX)
printf("YYLEX: EOF\n");
# endif
rtval = 0;
break;
}
switch (CMAP(chr))
{
case ALPHA:
rtval = rc_name(chr);
# ifdef RC_TRACE
if (TR_LEX)
printf("YYLEX: name ret %d\n", rtval);
# endif
break;
case NUMBR:
rtval = rc_number(chr);
# ifdef RC_TRACE
if (TR_LEX)
printf("YYLEX: number ret %d\n", rtval);
# endif
break;
case OPATR:
if (!(rtval = rc_operator(chr)))
rtval = -1;
# ifdef RC_TRACE
if (TR_LEX)
printf("YYLEX: operator ret %d\n", rtval);
# endif
break;
case CNTRL:
printf("<\\0%o>", chr);
continue;
case PUNCT:
continue;
}
} while (rtval == -1);
# ifdef RC_TRACE
if (TR_LEX)
printf("YYLEX: ret %d\n", rtval);
# endif
return (rtval);
}

View File

@ -0,0 +1,92 @@
/*
** --- RC_STR.C -------- STRING CONSTANT SCANNER ----------------------------
**
** A string is defined as any sequence of MAX_FIELD or fewer characters,
** surrounded by string delimiters. New-line ;characters are purged
** from strings unless preceeded by a '\'; QUOTE's must be similarly
** prefixed in order to be correctly inserted within a string. Each
** string is entered in the symbol table, indexed by 'yylval'. A
** token or the error condition -1 is returned.
**
** Version: @(#)rc_str.c 4.0 02/05/89
**
*/
# include "rc.h"
rc_string(op)
struct optab *op;
{
register int esc;
register int toktyp;
register char *ptr;
register int save;
char buf[MAX_FIELD + 1];
extern char *rc_syment();
extern char *yylval;
/* disable case conversion and fill in string */
ptr = buf;
save = Lcase;
Lcase = 0;
do
{
/* get next character */
if (!(*ptr = rc_gtchar()))
{
/* non term string */
rc_error(11);
break;
}
/* handle escape characters */
esc = (*ptr == '\\');
if (*ptr == '\n')
{
if (!(*ptr = rc_gtchar()))
{
*ptr = 0;
/* non term string */
rc_error(11);
break;
}
}
if (esc == 1)
{
if (!(*++ptr = rc_gtchar()))
{
*ptr = 0;
/* non term string */
rc_error(11);
break;
}
if (*ptr == *(op->term))
*--ptr = *(op->term);
}
/* check length */
if ((ptr - buf) > MAX_FIELD - 1)
{
/* string too long */
rc_error(12);
break;
}
toktyp = *ptr;
if (CMAP(toktyp) == CNTRL)
{
printf("<\\0%o>", *ptr);
*ptr = ' ';
}
} while (*ptr++ != *(op->term) || esc == 1);
/* restore case conversion and return */
*--ptr = '\0';
Lcase = save;
yylval = rc_syment(buf, (ptr - buf) + 1);
# ifdef RC_TRACE
if (TR_LEX)
printf("STRING: %s\n", yylval);
# endif
return (Tokens.sconst);
}