mirror of
https://github.com/PDP-10/its.git
synced 2026-03-27 10:30:50 +00:00
C20, port to TOPS-20.
This commit is contained in:
41
c20/c.defs
Normal file
41
c20/c.defs
Normal file
@@ -0,0 +1,41 @@
|
||||
/* C Standard Definitions, for TOPS-20 */
|
||||
|
||||
/* data types */
|
||||
|
||||
struct _cal {int year, month, day, hour, minute, second;};
|
||||
# define cal struct _cal
|
||||
|
||||
struct _tag {int *pc, *fp, *ap, *sp, regs[10];};
|
||||
# define tag struct _tag
|
||||
|
||||
|
||||
/* common values */
|
||||
|
||||
# define TRUE 1
|
||||
# define FALSE 0
|
||||
|
||||
# define OPENLOSS (-1) /* returned by COPEN if lose */
|
||||
# define EOF_VALUE 0 /* returned by CGETC if EOF */
|
||||
|
||||
# define channel *int
|
||||
|
||||
/* C interrupts */
|
||||
|
||||
# define INT_DEFAULT 0
|
||||
# define INT_IGNORE 1
|
||||
|
||||
/* 0-5, 23-35 are user assignable */
|
||||
|
||||
# define aov_interrupt 6 /* arithmetic overflow */
|
||||
# define fov_interrupt 7 /* floating point overflow */
|
||||
# define eof_interrupt 10 /* end of file */
|
||||
# define dae_interrupt 11 /* data error */
|
||||
# define qta_interrupt 12 /* quota exceeded or disk full */
|
||||
# define ili_interrupt 15 /* illegal instruction */
|
||||
# define ird_interrupt 16 /* illegal memory read */
|
||||
# define iwr_interrupt 17 /* illegal memory write */
|
||||
# define ift_interrupt 19 /* inferior process termination */
|
||||
# define mse_interrupt 20 /* system resources exhausted */
|
||||
# define nxp_interrupt 22 /* non-existent page */
|
||||
|
||||
# define halves(l, r) (((l) << 18) | ((r) & 0777777))
|
||||
139
c20/cc.hlp
Normal file
139
c20/cc.hlp
Normal file
@@ -0,0 +1,139 @@
|
||||
C Info (30 July 1979)
|
||||
|
||||
--- C ---
|
||||
|
||||
C is an implementation language, similar to BCPL except with data
|
||||
types. It is the primary language used in the Unix operating system.
|
||||
This implementation runs on the ITS and TOPS-20 operating systems.
|
||||
(The ITS implementation exists only on DM.) This implementation is
|
||||
moderately compatible with the Unix C implementation. The Unix
|
||||
system calls are NOT implemented. Some implemented library routines
|
||||
are described below.
|
||||
|
||||
Further information is available from Eliot Moss (EBM@XX).
|
||||
|
||||
--- Compiling ---
|
||||
|
||||
CC is the C compiler command. Usage is
|
||||
|
||||
:cc file1.c file2.c ...
|
||||
|
||||
where the arguments are the path names of C source files which are to
|
||||
be compiled. Each file will be compiled in turn, and if the compilation
|
||||
is successful, the resulting relocatable file will be placed in the file
|
||||
"file*.stk". [The ITS compiler currently produces "file*.rel". This will
|
||||
soon be changed.] Arguments beginning with the '-' character are taken
|
||||
to be compiler options. Available options include:
|
||||
|
||||
-c compile only, do not assemble
|
||||
-g do not delete MIDAS file
|
||||
-x syntax check only
|
||||
-s produce a symbol table listing
|
||||
-b compile big function (FUNCTION TOO LARGE)
|
||||
|
||||
For example, the command
|
||||
|
||||
:cc foo.c
|
||||
|
||||
would compile the C program in the file "foo.c" ("FOO C" on ITS) in the
|
||||
current directory, and place the resulting relocatable program in the file
|
||||
"foo.stk" ("FOO STK" on ITS).
|
||||
|
||||
--- Loading ---
|
||||
|
||||
Relocatable programs produced by the C compiler are loaded together
|
||||
with the C support routines using the STINKR loader. To load program
|
||||
files "foo", "bar", and "bletch" and produce a runnable file "foo",
|
||||
type the following to STINKR:
|
||||
|
||||
(TOPS-20: (ITS:
|
||||
|
||||
x <c>clib x c/clib
|
||||
l foo l foo
|
||||
l bar l bar
|
||||
l bletch l bletch
|
||||
o foo.exe o ts.foo
|
||||
^Z ^@
|
||||
|
||||
The ^@ (ASCII NUL) or ^Z terminates the terminal input file.
|
||||
The ^Z must be followed by a CR. These commands (minus the ^@)
|
||||
could also be written in a file, say "foo.stinkr" ("FOO STINKR"
|
||||
on ITS), in which case one could invoke STINKR with "foo" as a
|
||||
JCL argument and STINKR would read the commands from the
|
||||
command file.
|
||||
|
||||
--- Library ---
|
||||
|
||||
The above STINKR commands will load in a set of library routines
|
||||
for performing I/O, etc. These routines are similar to the
|
||||
Unix "Portable I/O Library". A brief description of the most useful
|
||||
routines follows:
|
||||
|
||||
char c; /* an ASCII character */
|
||||
int i, n, cc; /* an integer */
|
||||
int *p; /* an integer pointer */
|
||||
int b; /* a boolean */
|
||||
char *s, *s1, *s2; /* strings */
|
||||
char *fn; /* an ITS file name or a path name */
|
||||
int fd; /* a "file descriptor" */
|
||||
|
||||
fd = copen (fn, mode, options); /* open file */
|
||||
char mode; /* 'r', 'w', or 'a' (append) */
|
||||
char *options; /* 0 (char I/O), "s" (string file), "b" (binary) */
|
||||
/* for string file, pass string as fn */
|
||||
/* returns -1 if open fails */
|
||||
|
||||
extern int cin; /* standard input - pre-existing */
|
||||
extern int cout; /* standard output - pre-existing */
|
||||
extern int cerr; /* standard error ouput - pre-existing */
|
||||
|
||||
c = cgetc (fd); /* get character; returns 0 if eof */
|
||||
c = cputc (c, fd); /* put character */
|
||||
b = ceof (fd); /* test for end of file */
|
||||
cclose (fd); /* close file */
|
||||
|
||||
c = getchar (); /* equivalent to cgetc(cin) */
|
||||
putchar (c); /* equivalent to cputc(c,cout) */
|
||||
|
||||
gets (s1); /* read string (line) from cin */
|
||||
puts (s1); /* put string and newline to cout */
|
||||
|
||||
cprint (fd, format, arg...); /* formatted print routine */
|
||||
/* the format is a string which may contain format items
|
||||
of the form %nf, where n is an optional decimal integer
|
||||
(the minimum field width) and f is one of the following
|
||||
characters:
|
||||
|
||||
d - print next arg (an integer) in decimal
|
||||
o - print next arg (an integer) in octal
|
||||
s - print next arg (a string)
|
||||
c - print next arg (a character)
|
||||
|
||||
The file descriptor FD can be omitted, in which case
|
||||
COUT is used.
|
||||
*/
|
||||
|
||||
i = cgeti (fd); /* get integer (binary input) */
|
||||
i = cputi (i, fd); /* put integer (binary output) */
|
||||
|
||||
b = istty (fd); /* test if file is a TTY */
|
||||
|
||||
c = utyi (); /* read char from TTY (unbuffered, no echo) */
|
||||
utyo (c); /* output char to TTY (unbuffered) */
|
||||
tyo_flush (); /* flush TTY output buffer */
|
||||
|
||||
cexit (cc); /* terminate job, closing all files */
|
||||
/* returning from "main" is equivalent */
|
||||
|
||||
/* STRING Routines */
|
||||
|
||||
i = slen (s); /* find string length */
|
||||
stcpy (s1, s2); /* copy string from S1 to S2 */
|
||||
b = stcmp (s1, s2); /* compare strings */
|
||||
|
||||
/* storage allocation */
|
||||
|
||||
p = salloc (n); /* allocate n words, return pointer to it */
|
||||
sfree (p); /* free storage allocated by salloc */
|
||||
s = calloc (n); /* allocate n characters, return ptr to it */
|
||||
cfree (s); /* free storage allocated by calloc */
|
||||
76
c20/cinsrt-stinkr.mid
Normal file
76
c20/cinsrt-stinkr.mid
Normal file
@@ -0,0 +1,76 @@
|
||||
; PS:<C>CINSRT.MID
|
||||
|
||||
; This file is needed to assemble MIDAS programs produced by
|
||||
; the "new" C compiler as well as hand-coded MIDAS programs designed
|
||||
; to be loaded with C programs.
|
||||
|
||||
;.SYMTAB 4000.,4000.
|
||||
.symtab 6089.,4001.
|
||||
|
||||
RELOCATABLE
|
||||
.INSRT PS:<C>MULSEG
|
||||
.MSEG 400000',500000'
|
||||
|
||||
IF1,[
|
||||
.MLLIT==1
|
||||
|
||||
A=1
|
||||
B=2
|
||||
C=3
|
||||
D=4
|
||||
EP=14.
|
||||
P=15.
|
||||
GO=JRST
|
||||
|
||||
EQUALS ENTRY .GLOBAL
|
||||
EQUALS EXTERN .GLOBAL
|
||||
|
||||
.GLOBAL CFLOAT
|
||||
.GLOBAL CFIX
|
||||
|
||||
DEFINE .IDATA
|
||||
.SEG 0
|
||||
TERMIN
|
||||
|
||||
DEFINE .CODE
|
||||
.SEG 1
|
||||
TERMIN
|
||||
|
||||
DEFINE .PDATA
|
||||
.SEG 2
|
||||
TERMIN
|
||||
|
||||
; STACK HACKING FOR VARIABLE REFERENCES
|
||||
|
||||
DEFINE PPUSH [A]
|
||||
PUSH P,A
|
||||
TERMIN
|
||||
|
||||
DEFINE PPOP [A]
|
||||
POP P,A
|
||||
TERMIN
|
||||
|
||||
DEFINE CCALL N,F
|
||||
PUSHJ P,F
|
||||
HRRI P,%V(EP)
|
||||
TERMIN
|
||||
|
||||
];END IF1
|
||||
|
||||
IF2,[IFDEF FS1,[
|
||||
.KILL A,B,C,D,EP,P,GO
|
||||
]]
|
||||
|
||||
; HACK FOR CONSTANTS
|
||||
|
||||
EQUALS NM%EN END
|
||||
EXPUNGE END
|
||||
DEFINE END ENDLOC
|
||||
.CODE
|
||||
; INSCODE
|
||||
.PDATA
|
||||
CONSTANTS
|
||||
NM%EN ENDLOC
|
||||
TERMIN
|
||||
|
||||
.CODE
|
||||
76
c20/cinsrt.mid
Normal file
76
c20/cinsrt.mid
Normal file
@@ -0,0 +1,76 @@
|
||||
; PS:<C>CINSRT.MID
|
||||
|
||||
; This file is needed to assemble MIDAS programs produced by
|
||||
; the "new" C compiler as well as hand-coded MIDAS programs designed
|
||||
; to be loaded with C programs.
|
||||
|
||||
;.SYMTAB 4000.,4000.
|
||||
.symtab 6089.,4001.
|
||||
|
||||
RELOCATABLE
|
||||
.INSRT PS:<C>MULSEG
|
||||
.MSEG 400000',500000'
|
||||
|
||||
IF1,[
|
||||
.MLLIT==1
|
||||
|
||||
A=1
|
||||
B=2
|
||||
C=3
|
||||
D=4
|
||||
EP=14.
|
||||
P=15.
|
||||
GO=JRST
|
||||
|
||||
EQUALS ENTRY .GLOBAL
|
||||
EQUALS EXTERN .GLOBAL
|
||||
|
||||
.GLOBAL CFLOAT
|
||||
.GLOBAL CFIX
|
||||
|
||||
DEFINE .IDATA
|
||||
.SEG 0
|
||||
TERMIN
|
||||
|
||||
DEFINE .CODE
|
||||
.SEG 1
|
||||
TERMIN
|
||||
|
||||
DEFINE .PDATA
|
||||
.SEG 2
|
||||
TERMIN
|
||||
|
||||
; STACK HACKING FOR VARIABLE REFERENCES
|
||||
|
||||
DEFINE PPUSH [A]
|
||||
PUSH P,A
|
||||
TERMIN
|
||||
|
||||
DEFINE PPOP [A]
|
||||
POP P,A
|
||||
TERMIN
|
||||
|
||||
DEFINE CCALL N,F
|
||||
PUSHJ P,F
|
||||
HRRI P,%V(EP)
|
||||
TERMIN
|
||||
|
||||
];END IF1
|
||||
|
||||
IF2,[IFDEF FS1,[
|
||||
.KILL A,B,C,D,EP,P,GO
|
||||
]]
|
||||
|
||||
; HACK FOR CONSTANTS
|
||||
|
||||
EQUALS NM%EN END
|
||||
EXPUNGE END
|
||||
DEFINE END ENDLOC
|
||||
.CODE
|
||||
; INSCODE
|
||||
.PDATA
|
||||
CONSTANTS
|
||||
NM%EN ENDLOC
|
||||
TERMIN
|
||||
|
||||
.CODE
|
||||
24
c20/ctype.h
Normal file
24
c20/ctype.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#define _U 01
|
||||
#define _L 02
|
||||
#define _N 04
|
||||
#define _S 010
|
||||
#define _P 020
|
||||
#define _C 040
|
||||
#define _X 0100
|
||||
|
||||
extern char _ctype_[];
|
||||
|
||||
#define isalpha(c) ((_ctype_+1)[c]&(_U|_L))
|
||||
#define isupper(c) ((_ctype_+1)[c]&_U)
|
||||
#define islower(c) ((_ctype_+1)[c]&_L)
|
||||
#define isdigit(c) ((_ctype_+1)[c]&_N)
|
||||
#define isxdigit(c) ((_ctype_+1)[c]&(_N|_X))
|
||||
#define isspace(c) ((_ctype_+1)[c]&_S)
|
||||
#define ispunct(c) ((_ctype_+1)[c]&_P)
|
||||
#define isalnum(c) ((_ctype_+1)[c]&(_U|_L|_N))
|
||||
#define isprint(c) ((_ctype_+1)[c]&(_P|_U|_L|_N))
|
||||
#define iscntrl(c) ((_ctype_+1)[c]&_C)
|
||||
#define isascii(c) ((unsigned)(c)<=0177)
|
||||
#define toupper(c) ((c)-'a'+'A')
|
||||
#define tolower(c) ((c)-'A'+'a')
|
||||
#define toascii(c) ((c)&0177)
|
||||
115
c20/gt/cmac.gt
Normal file
115
c20/gt/cmac.gt
Normal file
@@ -0,0 +1,115 @@
|
||||
typenames (char, int, float, double);
|
||||
regnames (a, b);
|
||||
memnames (reg, auto, ext, stat, param, label, intlit, floatlit,
|
||||
stringlit, ia, ib);
|
||||
size 1 (char, int, float, double);
|
||||
align 1 (char, int, float, double);
|
||||
class r (a, b);
|
||||
saveareasize 8;
|
||||
pointer p0 (1);
|
||||
offsetrange p0 (0, 0);
|
||||
returnreg a (int, double, p0);
|
||||
type char(r), int(r), float(r), double(r), p0(r);
|
||||
|
||||
.sw: a,,1;
|
||||
|
||||
+i: -i: *i: /i: %: <<: >>:
|
||||
&: .OR: ^: +p0: -p0: -p0p0: a,b,a;
|
||||
|
||||
.BNOT: -ui: r,,1;
|
||||
|
||||
&u0: M,,r;
|
||||
|
||||
.ic: .ci: .ip0: .p0i: r,,1;
|
||||
|
||||
==p0: !=p0: <p0: >p0: <=p0: >=p0:
|
||||
==i: !=i: <i: >i: <=i: >=i: a,b,label;
|
||||
|
||||
==0p0: !=0p0: a,,label;
|
||||
|
||||
|
||||
macros
|
||||
|
||||
+i: " CADD"
|
||||
-i: " CSUB"
|
||||
*i: " CMUL"
|
||||
/i: " CDIV"
|
||||
%: " CMOD"
|
||||
<<: " CLS"
|
||||
>>: " CRS"
|
||||
&: " CAND"
|
||||
.OR: " COR"
|
||||
^: " CXOR"
|
||||
+p0: " PINC"
|
||||
-p0: " PDEC"
|
||||
-p0p0: " PSUB"
|
||||
-ui: " CMINUS #R"
|
||||
.BNOT: " CNOT #R"
|
||||
|
||||
&u0:
|
||||
(auto,,): " LAAUTO #R,#F"
|
||||
(ext,,): " LAEXTN #R,#F"
|
||||
(stat,,): " LASTAT #R,#F"
|
||||
(param,,): " LAPARM #R,#F"
|
||||
(stringlit,,): " LASTRG #R,#F"
|
||||
|
||||
==i: ==p0: " JEQ #R"
|
||||
!=i: !=p0: " JNE #R"
|
||||
<i: <p0: " JLT #R"
|
||||
>i: >p0: " JGT #R"
|
||||
<=i: <=p0: " JLE #R"
|
||||
>=i: >=p0: " JGE #R"
|
||||
|
||||
==0p0: " JNULL #R"
|
||||
!=0p0: " JNNULL #R"
|
||||
|
||||
.cc: .ii: .p0p0:
|
||||
(r,,r): " LREG #R,#F"
|
||||
(auto,,): " LAUTO #R,#F"
|
||||
(ext,,): " LEXTRN #R,#F"
|
||||
(stat,,): " LSTAT #R,#F"
|
||||
(param,,): " LPARM #R,#F"
|
||||
(ia|ib,,): " LVPTR #R,#F"
|
||||
(intlit,,): " LLIT #R,#F"
|
||||
(,,auto): " STAUTO #F,#R"
|
||||
(,,ext): " STEXTN #F,#R"
|
||||
(,,stat): " STSTAT #F,#R"
|
||||
(,,param): " STPARM #F,#R"
|
||||
(,,ia|ib): " STVPTR #F,#R"
|
||||
|
||||
.ic: .ci:
|
||||
.ip0: .p0i: "\"
|
||||
|
||||
hd: " HEAD"
|
||||
end: " CEND"
|
||||
en: " CENTRY #0"
|
||||
ex: " CEXTRN #0"
|
||||
|
||||
eq: " CEQU #0"
|
||||
l: " LABDEF #0"
|
||||
st: " STATIC #0"
|
||||
ln: " LINNUM #0"
|
||||
|
||||
ad0:
|
||||
(,,ext): " ADCON #R"
|
||||
(,,stat): " SADCON #R"
|
||||
in: c: " INTCON #0"
|
||||
lc: " LABCON #0"
|
||||
sc: " STRCON #0"
|
||||
z: " CZERO #0"
|
||||
|
||||
p: " PROLOG #0,%i(#1)"
|
||||
ep: " EPILOG #0,#1"
|
||||
ca:
|
||||
(ext,,): " CCALL #0,#1,#F"
|
||||
(ia|ib,,): " CALREG #0,#1,#F"
|
||||
rt: " CRETRN"
|
||||
go: " CGOTO #R"
|
||||
ts: " TSWITCH #0,#5,#2"
|
||||
ets: " ETSWIT #0,#5,#2"
|
||||
ls: " LSWITCH #0,#2"
|
||||
els: " ELSWIT #0,#2"
|
||||
|
||||
pu: pd: " PURE"
|
||||
im: da: " IMPURE"
|
||||
al: "\"
|
||||
85
c20/gt/g0.c
Normal file
85
c20/gt/g0.c
Normal file
@@ -0,0 +1,85 @@
|
||||
# include "gt.h"
|
||||
|
||||
/*
|
||||
|
||||
GT Compiler
|
||||
Section 0: Command Routine
|
||||
|
||||
*/
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
Command Usage: GT {-options} source.file
|
||||
|
||||
Output is written on the file "source.gtout".
|
||||
|
||||
Options:
|
||||
d - print parser debugging info
|
||||
t - print tokens
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
External Routines used by GT compiler:
|
||||
|
||||
copen open file for input/output
|
||||
cgetc read character
|
||||
cputc write character
|
||||
ceof test for end-of-file
|
||||
cclose close file
|
||||
cexit terminate process
|
||||
apfname append suffix to file name
|
||||
|
||||
plus C24.C (parser) and C96.C (cprint)
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
char *fn_source,
|
||||
*fn_out,
|
||||
fnbuff[40];
|
||||
|
||||
main (argc, argv) int argc; char *argv[];
|
||||
|
||||
{int f, i, c;
|
||||
extern int debug, tflag;
|
||||
char *s;
|
||||
|
||||
/* check for options */
|
||||
|
||||
if (argc > 1 && (s = argv[1])[0] == '-') i = 2;
|
||||
else {i = 1; s = 0;}
|
||||
|
||||
/* check for file name */
|
||||
|
||||
if (argc <= i)
|
||||
{cprint ("Usage: GT description.file\n");
|
||||
cexit (100);
|
||||
}
|
||||
|
||||
/* process options */
|
||||
|
||||
if (s) while (c = *++s) switch (c) {
|
||||
case 'd': debug = TRUE; break;
|
||||
case 't': tflag = TRUE; break;
|
||||
default: cprint ("unrecognized option: '%c'\n", c);
|
||||
}
|
||||
|
||||
/* check that source file exists */
|
||||
|
||||
fn_source = argv[i];
|
||||
if ((f = copen (fn_source, MREAD, TEXT)) == OPENLOSS)
|
||||
{cprint ("Can't Find '%s'.\n", fn_source);
|
||||
cexit (100);
|
||||
}
|
||||
cclose (f);
|
||||
|
||||
apfname (fnbuff, fn_source, "gtout");
|
||||
fn_out = fnbuff;
|
||||
|
||||
pinit ();
|
||||
parse ();
|
||||
cleanup (0);
|
||||
}
|
||||
|
||||
505
c20/gt/g1.c
Normal file
505
c20/gt/g1.c
Normal file
@@ -0,0 +1,505 @@
|
||||
# include "gt.h"
|
||||
|
||||
/*
|
||||
|
||||
GT Compiler
|
||||
Section 1: Lexical Analyzer
|
||||
|
||||
*/
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
A token consists of a TAG and an INDEX.
|
||||
The valid token TAGs are listed in the include file.
|
||||
The interpretation of the INDEX is dependent upon the TAG:
|
||||
|
||||
T_AMOP the number of the abstract_machine_operator
|
||||
TIDN index of identifier name in CSTORE
|
||||
TINTCON value of integer constant
|
||||
TSTRING index of source representation in CSTORE
|
||||
others the line number upon which the token appeared
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
char *keyn[] {
|
||||
"typenames",
|
||||
"align",
|
||||
"pointer",
|
||||
"class",
|
||||
"conflict",
|
||||
"type",
|
||||
"memnames",
|
||||
"macros",
|
||||
"size",
|
||||
"indirect",
|
||||
"regnames",
|
||||
"returnreg",
|
||||
"saveareasize",
|
||||
"offsetrange",
|
||||
"m",
|
||||
0};
|
||||
|
||||
int keyv[] {
|
||||
_TYPENAMES,
|
||||
_ALIGN,
|
||||
_POINTER,
|
||||
_CLASS,
|
||||
_CONFLICT,
|
||||
_TYPE,
|
||||
_MEMNAMES,
|
||||
_MACROS,
|
||||
_SIZE,
|
||||
_INDIRECT,
|
||||
_REGNAMES,
|
||||
_RETURNREG,
|
||||
_SAVEAREASIZE,
|
||||
_OFFSETRANGE,
|
||||
_M};
|
||||
|
||||
/* character type array */
|
||||
|
||||
# define _ALPHA 50 /* identifier or keyword */
|
||||
# define _DIGIT 51 /* constant or identifier */
|
||||
# define _QUOTE 52 /* character string indicator */
|
||||
# define _AMOP 53 /* character beginning an abstract_machine_operation */
|
||||
# define _EOL 54 /* newline */
|
||||
# define _BLANK 55 /* blank, tab, VT, FF, CR */
|
||||
# define _BAD 56 /* invalid character */
|
||||
# define _MINUS 57 /* minus sign: integer or AMOP */
|
||||
# define _NAME (typ[t]==_ALPHA || typ[t]==_DIGIT)
|
||||
|
||||
int typ[] {
|
||||
_BAD, _BAD, _BAD, _BAD, _BAD, _BAD, _BAD, _BAD,
|
||||
_BAD, _BLANK, _EOL, _BLANK, _BLANK, _BLANK, _BAD, _BAD,
|
||||
_BAD, _BAD, _BAD, _BAD, _BAD, _BAD, _BAD, _BAD,
|
||||
_BAD, _BAD, _BAD, _BAD, _BAD, _BAD, _BAD, _BAD,
|
||||
_BLANK, _AMOP, _QUOTE, _BAD, _BAD, _AMOP, _AMOP, _BAD,
|
||||
_LPARN, _RPARN, _AMOP, _AMOP, _COMMA, _MINUS, _AMOP, _AMOP,
|
||||
_DIGIT, _DIGIT, _DIGIT, _DIGIT, _DIGIT, _DIGIT, _DIGIT, _DIGIT,
|
||||
_DIGIT, _DIGIT, _COLON, _SEMI, _AMOP, _AMOP, _AMOP, _AMOP,
|
||||
_BAD, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA,
|
||||
_ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA,
|
||||
_ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA,
|
||||
_ALPHA, _ALPHA, _ALPHA, _LBRAK, _BAD, _RBRAK, _AMOP, _ALPHA,
|
||||
_BAD, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA,
|
||||
_ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA,
|
||||
_ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA, _ALPHA,
|
||||
_ALPHA, _ALPHA, _ALPHA, _BAD, _OR, _BAD, _NOT, _BAD};
|
||||
|
||||
/* translation table */
|
||||
|
||||
int trt[] {
|
||||
000,001,002,003,004,005,006,007,010,' ','\n',' ',' ',' ',016,017,
|
||||
020,021,022,023,024,025,026,027,030,031,032,033,034,035,036,037,
|
||||
' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',
|
||||
'0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?',
|
||||
0100,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
|
||||
'p','q','r','s','t','u','v','w','x','y','z','[','\\',']','^','_',
|
||||
0140,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
|
||||
'p','q','r','s','t','u','v','w','x','y','z','{','|','}','~',0177 };
|
||||
|
||||
/* hash table, holds keywords and identifiers */
|
||||
|
||||
# define hentry struct _hentry
|
||||
hentry
|
||||
{char *hnp; /* pointer to string in cstore */
|
||||
int hclass; /* 1 - identifier, >1 - keyword type,
|
||||
<=0 - manifest constant, index in mcdef */
|
||||
};
|
||||
|
||||
/* identifier classes */
|
||||
|
||||
# define h_idn 1
|
||||
|
||||
hentry hshtab[hshsize], *lookup(), *lookx();
|
||||
int hshused 0; /* number of entries used */
|
||||
|
||||
/* character store: holds keywords and identifiers */
|
||||
|
||||
char cstore[cssiz];
|
||||
char *cscsp -1; /* current string pointer: points to first
|
||||
unused character in cstore */
|
||||
char *cscnp -1; /* current name pointer: points to last unused
|
||||
character in cstore */
|
||||
char *cp; /* pointer to working string */
|
||||
|
||||
/* communication between lexical routines */
|
||||
|
||||
extern int lextag, lexindex, lexline;
|
||||
|
||||
int ccard, /* indicates that current
|
||||
tokens should be interpreted
|
||||
by the lexical phase */
|
||||
lccard, /* lgetc local ccard */
|
||||
c, /* current untranslated input char */
|
||||
t, /* current translated input char */
|
||||
peekt, /* lookahead translated character */
|
||||
truncate; /* indicates that cstore is full */
|
||||
|
||||
/* FILES */
|
||||
|
||||
int f_source -1; /* source file */
|
||||
|
||||
extern char *fn_source;
|
||||
|
||||
int i_line, /* current line number */
|
||||
i_eof, /* indicates end-of-file */
|
||||
i_nlflag; /* indicates first char of line */
|
||||
|
||||
/* manifest constants */
|
||||
|
||||
int jdefine, /* index of "DEFINE" in hashtab */
|
||||
mcdef[mcdsz], /* storage of manifest constant
|
||||
definitions */
|
||||
*cmcdp {mcdef}; /* pointer to next free word in mcdef */
|
||||
|
||||
char *eopch[] {
|
||||
"-ui", "-ud", "++bi", "++ai", "--bi", "--ai", ".bnot", "!",
|
||||
".lseq", "", ".sw", "++bc", "++ac", "--bc", "--ac", "&u0",
|
||||
"&u1", "&u2", "&u3", "*u", "==0p0", "==0p1", "==0p2", "==0p3",
|
||||
"!=0p0", "!=0p1", "!=0p2", "!=0p3", "", "", "", "",
|
||||
".ci", ".cf", ".cd", ".ic", ".if", ".id", ".ip0", ".ip1",
|
||||
".ip2", ".ip3", ".fc", ".fi", ".fd", ".dc", ".di", ".df",
|
||||
".p0i", ".p0p1", ".p0p2", ".p0p3", ".p1i", ".p1p0", ".p1p2", ".p1p3",
|
||||
".p2i", ".p2p0", ".p2p1", ".p2p3", ".p3i", ".p3p0", ".p3p1", ".p3p2",
|
||||
"+i", "=+i", "+d", "=+d", "-i", "=-i", "-d", "=-d",
|
||||
"*i", "=*i", "*d", "=*d", "/i", "=/i", "/d", "=/d",
|
||||
"%", "=%", "<<", "=<<", ">>", "=>>", "&", "=&",
|
||||
"^", "=^", ".or", "=or", "&&", ".tvor", "-p0p0", "=",
|
||||
".argi", ".argd", ".arg0", ".arg1", ".arg2", ".arg3", "+p0", "+p1",
|
||||
"+p2", "+p3", "-p0", "-p1", "-p2", "-p3", "", "",
|
||||
".cc", ".ii", ".ff", ".dd", ".p0p0", ".p1p1", ".p2p2", ".p3p3",
|
||||
"", "?", ".", "call", "float", "string", "int", "idn",
|
||||
"==i", "!=i", "<i", ">i", "<=i", ">=i", "==d", "!=d",
|
||||
"<d", ">d", "<=d", ">=d", "==p0", "!=p0", "<p0", ">p0",
|
||||
"<=p0", ">=p0", "==p1", "!=p1", "<p1", ">p1", "<=p1", ">=p1",
|
||||
"==p2", "!=p2", "<p2", ">p2", "<=p2", ">=p2", "==p3", "!=p3",
|
||||
"<p3", ">p3", "<=p3", ">=p3", "", "", "", "",
|
||||
"++bf", "++af", "--bf", "--af", "++bd", "++ad", "--bd", "--ad",
|
||||
"++bp0", "++ap0", "--bp0", "--ap0", "++bp1", "++ap1", "--bp1", "--ap1",
|
||||
"++bp2", "++ap2", "--bp2", "--ap2", "++bp3", "++ap3", "--bp3", "--ap3"};
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
GETTOK - Get Next Token
|
||||
|
||||
Sets variables LEXTAG, LEXINDEX, LEXLINE. This routine
|
||||
implements compiler control lines.
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
gettok ()
|
||||
|
||||
{while (TRUE)
|
||||
{tokget();
|
||||
if (ccard)
|
||||
{if (lextag==TIDN && lexindex==jdefine)
|
||||
defccl ();
|
||||
else {error (1004, lexline);
|
||||
while (lextag) tokget();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
DEFCCL - Handle DEFINE Compiler Control Line
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
defccl ()
|
||||
|
||||
{hentry *hp;
|
||||
int k;
|
||||
|
||||
tokget ();
|
||||
if (lextag != TIDN)
|
||||
{error (1003, lexline);
|
||||
while (lextag) tokget ();
|
||||
}
|
||||
else
|
||||
{hp = lookx ();
|
||||
k = -(cmcdp-mcdef);
|
||||
do
|
||||
{tokget();
|
||||
if(cmcdp >= &mcdef[mcdsz-1])
|
||||
error(4004, lexline);
|
||||
*cmcdp++ = lextag;
|
||||
if (lextag<TIDN) lexindex = UNDEF;
|
||||
*cmcdp++ = lexindex;
|
||||
}
|
||||
while (lextag);
|
||||
--cmcdp;
|
||||
hp->hclass = k;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
TOKGET - Internal Get Token Routine
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
tokget ()
|
||||
|
||||
{static int *mcp, mcflag;
|
||||
int sum, flag, i;
|
||||
char buf[40];
|
||||
hentry *hp;
|
||||
|
||||
while (TRUE)
|
||||
{if (mcflag)
|
||||
{lextag= *mcp++;
|
||||
lexindex= *mcp++;
|
||||
if (lexindex==UNDEF) lexindex=lexline;
|
||||
if (lextag) return;
|
||||
mcflag=FALSE;
|
||||
}
|
||||
if (peekt) t=peekt;
|
||||
else t=trt[lgetc()];
|
||||
if (!t) break;
|
||||
peekt=NULL;
|
||||
flag = truncate = FALSE;
|
||||
cp = cscsp; /* character stack pointer */
|
||||
lexline = i_line; /* lgetc current line */
|
||||
ccard =| lccard; /* set control card indicator */
|
||||
|
||||
switch (typ[t]) {
|
||||
|
||||
case _ALPHA: do move(t); while (_NAME);
|
||||
*cp = 0;
|
||||
hp = lookup (cscsp);
|
||||
peekt = t;
|
||||
if (hp->hclass > 1) /* keyword */
|
||||
{lextag = hp->hclass;
|
||||
lexindex = lexline;
|
||||
}
|
||||
else if (hp->hclass <= 0) /* manifest constant */
|
||||
{mcflag = TRUE;
|
||||
mcp = mcdef + -hp->hclass;
|
||||
continue;
|
||||
}
|
||||
else /* identifier */
|
||||
{lextag = TIDN;
|
||||
lexindex = hp->hnp - cstore;
|
||||
if (truncate) error (4001,lexline);
|
||||
}
|
||||
return;
|
||||
|
||||
case _MINUS: move(0); /* look at next char */
|
||||
if (typ[t] != _DIGIT)
|
||||
{peekt = '-';
|
||||
goto l_amop;
|
||||
}
|
||||
flag = TRUE;
|
||||
|
||||
case _DIGIT: /* fall through */
|
||||
|
||||
sum = 0;
|
||||
do
|
||||
{sum = sum*10 + t-'0';
|
||||
move (0);
|
||||
} while (typ[t] == _DIGIT);
|
||||
|
||||
lextag = TINTCON;
|
||||
lexindex = (flag ? -sum : sum);
|
||||
peekt = t;
|
||||
return;
|
||||
|
||||
case _AMOP: /* abstract machine operator */
|
||||
|
||||
l_amop: i = 0;
|
||||
if (peekt) buf[i++]=peekt;
|
||||
do {buf[i++]=t; move(0);}
|
||||
while(typ[t]==_AMOP || typ[t]==_ALPHA
|
||||
|| typ[t]==_DIGIT || typ[t]==_MINUS );
|
||||
peekt = t;
|
||||
buf[i]=0;
|
||||
for (i=0;i<eopchsz;i++)
|
||||
if (stcmp(buf,eopch[i]))
|
||||
{lextag = T_AMOP;
|
||||
lexindex = i;
|
||||
return;
|
||||
}
|
||||
error (1002, lexline);
|
||||
continue;
|
||||
|
||||
case _QUOTE: /* character string */
|
||||
lexindex = cscsp - cstore;
|
||||
move(0); /* get next character */
|
||||
while (t)
|
||||
{if (t=='"')
|
||||
{move (0);
|
||||
if (t != '"') break;
|
||||
}
|
||||
move (c);
|
||||
}
|
||||
if (!t) error (2001, lexline);
|
||||
if (truncate) error (4001, lexline);
|
||||
lextag = TSTRING;
|
||||
cscsp = cp;
|
||||
*cscsp++ = 0;
|
||||
peekt = t;
|
||||
return;
|
||||
|
||||
case _EOL: if (ccard)
|
||||
{ccard=FALSE;
|
||||
lextag=LEXEOF;
|
||||
return;
|
||||
}
|
||||
|
||||
case _BLANK: continue;
|
||||
|
||||
case _BAD: error (1000, lexline);
|
||||
continue;
|
||||
|
||||
default: /* single character operator */
|
||||
lextag = typ[t];
|
||||
lexindex = lexline;
|
||||
return;
|
||||
}
|
||||
}
|
||||
lextag = TEOF;
|
||||
lexindex = lexline;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
MOVE - Move Character Into Buffer and Advance Input
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
move (u)
|
||||
|
||||
{if (u) if (cp<cscnp-1) *cp++ = u; else truncate=TRUE;
|
||||
return (t=trt[c=lgetc()]);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
LOOKUP - lookup or enter a symbol in the hash table
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
hentry *lookup (np) char *np;
|
||||
|
||||
{int i, u;
|
||||
char *p, *ep;
|
||||
hentry *hp;
|
||||
|
||||
i = 0;
|
||||
p = np;
|
||||
while (u = *p++) i =+ (u & 0177);
|
||||
if (i<0) i = -i;
|
||||
i =% hshsize;
|
||||
|
||||
/* search entries until found or empty */
|
||||
|
||||
while (ep = hshtab[i].hnp)
|
||||
if (stcmp(np,ep)) return (&hshtab[i]);
|
||||
else if (++i>=hshsize) i=0;
|
||||
|
||||
/* not found, so enter */
|
||||
|
||||
if (++hshused >= hshsize) error (4000,lexline);
|
||||
while (--p >= np) *cscnp-- = *p; /* move name */
|
||||
hp = &hshtab[i];
|
||||
hp->hnp = cscnp+1;
|
||||
hp->hclass = h_idn;
|
||||
return (hp);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
LOOKX - lookup current identifier
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
hentry *lookx ()
|
||||
{return (lookup (&cstore[lexindex]));}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
LXINIT - Lexical Phase Initializaton Routine
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
lxinit()
|
||||
|
||||
{int i;
|
||||
char *s;
|
||||
|
||||
f_source = xopen (fn_source, MREAD, TEXT);
|
||||
cscsp = cstore;
|
||||
cscnp = &cstore[cssiz-1];
|
||||
lexline = i_line = 1;
|
||||
i_eof = FALSE;
|
||||
i_nlflag = TRUE;
|
||||
|
||||
i = 0;
|
||||
while (s = keyn[i]) keyword (s, keyv[i++]);
|
||||
|
||||
jdefine=lookup("define")->hnp-cstore;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
KEYWORD - Define a Reserved Word
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
int keyword (s, type) int type; char *s;
|
||||
|
||||
{lookup(s)->hclass = type;}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
LGETC - Character Input Routine
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
int lgetc()
|
||||
|
||||
{int ch;
|
||||
|
||||
if (i_eof) return (LEXEOF);
|
||||
|
||||
while (TRUE)
|
||||
{ch = cgetc (f_source);
|
||||
if (ceof (f_source))
|
||||
{i_eof=TRUE;
|
||||
return (LEXEOF);
|
||||
}
|
||||
if (trt[ch]=='\n')
|
||||
{++i_line;
|
||||
lccard=FALSE;
|
||||
i_nlflag=TRUE;
|
||||
}
|
||||
else if (i_nlflag)
|
||||
{i_nlflag=FALSE;
|
||||
if (trt[ch]=='#')
|
||||
{lccard=TRUE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return (ch);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
STCMP - Compare Strings
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
int stcmp (s1, s2) char *s1,*s2;
|
||||
|
||||
{int u;
|
||||
|
||||
while ((u = *s1++) == *s2++) if (!u) return (TRUE);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
153
c20/gt/g2.c
Normal file
153
c20/gt/g2.c
Normal file
@@ -0,0 +1,153 @@
|
||||
# include "gt.h"
|
||||
|
||||
/*
|
||||
|
||||
GT Compiler
|
||||
Section 2: Parser Interface
|
||||
|
||||
*/
|
||||
|
||||
extern int lineno;
|
||||
extern char cstore[], *fn_out;
|
||||
|
||||
int f_out -1;
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
Parser Error Message Routines
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
synerr (line) {error (2007, line);}
|
||||
giveup (line) {error (4012, line);}
|
||||
stkovf (line) {error (4003, line);}
|
||||
delmsg (line) {error (2012, line);}
|
||||
skpmsg (line) {error (2013, line);}
|
||||
|
||||
qprint (q) {error (2008, -1, q);}
|
||||
tprint (tp) token *tp; {error (2011, -1, tp->type, tp->index);}
|
||||
pcursor () {error (2010, -1);}
|
||||
|
||||
stkunf (line) {error (6006, line);}
|
||||
tkbovf (line) {error (6002, line);}
|
||||
badtwp (line) {error (6005, line);}
|
||||
badtok (line, i) {error (6000, line, i);}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
PTOKEN - Print Token Routine
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
ptoken (tp, f) token *tp;
|
||||
|
||||
{int type, index;
|
||||
extern char *sterm[], *eopch[];
|
||||
|
||||
type = tp->type;
|
||||
index = tp->index;
|
||||
switch (type) {
|
||||
case TIDN: cprint (f, "%s", &cstore[index]);
|
||||
return;
|
||||
case TINTCON: cprint (f, "%d", index);
|
||||
return;
|
||||
case TSTRING: cprint (f, "\"\"");
|
||||
return;
|
||||
case T_AMOP: cprint (f, "%s", eopch[index]);
|
||||
return;
|
||||
default: cprint (f, "%s", sterm[type]);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
PINIT - Parser Initialization Routine
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
pinit ()
|
||||
|
||||
{extern int prm();
|
||||
lxinit ();
|
||||
f_out = xopen (fn_out, MWRITE, TEXT);
|
||||
deffmt ('m', prm, 1);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
CLEANUP - Parser CleanUp Routine
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
cleanup (rcode)
|
||||
|
||||
{cclose (f_out);
|
||||
cexit (rcode);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
STACK FOR ACTION ROUTINES
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
int stack[pssize];
|
||||
int *sp {stack};
|
||||
|
||||
int *push (i)
|
||||
|
||||
{if (++sp >= &stack[pssize]) error (4007, lineno);
|
||||
*sp = i;
|
||||
return (sp);
|
||||
}
|
||||
|
||||
int pop ()
|
||||
|
||||
{int i;
|
||||
|
||||
i = *sp--;
|
||||
if (sp < stack) error (6001, lineno);
|
||||
return (i);
|
||||
}
|
||||
|
||||
int *setsp (nsp) int *nsp; /* set stack pointer */
|
||||
|
||||
{if (nsp < stack) error (6003, lineno);
|
||||
if (nsp >= &stack[pssize]) error (6004, lineno);
|
||||
return (sp = nsp);
|
||||
}
|
||||
|
||||
int *top () /* get stack pointer */
|
||||
|
||||
{return (sp);
|
||||
}
|
||||
|
||||
int *get_top (nsp) int *nsp; /* get list from top of stack */
|
||||
|
||||
{int *ot;
|
||||
|
||||
ot = top();
|
||||
setsp (nsp-1);
|
||||
return (ot);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
GPRINT - Formatted Print Routine
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
gprint (fmt,x1,x2,x3) char fmt[];
|
||||
|
||||
{cprint (f_out, fmt, x1, x2, x3);}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
PRM - Print String in Cstore
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
prm (i, f)
|
||||
|
||||
{cprint (f, "%s", &cstore[i]);}
|
||||
|
||||
1045
c20/gt/g3.c
Normal file
1045
c20/gt/g3.c
Normal file
File diff suppressed because it is too large
Load Diff
308
c20/gt/g4.c
Normal file
308
c20/gt/g4.c
Normal file
@@ -0,0 +1,308 @@
|
||||
# include "gt.h"
|
||||
|
||||
/*
|
||||
|
||||
GT Compiler
|
||||
Section 4: Parsing Tables
|
||||
|
||||
*/
|
||||
|
||||
extern int copflag, amopl[], c_amopl, coplist;
|
||||
extern int mactab[], macdef[], cmacro, lineno;
|
||||
|
||||
extern int val, line, *pv, *pl;
|
||||
|
||||
ar3 ()
|
||||
{fs1();}
|
||||
|
||||
ar4 ()
|
||||
{fs2();}
|
||||
|
||||
ar21 ()
|
||||
{error(4025,lineno);}
|
||||
|
||||
ar22 ()
|
||||
{ftype();}
|
||||
|
||||
ar23 ()
|
||||
{error(4022,lineno);}
|
||||
|
||||
ar24 ()
|
||||
{foploc();}
|
||||
|
||||
ar25 ()
|
||||
{error(4023,lineno);}
|
||||
|
||||
ar26 ()
|
||||
{fmacro();}
|
||||
|
||||
ar27 ()
|
||||
{error(4024,lineno);}
|
||||
|
||||
ar56 ()
|
||||
{amopl[c_amopl++]= -1;coplist=0;}
|
||||
|
||||
ar57 ()
|
||||
{asave(pv[2]);}
|
||||
|
||||
ar58 ()
|
||||
{asize(pv[1],pv[3]);}
|
||||
|
||||
ar59 ()
|
||||
{aalign(pv[1],pv[3]);}
|
||||
|
||||
ar60 ()
|
||||
{apoint(pv[1],pv[3]);}
|
||||
|
||||
ar61 ()
|
||||
{aclass(pv[1],pv[3]);}
|
||||
|
||||
ar62 ()
|
||||
{aretreg(pv[1],pv[3]);}
|
||||
|
||||
ar63 ()
|
||||
{atype(pv[1],pv[3]);}
|
||||
|
||||
ar64 ()
|
||||
{aconf(pv[2],pv[4]);}
|
||||
|
||||
ar65 ()
|
||||
{push(pv[3]);}
|
||||
|
||||
ar66 ()
|
||||
{val=push(pv[1]);}
|
||||
|
||||
ar67 ()
|
||||
{push(pv[3]);}
|
||||
|
||||
ar68 ()
|
||||
{val=push(pv[1]);}
|
||||
|
||||
ar69 ()
|
||||
{atnames(pv[3]);}
|
||||
|
||||
ar70 ()
|
||||
{amnames(pv[3]);}
|
||||
|
||||
ar71 ()
|
||||
{arnames(pv[3]);}
|
||||
|
||||
ar72 ()
|
||||
{aor1(pv[1],pv[3],pv[5]);}
|
||||
|
||||
ar73 ()
|
||||
{aor2(pv[1],pv[3]);}
|
||||
|
||||
ar74 ()
|
||||
{aor3(pv[1],pv[4]);}
|
||||
|
||||
ar75 ()
|
||||
{aor4(pv[1]);}
|
||||
|
||||
ar78 ()
|
||||
{aoploc(pv[6]);}
|
||||
|
||||
ar79 ()
|
||||
{aamop(pv[1]);}
|
||||
|
||||
ar80 ()
|
||||
{aamop(pv[1]);}
|
||||
|
||||
ar81 ()
|
||||
{aopl(0,copflag,pv[1]);}
|
||||
|
||||
ar82 ()
|
||||
{aopl(1,copflag,pv[1]);}
|
||||
|
||||
ar83 ()
|
||||
{aopl(1,0,0);}
|
||||
|
||||
ar84 ()
|
||||
{aopl(2,copflag,pv[1]);}
|
||||
|
||||
ar86 ()
|
||||
{copflag=pv[1]+2;val=0;}
|
||||
|
||||
ar87 ()
|
||||
{val=pv[1] | pv[3];}
|
||||
|
||||
ar88 ()
|
||||
{val= ~pv[2];}
|
||||
|
||||
ar89 ()
|
||||
{val=pv[2];}
|
||||
|
||||
ar90 ()
|
||||
{val=aope(-1);}
|
||||
|
||||
ar91 ()
|
||||
{val=aope(-2);}
|
||||
|
||||
ar92 ()
|
||||
{val=aope(pv[1]);}
|
||||
|
||||
ar93 ()
|
||||
{val=aclobber(pv[2]);}
|
||||
|
||||
ar94 ()
|
||||
{val=0;}
|
||||
|
||||
ar95 ()
|
||||
{macdef[cmacro++]=pv[2];mpush(-1);}
|
||||
|
||||
ar100 ()
|
||||
{mpush(-3);val=pv[2];}
|
||||
|
||||
ar101 ()
|
||||
{val=mpsh2(3,-3);}
|
||||
|
||||
ar102 ()
|
||||
{val=mpsh2(copflag,pv[1]);copflag=0;}
|
||||
|
||||
ar103 ()
|
||||
{val=mpsh2(0,0);}
|
||||
|
||||
ar104 ()
|
||||
{mactab[pv[1]]=cmacro;}
|
||||
|
||||
ar105 ()
|
||||
{nmac(pv[1],cmacro);}
|
||||
|
||||
ar106 ()
|
||||
{push(pv[3]);}
|
||||
|
||||
ar107 ()
|
||||
{val=push(pv[1]);}
|
||||
|
||||
int (*act[])() {
|
||||
0, 0, 0, ar3, ar4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, ar21, ar22, ar23, ar24, ar25, ar26, ar27, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, ar56, ar57, ar58, ar59, ar60, ar61,
|
||||
ar62, ar63, ar64, ar65, ar66, ar67, ar68, ar69, ar70, ar71,
|
||||
ar72, ar73, ar74, ar75, 0, 0, ar78, ar79, ar80, ar81, ar82,
|
||||
ar83, ar84, 0, ar86, ar87, ar88, ar89, ar90, ar91, ar92,
|
||||
ar93, ar94, ar95, 0, 0, 0, 0, ar100, ar101, ar102, ar103,
|
||||
ar104, ar105, ar106, ar107, -1};
|
||||
|
||||
|
||||
|
||||
int r1[] {
|
||||
0, 1, 2, 3, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9,
|
||||
9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16,
|
||||
17, 17, 18, 19, 19, 20, 21, 21, 22, 23, 23, 24, 25, 25,
|
||||
26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 35, 36,
|
||||
37, 38, 39, 40, 41, 41, 42, 42, 43, 44, 45, 46, 46, 46,
|
||||
46, 47, 47, 48, 49, 49, 50, 51, 51, 52, 53, 53, 54, 54,
|
||||
54, 54, 54, 54, 55, 55, 56, 57, 57, 58, 58, 59, 59, 60,
|
||||
60, 61, 61, 62, 62, -1};
|
||||
|
||||
int r2[] {
|
||||
0, 2, 8, 1, 1, 2, 0, 1, 1, 1, 2, 0, 1, 1, 1, 1, 1, 1, 1,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 1, 2, 1, 3, 3, 1, 3, 3, 1,
|
||||
3, 3, 1, 3, 3, 1, 3, 3, 1, 3, 3, 1, 3, 3, 1, 3, 3, 1, 2,
|
||||
3, 4, 4, 4, 4, 4, 4, 5, 3, 1, 3, 1, 5, 5, 5, 6, 5, 5, 4,
|
||||
2, 1, 7, 3, 2, 1, 1, 0, 1, 1, 1, 3, 2, 3, 1, 1, 1, 3, 0,
|
||||
2, 3, 2, 2, 1, 9, 1, 1, 0, 1, 1, 3, 1, -1};
|
||||
|
||||
int g[] {
|
||||
0, 0, 2, 0, 3, 0, 5, 0, 4, 0, 10, 0, 6, 0, 23, 0, 15, 0,
|
||||
37, 0, 66, 0, 98, 0, 152, 0, 99, 0, 153, 0, 24, 0, 52,
|
||||
0, 25, 0, 40, 0, 26, 0, 43, 0, 27, 0, 46, 0, 16, 0, 34,
|
||||
0, 38, 0, 63, 0, 67, 0, 95, 0, 28, 0, 49, 99, 126, 0, 100,
|
||||
0, 29, 82, 111, 0, 53, 70, 103, 0, 41, 73, 105, 0, 44,
|
||||
76, 107, 0, 47, 93, 120, 0, 64, 123, 148, 0, 96, 79, 109,
|
||||
0, 50, 0, 50, 31, 57, 32, 58, 68, 102, 74, 106, 80, 110,
|
||||
91, 119, 121, 147, 185, 188, 0, 56, 0, 11, 0, 12, 0, 13,
|
||||
61, 90, 0, 35, 0, 133, 133, 159, 0, 134, 124, 149, 0, 101,
|
||||
0, 135, 0, 173, 0, 182, 160, 174, 180, 183, 0, 136, 127,
|
||||
157, 128, 158, 161, 175, 166, 176, 181, 176, 187, 176,
|
||||
0, 137, 0, 186, 153, 165, 0, 154, 0, 155, 0, 168, 168,
|
||||
178, 0, 169, 181, 184, 187, 190, 0, 177, 155, 170, 0, 156,
|
||||
0, 156, -1};
|
||||
|
||||
int pg[] {
|
||||
0, 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27,
|
||||
29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55,
|
||||
57, 59, 61, 65, 67, 71, 75, 79, 83, 87, 91, 95, 97, 115,
|
||||
117, 119, 121, 125, 127, 131, 135, 137, 139, 141, 147,
|
||||
161, 163, 167, 169, 171, 175, 181, 185, -1};
|
||||
|
||||
int nbpw {16};
|
||||
|
||||
int nwpbt {2};
|
||||
|
||||
int a[] {
|
||||
0, 0, 0, 60, 30, 85, 185, 191, 124, 61, 161, 128, 97, 7,
|
||||
17, 18, 19, 20, 65, 8, 125, 21, 129, 9, 36, 22, 14, 130,
|
||||
33, 39, 167, 12294, 4097, 16384, 0, 12299, 20481, 8192,
|
||||
136, 12291, 4122, 8206, 12307, 20481, 49152, 547, 12292,
|
||||
4100, 8222, 0, 4100, 8223, 0, 4100, 8224, 0, 12293, 12295,
|
||||
12297, 12296, 4124, 8225, 0, 4120, 8228, 12309, 12306,
|
||||
4125, 8231, 0, 4124, 8234, 0, 4124, 8237, 0, 4100, 8240,
|
||||
0, 4125, 8243, 0, 4125, 8246, 0, 12298, 12300, 12301, 12304,
|
||||
12302, 12303, 12305, 4124, 8247, 0, 4100, 8251, 0, 4099,
|
||||
8252, 4105, 8253, 0, 12334, 4124, 8254, 0, 4114, 8257,
|
||||
12311, 12308, 4100, 8260, 0, 4099, 8261, 4105, 8262, 0,
|
||||
12325, 4100, 8263, 0, 4099, 8264, 4105, 8265, 0, 12328,
|
||||
4100, 8266, 0, 4099, 8267, 4105, 8268, 0, 12331, 4124,
|
||||
8269, 0, 4099, 8270, 4105, 8271, 0, 12343, 4100, 8272,
|
||||
0, 4099, 8273, 4105, 8274, 0, 12322, 4099, 8275, 0, 12356,
|
||||
4101, 8277, 4105, 8276, 0, 4101, 8278, 4105, 8276, 0, 4101,
|
||||
8279, 4105, 8276, 0, 4105, 8281, 4125, 8280, 0, 12332,
|
||||
4124, 8225, 0, 4100, 8283, 0, 4099, 8284, 4105, 8285, 0,
|
||||
12337, 4124, 8286, 0, 4108, 8289, 12313, 12310, 12323,
|
||||
4125, 8231, 0, 4125, 8296, 0, 12326, 4124, 8234, 0, 12329,
|
||||
4124, 8237, 0, 4105, 8300, 0, 12341, 4100, 8240, 0, 12320,
|
||||
4125, 8243, 0, 12345, 4124, 8304, 0, 4099, 8305, 0, 4099,
|
||||
8306, 0, 4099, 8307, 0, 4105, 8308, 0, 4101, 8310, 4125,
|
||||
8309, 0, 12333, 12335, 4124, 8254, 0, 4100, 8313, 0, 4099,
|
||||
8314, 4105, 8315, 0, 12340, 4104, 8316, 0, 4116, 8317,
|
||||
0, 4108, 8289, 12312, 12317, 20481, 2048, 2112, 4100, 8319,
|
||||
4124, 8323, 4125, 8324, 0, 4101, 8330, 4105, 8276, 0, 12324,
|
||||
4101, 8331, 0, 12327, 4101, 8332, 4105, 8276, 0, 12330,
|
||||
4124, 8333, 0, 12342, 4101, 8334, 4105, 8276, 0, 12321,
|
||||
12355, 12357, 12358, 12359, 4101, 8336, 4125, 8335, 0,
|
||||
4101, 8337, 0, 12363, 4101, 8338, 4105, 8276, 0, 12336,
|
||||
12338, 4124, 8286, 0, 4108, 8289, 12368, 4108, 8342, 4124,
|
||||
8343, 12315, 12316, 20481, 2048, 2112, 4100, 8319, 4124,
|
||||
8323, 0, 12378, 12379, 12380, 12374, 20481, 2048, 2112,
|
||||
4100, 8319, 4124, 8323, 4125, 8324, 12344, 12365, 4105,
|
||||
8352, 0, 12369, 4106, 8353, 12373, 12347, 12348, 12349,
|
||||
4101, 8354, 0, 12346, 4101, 8355, 0, 12361, 12362, 12350,
|
||||
4101, 8356, 4105, 8276, 0, 12339, 12367, 12392, 12393,
|
||||
12290, 4108, 8342, 4124, 8343, 12314, 12319, 4100, 8358,
|
||||
4108, 8342, 4124, 8343, 4126, 8359, 0, 4104, 8363, 0, 4101,
|
||||
8364, 4106, 8353, 0, 12376, 12364, 20481, 2048, 2112, 4100,
|
||||
8319, 4124, 8323, 4125, 8324, 12371, 12352, 12360, 12351,
|
||||
12318, 20481, 2048, 2112, 4100, 8319, 4124, 8323, 12391,
|
||||
12389, 4100, 8358, 4126, 8359, 12383, 12387, 4104, 8371,
|
||||
0, 12385, 12377, 4105, 8372, 0, 12370, 12375, 4106, 8353,
|
||||
12390, 4105, 8373, 0, 12386, 12384, 20481, 2048, 2112,
|
||||
4100, 8319, 4124, 8323, 4125, 8324, 0, 20481, 2048, 2112,
|
||||
4100, 8319, 4124, 8323, 12391, 4102, 8377, 12382, 12372,
|
||||
4105, 8379, 0, 4099, 8381, 0, 20481, 2048, 2112, 4100,
|
||||
8319, 4124, 8323, 12391, 4103, 8383, 4105, 8276, 0, 12366,
|
||||
4101, 8384, 0, 12381, 4104, 8385, 0, 4126, 8386, 0, 12388,
|
||||
-1};
|
||||
|
||||
int pa[] {
|
||||
0, 31, 32, 35, 36, 40, 43, 47, 50, 53, 56, 57, 58, 59,
|
||||
60, 63, 66, 67, 70, 73, 76, 79, 82, 85, 86, 87, 88, 89,
|
||||
90, 91, 92, 92, 92, 95, 98, 103, 104, 107, 110, 111, 114,
|
||||
119, 120, 123, 128, 129, 132, 137, 138, 141, 146, 147,
|
||||
150, 155, 156, 159, 160, 165, 170, 175, 180, 181, 184,
|
||||
187, 192, 193, 196, 199, 92, 200, 201, 204, 207, 208, 92,
|
||||
211, 212, 215, 218, 219, 92, 222, 223, 226, 227, 230, 233,
|
||||
236, 239, 242, 247, 92, 248, 249, 252, 255, 260, 261, 264,
|
||||
267, 270, 271, 281, 286, 287, 290, 291, 296, 297, 300,
|
||||
301, 306, 307, 308, 309, 310, 311, 316, 319, 320, 325,
|
||||
92, 326, 327, 330, 333, 338, 339, 339, 347, 348, 349, 350,
|
||||
351, 361, 362, 365, 366, 369, 370, 371, 372, 375, 376,
|
||||
379, 380, 381, 382, 387, 388, 389, 390, 391, 392, 397,
|
||||
398, 407, 410, 415, 416, 417, 339, 427, 428, 429, 430,
|
||||
431, 439, 440, 445, 446, 449, 450, 451, 454, 455, 456,
|
||||
459, 462, 463, 464, 474, 482, 485, 486, 92, 489, 492, 500,
|
||||
505, 506, 509, 510, 513, 516, -1};
|
||||
|
||||
|
||||
276
c20/gt/g5.c
Normal file
276
c20/gt/g5.c
Normal file
@@ -0,0 +1,276 @@
|
||||
# include "gt.h"
|
||||
|
||||
/*
|
||||
|
||||
GT Compiler
|
||||
Section 5: Error Message Editor
|
||||
|
||||
*/
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
global variables
|
||||
|
||||
sterm table of GT terminal symbols
|
||||
snterm table of GT nonterminal symbols
|
||||
sq table of states
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
extern char cstore[], *eopch[];
|
||||
|
||||
char *sterm[] {
|
||||
"", "-|", "error", ";", "(", ")", "[", "]", ":", ",", "|",
|
||||
"~", "amop", "TYPENAMES", "ALIGN", "POINTER", "CLASS",
|
||||
"CONFLICT", "TYPE", "MEMNAMES", "MACROS", "SIZE", "INDIRECT",
|
||||
"REGNAMES", "RETURNREG", "SAVEAREASIZE", "OFFSETRANGE",
|
||||
"M", "idn", "integer", "string", 0};
|
||||
|
||||
char *snterm[] {
|
||||
"", "$accept", "program", "$s1", "$s2", "$s1.list", "s1",
|
||||
"$s2.list", "s2", "$or", "$r", "$t", "$o", "$m", "$o.list",
|
||||
"$m.list", "$size", "s.list", "$align", "a.list", "$pointer",
|
||||
"p.list", "$class", "c.list", "$offsetrange", "or.list",
|
||||
"$returnreg", "r.list", "$type", "t.list", "$conflict",
|
||||
"x.list", "$oploc", "$saveareasize", "s.elem", "a.elem",
|
||||
"p.elem", "c.elem", "r.elem", "t.elem", "x.elem", "int_list",
|
||||
"idn_list", "$typenames", "$memnames", "$regnames", "or.elem",
|
||||
"oploc_list", "oploc", "oplist", "op1", "op2", "op3", "opl",
|
||||
"ope", "clobber", "macro", "name_list", "cstring_list",
|
||||
"cstring", "ope2", "name", "amop_list", 0};
|
||||
|
||||
int sq[] {
|
||||
0, 0, 4098, 4099, 4101, 4100, 4103, 13, 19, 23, 4102, 4139,
|
||||
4140, 4141, 26, 4105, 4120, 14, 15, 16, 17, 21, 25, 4104,
|
||||
4112, 4114, 4116, 4118, 4126, 4129, 4, 4, 4, 28, 4121,
|
||||
4142, 24, 4106, 4122, 29, 4115, 4131, 28, 4117, 4132, 28,
|
||||
4119, 4133, 4, 4127, 4136, 29, 4113, 4130, 29, 28, 4138,
|
||||
4138, 4138, 4, 3, 9, 28, 4123, 4134, 18, 4107, 4124, 4,
|
||||
3, 9, 4, 3, 9, 4, 3, 9, 28, 3, 9, 4, 3, 9, 3, 9, 5, 5,
|
||||
5, 29, 9, 4142, 4, 3, 9, 28, 4125, 4135, 12, 4108, 4110,
|
||||
4128, 4145, 4138, 4131, 29, 4132, 4138, 4133, 9, 4136,
|
||||
4138, 4130, 28, 3, 3, 3, 9, 29, 5, 4138, 4134, 4, 3, 9,
|
||||
8, 20, 4128, 4, 11, 22, 27, 28, 29, 4143, 4144, 4146, 4149,
|
||||
4150, 5, 5, 5, 28, 5, 29, 5, 5, 5, 4138, 4135, 4145, 12,
|
||||
28, 4109, 4111, 4152, 4153, 4157, 4150, 4150, 4144, 9,
|
||||
10, 5, 5, 5, 4152, 4, 30, 4154, 4155, 4157, 8, 5, 4147,
|
||||
4149, 4150, 4150, 4156, 4155, 8, 9, 9, 4148, 4149, 4156,
|
||||
6, 4151, 9, 4138, 3, 4156, 7, 5, 8, 30, -1};
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
ERROR MESSAGES
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
char *m1000[] {
|
||||
/* 1000 */ "INVALID CHARACTER",
|
||||
/* 1001 */ "INVALID ESCAPE CHARACTER",
|
||||
/* 1002 */ "UNRECOGNIZED ABSTRACT MACHINE OPERATOR",
|
||||
/* 1003 */ "INVALID MANIFEST CONSTANT DEFINITION",
|
||||
/* 1004 */ "INVALID COMPILER CONTROL LINE",
|
||||
/* 1005 */ "INVALID ESCAPE CONTROL LINE"
|
||||
};
|
||||
|
||||
char *m2000[] {
|
||||
/* 2000 */ 0,
|
||||
/* 2001 */ "UNTERMINATED STRING CONSTANT",
|
||||
/* 2002 */ "MULTIPLE TYPENAMES STATEMENTS IGNORED",
|
||||
/* 2003 */ "MULTIPLE REGNAMES STATEMENTS IGNORED",
|
||||
/* 2004 */ "MULTIPLE MEMNAMES STATEMENTS IGNORED",
|
||||
/* 2005 */ "RETURN REGISTER FOR %t REDEFINED",
|
||||
/* 2006 */ "%q DELETED",
|
||||
/* 2007 */ "SYNTAX ERROR. PARSE SO FAR: ",
|
||||
/* 2008 */ " %q",
|
||||
/* 2009 */ "ALIGNMENT FACTORS MUST INCREASE",
|
||||
/* 2010 */ " _ ",
|
||||
/* 2011 */ " %t",
|
||||
/* 2012 */ "DELETED: ",
|
||||
/* 2013 */ "SKIPPED: ",
|
||||
/* 2014 */ "MISSING SAVEAREASIZE STATEMENT",
|
||||
/* 2015 */ "SIZE OF %t REDECLARED",
|
||||
/* 2016 */ "SIZE OF %t NOT SPECIFIED",
|
||||
/* 2017 */ "MACRO %t REDEFINED",
|
||||
/* 2018 */ "ATTEMPT TO MIX REGISTER AND MEMORY IN LOCATION EXPRESSION",
|
||||
/* 2019 */ 0,
|
||||
/* 2020 */ "ALIGNMENT OF TYPE %t REDECLARED",
|
||||
/* 2021 */ "INVALID ALIGMENT CLASS %d",
|
||||
/* 2022 */ "NO POINTER CLASS CAN RESOLVE TYPE %t",
|
||||
/* 2023 */ "ALIGNMENT CLASS FOR %t NOT SPECIFIED",
|
||||
/* 2024 */ "SMALLEST ALIGNMENT FACTOR MUST BE 1",
|
||||
/* 2025 */ 0,
|
||||
/* 2026 */ "UNDEFINED POINTER CLASS %t",
|
||||
/* 2027 */ "UNDEFINED REGISTER %t",
|
||||
/* 2028 */ "UNDEFINED DATA TYPE %t",
|
||||
/* 2029 */ "UNDEFINED MEMORY REFERENCE TYPE %t"
|
||||
};
|
||||
|
||||
char *m4000[] {
|
||||
/* 4000 */ "NAME TABLE OVERFLOW",
|
||||
/* 4001 */ "NAME TABLE OVERFLOW",
|
||||
/* 4002 */ "MACRO DEFINITION OVERFLOW",
|
||||
/* 4003 */ "PROGRAM TOO COMPLICATED. PARSER STACK OVERFLOW.",
|
||||
/* 4004 */ "MANIFEST CONSTANT DEFINITION TABLE OVERFLOW",
|
||||
/* 4005 */ "PROGRAM TOO LARGE: SYMBOL TABLE OVERFLOW",
|
||||
/* 4006 */ "TOO MANY NAMED MACROS",
|
||||
/* 4007 */ 0,
|
||||
/* 4008 */ 0,
|
||||
/* 4009 */ 0,
|
||||
/* 4010 */ 0,
|
||||
/* 4011 */ 0,
|
||||
/* 4012 */ "I GIVE UP",
|
||||
/* 4013 */ "TYPENAMES STATEMENT MISSING",
|
||||
/* 4014 */ "REGNAMES STATEMENT MISSING",
|
||||
/* 4015 */ "MEMNAMES STATEMENT MISSING",
|
||||
/* 4016 */ "TOO MANY POINTER CLASSES",
|
||||
/* 4017 */ "TOO MANY REGISTERS",
|
||||
/* 4018 */ "TOO MANY REGISTER CLASSES",
|
||||
/* 4019 */ "TOO MANY DATA TYPES",
|
||||
/* 4020 */ "TOO MANY MEMORY REFERENCE TYPES",
|
||||
/* 4021 */ "POINTER STATEMENT MISSING",
|
||||
/* 4022 */ "TYPE STATEMENT MISSING",
|
||||
/* 4023 */ "OPLOC STATEMENTS MISSING",
|
||||
/* 4024 */ "MACROS MISSING",
|
||||
/* 4025 */ "RETURNREG STATEMENT MISSING"
|
||||
};
|
||||
|
||||
char *m6000[] {
|
||||
/* 6000 */ "T(P): ATTEMPT TO REFERENCE TOKEN %d",
|
||||
/* 6001 */ "POP(P): STACK ERROR",
|
||||
/* 6002 */ "LEX(P): TOKEN BUFFER OVERFLOW",
|
||||
/* 6003 */ "SETSP(P): STACK POINTER TOO SMALL",
|
||||
/* 6004 */ "SETSP(P): STACK POINTER TOO LARGE",
|
||||
/* 6005 */ "LEX(P): INCONSISTENT TOKEN POINTERS",
|
||||
/* 6006 */ "PARSE(P): ATTEMPT TO POP EMPTY PARSER STACK"
|
||||
};
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
DTOKEN - Print Token
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
dtoken (type, index)
|
||||
|
||||
{extern int cout;
|
||||
ptoken (&type, cout);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
EPRINT - Error Editor Formatted Print Routine
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
eprint (fmt, x1, x2) char *fmt;
|
||||
|
||||
{int *argp, x, c;
|
||||
char *s;
|
||||
|
||||
argp = &x1; /* argument pointer */
|
||||
while (c = *fmt++)
|
||||
{if (c != '%') eputc (c);
|
||||
else
|
||||
{x = *argp++;
|
||||
switch (c = *fmt++) {
|
||||
|
||||
case 'd': /* decimal */ if (x<0) {x = -x; eputc ('-');}
|
||||
eprd (x);
|
||||
break;
|
||||
case 'q': /* parser state */
|
||||
x = sq[x];
|
||||
if (x<0) break;
|
||||
if (x<010000) eprint ("%s", sterm[x]);
|
||||
else eprint ("<%s>", snterm[x-010000]);
|
||||
break;
|
||||
case 's': /* string */ s = x;
|
||||
while (c = *s++) eputc (c);
|
||||
break;
|
||||
case 't': /* token */ dtoken (x, *argp++);
|
||||
break;
|
||||
default: eputc (c);
|
||||
--argp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
EPRD - Print Positive Decimal Integer
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
eprd (n)
|
||||
|
||||
{int a;
|
||||
if (a=n/10) eprd (a);
|
||||
eputc (n%10+'0');
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
EPUTC - Write a character onto standard output unit.
|
||||
|
||||
Break lines which exceed 60 characters.
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
eputc (c)
|
||||
|
||||
{static int column;
|
||||
extern int cout;
|
||||
|
||||
if (column >= 59 && c == ' ') c = '\n';
|
||||
else if (column >= 80 && c != '\n')
|
||||
{cputc ('\n', cout); column = 0;
|
||||
}
|
||||
cputc (c, cout);
|
||||
if (c=='\n') column=0; else ++column;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
ERROR - Print Error Message
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
error (errno, lineno, p1, p2)
|
||||
|
||||
{char *f, *getfmt();
|
||||
|
||||
if (lineno>0) eprint ("\n%d: ", lineno);
|
||||
if (errno>=6000) eprint ("COMPILER ERROR. ");
|
||||
|
||||
if (errno < 2000)
|
||||
f = getfmt (errno-1000, m1000, sizeof m1000);
|
||||
else if (errno < 4000)
|
||||
f = getfmt (errno-2000, m2000, sizeof m2000);
|
||||
else if (errno < 6000)
|
||||
f = getfmt (errno-4000, m4000, sizeof m4000);
|
||||
else f = getfmt (errno-6000, m6000, sizeof m6000);
|
||||
|
||||
if (f==0) {f = "ERROR %d"; p1=errno;}
|
||||
eprint (f, p1, p2);
|
||||
if (errno>=4000) cleanup (1);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
|
||||
GETFMT - get format given
|
||||
N - relative error number
|
||||
T - error message table
|
||||
Z - size of error message table
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
char *getfmt (n, t, z)
|
||||
char *t[];
|
||||
|
||||
{int nm;
|
||||
|
||||
nm = z / sizeof t[0];
|
||||
if (n < 0 || n >= nm) return (0);
|
||||
return (t[n]);
|
||||
}
|
||||
|
||||
BIN
c20/gt/get.ctl
Normal file
BIN
c20/gt/get.ctl
Normal file
Binary file not shown.
7
c20/gt/gt.cmac
Normal file
7
c20/gt/gt.cmac
Normal file
@@ -0,0 +1,7 @@
|
||||
:MM G0 CREL _ G0 CMAC
|
||||
:MM G1 CREL _ G1 CMAC
|
||||
:MM G2 CREL _ G2 CMAC
|
||||
:MM G3 CREL _ G3 CMAC
|
||||
:MM G4 CREL _ G4 CMAC
|
||||
:MM G5 CREL _ G5 CMAC
|
||||
|
||||
152
c20/gt/gt.h
Normal file
152
c20/gt/gt.h
Normal file
@@ -0,0 +1,152 @@
|
||||
/* dependencies upon host machine !! */
|
||||
|
||||
# define WORDMASK 077777777777 /* mask all but high 3 bits */
|
||||
# define SMALLEST "-34359738368" /* smallest negative number */
|
||||
|
||||
/* table sizes */
|
||||
|
||||
# define hshsize 200 /* size of hash table for identifiers */
|
||||
# define cssiz 5000 /* size of character store */
|
||||
# define pssize 100 /* size of action routine stack */
|
||||
# define mcdsz 200 /* manifest constant definition table size */
|
||||
# define eopchsz 0300
|
||||
|
||||
/* various values */
|
||||
|
||||
# define MREAD 'r' /* read mode */
|
||||
# define MWRITE 'w' /* write mode */
|
||||
# define MAPPEND 'a' /* append mode */
|
||||
# define TEXT "t" /* text file */
|
||||
# define BINARY "b" /* binary file */
|
||||
|
||||
# define TRUE 1
|
||||
# define FALSE 0
|
||||
# define NULL 0
|
||||
# define UNDEF -1
|
||||
# define OPENLOSS -1
|
||||
|
||||
/* token types */
|
||||
|
||||
# define LEXEOF 0 /* internal end of file indicator */
|
||||
# define TEOF 1 /* end of file */
|
||||
# define _SEMI 3
|
||||
# define _LPARN 4
|
||||
# define _RPARN 5
|
||||
# define _LBRAK 6
|
||||
# define _RBRAK 7
|
||||
# define _COLON 8
|
||||
# define _COMMA 9
|
||||
# define _OR 10
|
||||
# define _NOT 11
|
||||
# define T_AMOP 12 /* abstract machine operator */
|
||||
# define _TYPENAMES 13
|
||||
# define _ALIGN 14
|
||||
# define _POINTER 15
|
||||
# define _CLASS 16
|
||||
# define _CONFLICT 17
|
||||
# define _TYPE 18
|
||||
# define _MEMNAMES 19
|
||||
# define _MACROS 20
|
||||
# define _SIZE 21
|
||||
# define _INDIRECT 22
|
||||
# define _REGNAMES 23
|
||||
# define _RETURNREG 24
|
||||
# define _SAVEAREASIZE 25
|
||||
# define _OFFSETRANGE 26
|
||||
# define _M 27
|
||||
# define TIDN 28 /* identifiers */
|
||||
# define TINTCON 29 /* integer constants */
|
||||
# define TSTRING 30 /* string constants */
|
||||
|
||||
/* location expression modes */
|
||||
|
||||
# define l_unknown 0
|
||||
# define l_register 1
|
||||
# define l_memory 2
|
||||
|
||||
/* basic data types */
|
||||
|
||||
# define tchar 0 /* character */
|
||||
# define tint 1 /* integer */
|
||||
# define tfloat 2 /* float */
|
||||
# define tdouble 3 /* double */
|
||||
|
||||
/* storage classes */
|
||||
|
||||
# define c_register 0 /* register */
|
||||
# define c_temp 1 /* temporary */
|
||||
# define c_auto 1 /* automatic */
|
||||
# define c_extdef 2 /* external definition */
|
||||
# define c_static 3 /* static */
|
||||
# define c_param 4 /* parameter */
|
||||
# define c_label 5 /* label */
|
||||
# define c_integer 6 /* integer literal */
|
||||
# define c_float 7 /* floating-point literal */
|
||||
# define c_string 8 /* string literal */
|
||||
# define c_indirect 9 /* indirection through reg #0 ... */
|
||||
# define c_extern 50 /* external */
|
||||
# define c_struct 51 /* structure type */
|
||||
# define c_mos 52 /* member of structure */
|
||||
# define c_dummy 53 /* dummy structure def -
|
||||
for recursive definitions */
|
||||
|
||||
/* enodes */
|
||||
|
||||
# define e_iminus 0000
|
||||
# define e_dminus 0001
|
||||
# define e_incbi 0002
|
||||
# define e_bnot 0006
|
||||
# define e_not 0007
|
||||
# define e_sw 0012
|
||||
# define e_incbc 0013
|
||||
# define e_a0 0017
|
||||
# define e_a3 0022
|
||||
# define e_ind 0023
|
||||
# define e_jz0 0024
|
||||
# define e_jz3 0027
|
||||
# define e_jn0 0030
|
||||
# define e_jn3 0033
|
||||
# define e_addi 0100
|
||||
# define e_eaddi 0101
|
||||
# define e_subi 0104
|
||||
# define e_esubi 0105
|
||||
# define e_muli 0110
|
||||
# define e_divi 0114
|
||||
# define e_mod 0120
|
||||
# define e_ls 0122
|
||||
# define e_els 0123
|
||||
# define e_rs 0124
|
||||
# define e_ers 0125
|
||||
# define e_band 0126
|
||||
# define e_eand 0127
|
||||
# define e_xor 0130
|
||||
# define e_exor 0131
|
||||
# define e_bor 0132
|
||||
# define e_eor 0133
|
||||
# define e_and 0134
|
||||
# define e_or 0135
|
||||
# define e_p0sub 0136
|
||||
# define e_assign 0137
|
||||
# define e_add0 0146
|
||||
# define e_add3 0151
|
||||
# define e_sub0 0152
|
||||
# define e_sub3 0155
|
||||
# define e_movec 0160
|
||||
# define e_idn 0177
|
||||
# define e_int 0176
|
||||
# define e_string 0175
|
||||
# define e_float 0174
|
||||
# define e_call 0173
|
||||
# define e_colon 0172
|
||||
# define e_qmark 0171
|
||||
# define e_eqi 0200
|
||||
# define e_eqd 0206
|
||||
# define e_eqp0 0214
|
||||
# define e_gep3 0243
|
||||
# define e_incb0 0260
|
||||
|
||||
/* STRUCTURES */
|
||||
|
||||
struct _token {int type,index,line;};
|
||||
# define token struct _token
|
||||
|
||||
BIN
c20/gt/gt.stinkr
Normal file
BIN
c20/gt/gt.stinkr
Normal file
Binary file not shown.
282
c20/gt/h6000.gt
Normal file
282
c20/gt/h6000.gt
Normal file
@@ -0,0 +1,282 @@
|
||||
typenames (char,int,float,double);
|
||||
memnames (reg,auto,ext,stat,param,label,intlit,floatlit,string,
|
||||
ix0,ix1,ix2,ix3,ix4,ia,iq);
|
||||
regnames (x0,x1,x2,x3,x4,a,q,f);
|
||||
size 1(char),4(int,float),8(double);
|
||||
align 1(char),4(int,float),8(double);
|
||||
class x(x0,x1,x2,x3,x4), r(a,q);
|
||||
conflict (a,f),(q,f);
|
||||
saveareasize 16;
|
||||
pointer p0(1), p1(4);
|
||||
offsetrange p1 (,);
|
||||
returnreg q(char,int,p0,p1), f(double);
|
||||
type int(r), char(r), float(f), double(f), p0(r), p1(x);
|
||||
|
||||
.sw: a,,1[x4];
|
||||
+p0: -p0: +i:-i:&:^: .OR: -p0p0:<<: >>: r,M,1;
|
||||
+p1: M,M,x; x,r,1; x,intlit,1;
|
||||
-p1: x,r,1; x,intlit,1;
|
||||
=+i: =&: =^: =OR: M,r,1;
|
||||
*i: /i: q,M,q[a];
|
||||
+d: -d: *d: /d: f,M,f;
|
||||
%: q,M,a[q];
|
||||
=<<: =>>: M,a,q; M,q,a;
|
||||
&u0: auto|ext|stat|string|ia|iq,,r;
|
||||
&u1: M,,x;
|
||||
.BNOT: .ic: .ci: r,,1;
|
||||
-ui: M,,r;
|
||||
.cf: .cd: .if: .id: a,,f;
|
||||
.fc: .dc: .fi: .di: f,,q;
|
||||
.fd: M,,f;
|
||||
.df: -ud: f,,1;
|
||||
.ip0: .p0i: r,,1; M,,r;
|
||||
.ip1: .p0p1: r,,x; M,,x;
|
||||
.p1i: .p1p0: x,,r; M,,r;
|
||||
++bi: M,,1;
|
||||
++ai: M,,a[q];
|
||||
M,,q[a];
|
||||
++ap1: --ap1: M,M,x;
|
||||
==i: !=i: <i: >i: <=i: >=i:
|
||||
==p0: !=p0: <p0: >p0: <=p0: >=p0: r,M,M;
|
||||
==d: !=d: <d: >d: <=d: >=d: f,M,M;
|
||||
==p1: !=p1: <p1: >p1: <=p1: >=p1: x,M,M;
|
||||
|
||||
macros
|
||||
|
||||
+i: " AD#R #S"
|
||||
-i: " SB#R #S"
|
||||
*i: " MPY #S"
|
||||
/i: %: " DIV #S"
|
||||
+d: " DFAD #S"
|
||||
-d: " DFSB #S"
|
||||
*d: " DFMP #S"
|
||||
/d: " DFDV #S"
|
||||
=+i: " AS#S #R"
|
||||
&: " AN#F #S"
|
||||
=&: " ANS#S #F"
|
||||
^: " ER#F #S"
|
||||
=^: " ERS#S #F"
|
||||
.OR: " OR#F #S"
|
||||
=OR: " ORS#S #F"
|
||||
|
||||
>>:
|
||||
(,intlit,): " #FRS %o(#'S)"
|
||||
(,~intlit,): " LXL5 #S\n #FRS 0,5"
|
||||
|
||||
<<:
|
||||
(,intlit,): " #FLS %o(#'S)"
|
||||
(,~intlit,): " LXL5 #S\n #FLS 0,5"
|
||||
|
||||
=>>:
|
||||
" LD#R #F
|
||||
#RRS 0,#SL
|
||||
ST#R #F"
|
||||
|
||||
=<<:
|
||||
" LD#R #F
|
||||
#RLS 0,#SL
|
||||
ST#R #F"
|
||||
|
||||
+p0:
|
||||
(,~intlit,): " #FRS 16\n AD#F #S\n #FLS 16"
|
||||
(,intlit,): " ADL#R %co(#'S)"
|
||||
|
||||
-p0:
|
||||
(,~intlit,): " #FRS 16\n SB#F #S\n #FLS 16"
|
||||
(,intlit,): " SBL#R %co(#'S)"
|
||||
|
||||
+p1:
|
||||
(M,M,): " LXL#R #S\n ADLX#R #F"
|
||||
(x,r,): " #SLS 18\n ST#S .TEMP\n ADX#F .TEMP"
|
||||
(x,intlit,): " EAX#R %o(#'S),#R"
|
||||
|
||||
-p1:
|
||||
(,r,): " #SLS 18\n ST#S .TEMP\n SBX#F .TEMP"
|
||||
(,intlit,): " EAX#R -%o(#'S),#R"
|
||||
|
||||
-ui: " LC#R #F"
|
||||
-ud: " FNEG"
|
||||
++bi: " AOS #F"
|
||||
++ai: " LD#R #F\n AOS #F"
|
||||
|
||||
++ap1:
|
||||
" LDX#R #F
|
||||
EAX5 %o(#'S),#1
|
||||
STX5 #F"
|
||||
|
||||
--ap1:
|
||||
" LDX#R #F
|
||||
EAX5 -%o(#'S),#1
|
||||
STX5 #F"
|
||||
|
||||
.BNOT: " ER#F =-1"
|
||||
&u0:
|
||||
(ia|iq,,r):
|
||||
"%if(%o(#'F), AD#F %co(#'F)\n,)\"
|
||||
(ia,,q): " LLR 36"
|
||||
(iq,,a): " LLR 36"
|
||||
(auto|stat,,r):
|
||||
" EA#R %n(#3,0)
|
||||
%if(%o(#'F), AD#R %co(#'F)\n,)\"
|
||||
(ext|string,,r):
|
||||
" EA#R #F"
|
||||
|
||||
&u1: " EAX#R #F"
|
||||
|
||||
==i: " CMP#F #S\n TZE #R"
|
||||
!=i: " CMP#F #S\n TNZ #R"
|
||||
<i: " CMP#F #S\n TMI #R"
|
||||
>i: " CMP#F #S\n TZE *+2\n TPL #R"
|
||||
<=i: " CMP#F #S\n TZE #R\n TMI #R"
|
||||
>=i: " CMP#F #S\n TPL #R"
|
||||
|
||||
==d: " DFCMP #S\n TZE #R"
|
||||
!=d: " DFCMP #S\n TNZ #R"
|
||||
<d: " DFCMP #S\n TMI #R"
|
||||
>d: " DFCMP #S\n TZE *+2\n TPL #R"
|
||||
<=d: " DFCMP #S\n TZE #R\n TMI #R"
|
||||
>=d: " DFCMP #S\n TPL #R"
|
||||
|
||||
==p0: " CMP#F #S\n TZE #R"
|
||||
!=p0: " CMP#F #S\n TNZ #R"
|
||||
<p0: " CMP#F #S\n TZE *+2\n TNC #R"
|
||||
>p0: " CMP#F #S\n TZE *+2\n TRC #R"
|
||||
<=p0: " CMP#F #S\n TZE #R\n TNC #R"
|
||||
>=p0: " CMP#F #S\n TRC #R"
|
||||
|
||||
==p1: " CMPX#F #S\n TZE #R"
|
||||
!=p1: " CMPX#F #S\n TNZ #R"
|
||||
<p1: " CMPX#F #S\n TZE *+2\n TNC #R"
|
||||
>p1: " CMPX#F #S\n TZE *+2\n TRC #R"
|
||||
<=p1: " CMPX#F #S\n TZE #R\n TNC #R"
|
||||
>=p1: " CMPX#F #S\n TRC #R"
|
||||
|
||||
-p0p0: " SBL#F #S\n #FRL 16"
|
||||
|
||||
.cc:
|
||||
(auto,,): " EA#R 0,7\n"
|
||||
(stat,,): " EA#R .STAT\n"
|
||||
(ia,,q): " STA .TEMP\n LDQ .TEMP\n"
|
||||
(iq,,a): " STQ .TEMP\n LDA .TEMP\n"
|
||||
(auto|stat|indirect,,):
|
||||
"%if(%o(#'F), AD#R %co(#'F)\n,)\
|
||||
TSX5 .CTO#R"
|
||||
(ext|string,,): " LD#R #F\n #RRL 27"
|
||||
(r,,r): " EA#R 0,#FL\n #RRL 18"
|
||||
(r,,auto|stat|indirect|string):
|
||||
" EAX5 0,#FL\n"
|
||||
(r,,auto): " EA#F 0,7\n"
|
||||
(r,,stat): " EA#F .STAT\n"
|
||||
(r,,auto|stat):
|
||||
"%if(%o(#'R), AD#F %co(#'R)\n,)\
|
||||
TSX4 .#FTOC"
|
||||
(r,,string): " EA#F #R\n TSX4 .#FTOC"
|
||||
(r,,ext): " #FLS 27\n ST#F #R\n #FRL 27"
|
||||
(q,,ia):
|
||||
"%if(%o(#'R), ADA %co(#'R)\n,)\
|
||||
TSX4 .ATOC"
|
||||
(a,,iq):
|
||||
"%if(%o(#'R), ADQ %co(#'R)\n,)\
|
||||
TSX4 .QTOC"
|
||||
.ii:
|
||||
(r,,M): " ST#F #R"
|
||||
(M,,r): " LD#R #F"
|
||||
(r,,r): " LLR 36"
|
||||
.ff:
|
||||
(f,,M): " FSTR #R"
|
||||
(M,,f): " FLD #F"
|
||||
.dd:
|
||||
(f,,M): " DPSTR #R"
|
||||
(M,,f): " DPLD #F"
|
||||
.p0p0:
|
||||
(r,,r): " LLR 36"
|
||||
(r,,M): " ST#F #R"
|
||||
(M,,r): " LD#R #F"
|
||||
.p1p1:
|
||||
(x,,x): " EAX#R 0,#F"
|
||||
(x,,M): " STZ #R\n STX#F #R"
|
||||
(M,,x): " LDX#R #F"
|
||||
(x,,q): " EAQ 0,#F"
|
||||
(q,,x): " EAX#R 0,QU"
|
||||
(M,,q): " LDQ #F"
|
||||
(q,,M): " STQ #R"
|
||||
|
||||
.ci: "\"
|
||||
.ic: " AN#F =O377,DL"
|
||||
|
||||
.p0p1: .ip1:
|
||||
(r,,x): " EAX#R 0,#FU"
|
||||
(M,,x): " LDX#R #F"
|
||||
|
||||
.p1p0: .p1i:
|
||||
(x,,r): " EA#R 0,#F"
|
||||
(M,,r): " LD#R #F"
|
||||
|
||||
.ip0: .p0i:
|
||||
(M,,r): " LD#R #F"
|
||||
(r,,r): "\"
|
||||
|
||||
.fd: " FLD #F"
|
||||
.df: " FRD"
|
||||
|
||||
.cf: .cd: .if: .id:
|
||||
" LDQ 0,DL
|
||||
LDE =35B25,DU
|
||||
FNO"
|
||||
|
||||
.fi: .di: " UFA =71B25,DU"
|
||||
.fc: .dc:
|
||||
" UFA =71B25,DU
|
||||
ANQ =O377,DL"
|
||||
|
||||
hd:
|
||||
"$ GMAP
|
||||
SYMREF .PROLG,.EPILG,.TEMP,.LSIWT,.TSWIT
|
||||
SYMREF .CTOA,.CTOQ,.ATOC,.QTOC"
|
||||
|
||||
en: " SYMDEF #0"
|
||||
ex: " SYMREF #0"
|
||||
st: ".I#0 EQU *"
|
||||
rt: " TRA .EPILG"
|
||||
go: " TRA #R"
|
||||
l: ".L#0 EQU *"
|
||||
lc: " ZERO .L#0"
|
||||
|
||||
p:
|
||||
"*
|
||||
* FUNCTION %m(#1)
|
||||
*
|
||||
%i(#1) TSX0 .PROLG
|
||||
ZERO .FS#0"
|
||||
ca:
|
||||
" TSX1 #F
|
||||
ZERO #1/4,#0"
|
||||
ep:
|
||||
" TRA .EPILG
|
||||
.FS#0 EQU #1/4"
|
||||
|
||||
ls:
|
||||
" TSX5 .LSWIT
|
||||
ZERO #R,#0"
|
||||
ts:
|
||||
" TSX5 .TSWIT
|
||||
ZERO #0,#5
|
||||
TRA #R"
|
||||
|
||||
o: "#1"
|
||||
co: "=V20/#1,16/0"
|
||||
|
||||
ln: "%flush().N#0 EQU *"
|
||||
eq: "%flush()#0 EQU *"
|
||||
in: "%flush() DEC #0"
|
||||
ad0: ad1: "%flush() ZERO #R"
|
||||
sc: "%flush() ZERO .S#0"
|
||||
end: "%flush() END"
|
||||
f: "%flush() DEC %ff(#0)"
|
||||
nf: "%flush() DEC -%ff(#0)"
|
||||
d: "%flush() DEC %dd(#0)"
|
||||
nd: "%flush() DEC -%dd(#0)"
|
||||
al1: "%flush()\"
|
||||
al2: "%flush() EVEN"
|
||||
im: da: pu: pd: "\"
|
||||
|
||||
234
c20/gt/pdp10.gt
Normal file
234
c20/gt/pdp10.gt
Normal file
@@ -0,0 +1,234 @@
|
||||
typenames (char, int, float, double);
|
||||
regnames (a, c, d, b);
|
||||
memnames (reg, auto, ext, stat, param, label, intlit, floatlit,
|
||||
stringlit, ia, ic, id, ib);
|
||||
size 1 (char, int, float, double);
|
||||
align 1(char, int, float, double);
|
||||
class r (a, b, c, d);
|
||||
saveareasize 1;
|
||||
pointer p0 (1);
|
||||
offsetrange p0 (,);
|
||||
returnreg a (int, double, p0);
|
||||
type char(r), int(r), float(r), double(r), p0(r);
|
||||
|
||||
.sw: a|c|d,,1[b];
|
||||
.argi: .argd: .arg0: r,,1; M,,1;
|
||||
|
||||
+i: *i: &: ^: .OR: +p0:
|
||||
+d: *d: r,r,1; r,M,1; M,r,2;
|
||||
|
||||
-i: -p0: -p0p0: -d: /d: r,r,1; r,M,1;
|
||||
|
||||
/i: a,r,1[b]; b,r,1[c]; c,r,1[d];
|
||||
a,M,1[b]; b,M,1[c]; c,M,1[d];
|
||||
|
||||
%: a,r,b; b,r,c; c,r,d;
|
||||
a,M,b; b,M,c; c,M,d;
|
||||
|
||||
<<: >>: r,r,1; r,intlit,1;
|
||||
|
||||
=+i: =*i: =&: =^: =OR:
|
||||
=+d: =*d: M,r,1; M,r,2;
|
||||
|
||||
.BNOT: -ui: -ud: r,,1; M,,r;
|
||||
|
||||
&u0:
|
||||
++ai: ++ac: --ai: --ac: M,,r;
|
||||
|
||||
++ap0: --ap0: M,b,a|c|d; M,d,b;
|
||||
|
||||
++bi: ++bc:
|
||||
--bi: --bc: M,,r; M,,1;
|
||||
|
||||
++bp0: --bp0: M,r,2;
|
||||
|
||||
.ic: .ci: .ip0: .p0i: .df: .fd:
|
||||
.cf: .cd: .if: .id: r,,1;
|
||||
|
||||
.fc: .dc: .fi: .di: a,,b;
|
||||
|
||||
==p0: !=p0: <p0: >p0: <=p0: >=p0:
|
||||
==i: !=i: <i: >i: <=i: >=i:
|
||||
==d: !=d: <d: >d: <=d: >=d: r,r,label; r,M,label;
|
||||
|
||||
==0p0: !=0p0: r,,label; M,,label;
|
||||
|
||||
|
||||
|
||||
|
||||
macros
|
||||
|
||||
+i: *i: &: ^: .OR: +p0:
|
||||
|
||||
(r,r,): " #O #F,#S"
|
||||
(M,,): " #O #S,#F"
|
||||
(r,~intlit,): " #O #F,#S"
|
||||
(r,intlit,): " #O%ifm(#'S,I #F\,#6, #F\,#S)"
|
||||
|
||||
-i: /i: %: -p0: sb:
|
||||
|
||||
(,r,): " #O #F,#S"
|
||||
(,~intlit,): " #O #F,#S"
|
||||
(,intlit,): " #O%ifm(#'S,I #F\,#6, #F\,#S)"
|
||||
|
||||
+d: *d:
|
||||
|
||||
(r,,): " #O #F,#S"
|
||||
(M,,): " #O #S,#F"
|
||||
|
||||
-d: /d: -p0p0:
|
||||
|
||||
" #O #F,#S"
|
||||
|
||||
<<:
|
||||
(,intlit,): " LSH #R,#6"
|
||||
(,r,): " LSH #R,(#S)"
|
||||
>>:
|
||||
(,intlit,): " LSH #R,-#6"
|
||||
(,r,): " MOVN #S,#S\n LSH #R,(#S)"
|
||||
|
||||
=+i: " ADDB #S,#F"
|
||||
=*i: " IMULB #S,#F"
|
||||
=&: " ANDB #S,#F"
|
||||
=^: " XORB #S,#F"
|
||||
=OR: " IORB #S,#F"
|
||||
=+d: " FADRB #S,#F"
|
||||
=*d: " FMPRB #S,#F"
|
||||
|
||||
&u0: " MOVEI #R,#F"
|
||||
++ai: ++ac: " MOVE #R,#F\n AOS #F"
|
||||
--ai: --ac: " MOVE #R,#F\n SOS #F"
|
||||
++bi: ++bc:
|
||||
(,,r): " MOVEI #R,1\n ADDB #R,#F"
|
||||
(,,M): " AOS #F"
|
||||
--bi: --bc:
|
||||
(,,r): " SETO #R,\n ADDB #R,#F"
|
||||
(,,M): " SOS #F"
|
||||
++ap0: " MOVE #R,#F\n ADDM #S,#F"
|
||||
--ap0: " MOVE #R,#F\n MOVN #S,#S\n ADDM #S,#F"
|
||||
++bp0: " ADDB #S,#F"
|
||||
--bp0: " MOVN #S,#S\n ADDB #S,#F"
|
||||
.BNOT:
|
||||
(r,,): " SETCA #R,"
|
||||
(M,,): " SETCM #R,#F"
|
||||
-ui: -ud: " MOVN #R,#F"
|
||||
|
||||
==p0: " CAMN #F,#S\n GO #R"
|
||||
!=p0: " CAME #F,#S\n GO #R"
|
||||
<p0: " CAMGE #F,#S\n GO #R"
|
||||
>p0: " CAMLE #F,#S\n GO #R"
|
||||
<=p0: " CAMG #F,#S\n GO #R"
|
||||
>=p0: " CAML #F,#S\n GO #R"
|
||||
|
||||
==i: "%ifm(#'S,%if(#6,\tCAIN\t#F\,#6\n\tGO\t#R,\tJUMPE\t#F\,#R),\tCAMN\t#F\,#S\n\tGO\t#R)"
|
||||
!=i: "%ifm(#'S,%if(#6,\tCAIE\t#F\,#6\n\tGO\t#R,\tJUMPN\t#F\,#R),\tCAME\t#F\,#S\n\tGO\t#R)"
|
||||
<i: "%ifm(#'S,%if(#6,\tCAIGE\t#F\,#6\n\tGO\t#R,\tJUMPL\t#F\,#R),\tCAMGE\t#F\,#S\n\tGO\t#R)"
|
||||
>i: "%ifm(#'S,%if(#6,\tCAILE\t#F\,#6\n\tGO\t#R,\tJUMPG\t#F\,#R),\tCAMLE\t#F\,#S\n\tGO\t#R)"
|
||||
<=i: "%ifm(#'S,%if(#6,\tCAIG\t#F\,#6\n\tGO\t#R,\tJUMPLE\t#F\,#R),\tCAMG\t#F\,#S\n\tGO\t#R)"
|
||||
>=i: "%ifm(#'S,%if(#6,\tCAIL\t#F\,#6\n\tGO\t#R,\tJUMPGE\t#F\,#R),\tCAML\t#F\,#S\n\tGO\t#R)"
|
||||
|
||||
==d: " FSBR #F,#S\n JUMPE #F,#R"
|
||||
!=d: " FSBR #F,#S\n JUMPN #F,#R"
|
||||
<d: " FSBR #F,#S\n JUMPL #F,#R"
|
||||
>d: " FSBR #F,#S\n JUMPG #F,#R"
|
||||
<=d: " FSBR #F,#S\n JUMPLE #F,#R"
|
||||
>=d: " FSBR #F,#S\n JUMPGE #F,#R"
|
||||
|
||||
==0p0:
|
||||
(M,,): " SKIPN #F\n GO #R"
|
||||
(r,,): " JUMPE #F,#R"
|
||||
!=0p0:
|
||||
(M,,): " SKIPE #F\n GO #R"
|
||||
(r,,): " JUMPN #F,#R"
|
||||
|
||||
.cc: .ii:
|
||||
.ff: .dd:
|
||||
.p0p0:
|
||||
(r,,r): " MOVE #R,#F"
|
||||
(r,,M): " MOVEM #F,#R"
|
||||
(~intlit,,r): " MOVE #R,#F"
|
||||
(intlit,,r): " %ifm(#'F,MOVEI\t#R\,#4,%ifm(#3,-#4,MOVNI\t#R\,-#4,MOVE\t#R\,#F))"
|
||||
|
||||
.if: .id:
|
||||
.cf: .cd: " FSC #R,155"
|
||||
.di: .dc:
|
||||
.fi: .fc: " JSP 0,FIXIFY"""
|
||||
.ic: .ci:
|
||||
.ip0: .p0i:
|
||||
.df: .fd: "\"
|
||||
|
||||
.argi:
|
||||
.argd:
|
||||
.arg0: " PPUSH #F"
|
||||
|
||||
in: c: " #0"
|
||||
ad0: " #R"
|
||||
|
||||
al: "\"
|
||||
ca: " CCALL #0,#F"
|
||||
|
||||
end:
|
||||
".PDATA
|
||||
CONSTANTS
|
||||
END"
|
||||
|
||||
en: " ENTRY #0"
|
||||
ex: " EXTERN #0"
|
||||
eq: "#0:"
|
||||
go: " GO #R"
|
||||
hd:
|
||||
|
||||
" TITLE %pname()
|
||||
RADIX 10.
|
||||
.INSRT C;NC INSERT
|
||||
"
|
||||
|
||||
ln: "\n; LINE #0\n"
|
||||
p:
|
||||
|
||||
"%setfno(#0)
|
||||
\%A==#2
|
||||
\%A,,[ASCIZ/%m(#1)/]
|
||||
%i(#1): ADDI P,FS#0"
|
||||
|
||||
rt:
|
||||
" SUBI P,FS#0+\%A+1
|
||||
GO @<\%A+1>(P)"
|
||||
ep:
|
||||
" SUBI P,FS#0+\%A+1
|
||||
GO @<\%A+1>(P)
|
||||
FS#0==#1-1"
|
||||
|
||||
st: "I#0:"
|
||||
z: " BLOCK #0"
|
||||
|
||||
f: d: " %ff(#0)"
|
||||
nf: nd: " -%ff(#0)"
|
||||
|
||||
ts:
|
||||
"%if(#0,%sb(68,#'F,#'F,-6,#0)
|
||||
,) JUMPL #F,#R
|
||||
CAILE #F,#5-#0
|
||||
GO #R
|
||||
GO @(#F)["
|
||||
|
||||
ets: " ]"
|
||||
|
||||
ls:
|
||||
" MOVE B,[-#0,,["
|
||||
|
||||
els:
|
||||
" ]]
|
||||
CAMN #F,(B)
|
||||
GO @#0(B)
|
||||
AOBJN B,.-2
|
||||
GO #R"
|
||||
|
||||
lc: " L#0"
|
||||
l: "L#0:"
|
||||
sc: " S#0"
|
||||
pu: ".CODE"
|
||||
pd: ".PDATA"
|
||||
im: ".UDATA"
|
||||
da: ".IDATA"
|
||||
|
||||
429
c20/gt/pdp10.gtout
Normal file
429
c20/gt/pdp10.gtout
Normal file
@@ -0,0 +1,429 @@
|
||||
/* class r 1111 */
|
||||
/* conflict a 0000 */
|
||||
/* conflict c 0000 */
|
||||
/* conflict d 0000 */
|
||||
/* conflict b 0000 */
|
||||
int ofok1(i) {return (1);}
|
||||
/* type char 1111 */
|
||||
/* type int 1111 */
|
||||
/* type float 1111 */
|
||||
/* type double 1111 */
|
||||
/* pointer class p0 1111 */
|
||||
|
||||
int (*off_ok[])() {ofok1};
|
||||
|
||||
int tsize[4] {
|
||||
1,1,1,1};
|
||||
int talign[4] {
|
||||
0,0,0,0};
|
||||
int calign[1] {
|
||||
1};
|
||||
int retreg[7] {
|
||||
-1,-1,-1,0,-1,0,0};
|
||||
int tpoint[4] {
|
||||
0,0,0,0};
|
||||
int spoint[1] {
|
||||
1};
|
||||
int trdt[4] {
|
||||
15,15,15,15};
|
||||
int prdt[1] {
|
||||
15};
|
||||
int conf[4] {
|
||||
0,0,0,0};
|
||||
int flt_hack { 0 };
|
||||
int xoploc[] {
|
||||
1,7,0,0,3,0,8,
|
||||
1,15,0,0,3,0,0,
|
||||
2,-1,0,0,3,0,0,
|
||||
1,15,1,15,3,0,0,
|
||||
1,15,2,-1,3,0,0,
|
||||
2,-1,1,15,4,0,0,
|
||||
1,15,1,15,3,0,0,
|
||||
1,15,2,-1,3,0,0,
|
||||
1,1,1,15,3,0,8,
|
||||
1,8,1,15,3,0,2,
|
||||
1,2,1,15,3,0,4,
|
||||
1,1,2,-1,3,0,8,
|
||||
1,8,2,-1,3,0,2,
|
||||
1,2,2,-1,3,0,4,
|
||||
1,1,1,15,1,8,0,
|
||||
1,8,1,15,1,2,0,
|
||||
1,2,1,15,1,4,0,
|
||||
1,1,2,-1,1,8,0,
|
||||
1,8,2,-1,1,2,0,
|
||||
1,2,2,-1,1,4,0,
|
||||
1,15,1,15,3,0,0,
|
||||
1,15,2,64,3,0,0,
|
||||
2,-1,1,15,3,0,0,
|
||||
2,-1,1,15,4,0,0,
|
||||
1,15,0,0,3,0,0,
|
||||
2,-1,0,0,1,15,0,
|
||||
2,-1,0,0,1,15,0,
|
||||
2,-1,1,8,1,7,0,
|
||||
2,-1,1,4,1,8,0,
|
||||
2,-1,0,0,1,15,0,
|
||||
2,-1,0,0,3,0,0,
|
||||
2,-1,1,15,4,0,0,
|
||||
1,15,0,0,3,0,0,
|
||||
1,1,0,0,1,8,0,
|
||||
1,15,1,15,2,32,0,
|
||||
1,15,2,-1,2,32,0,
|
||||
1,15,0,0,2,32,0,
|
||||
2,-1,0,0,2,32,0,
|
||||
0};
|
||||
int rtopp[192] {
|
||||
32,32,40,35,40,35,32,-1,-1,-1,
|
||||
0,40,35,40,35,35,-1,-1,-1,-1,
|
||||
52,-1,-1,-1,52,-1,-1,-1,-1,-1,
|
||||
-1,-1,45,45,45,45,45,45,45,-1,
|
||||
-1,-1,47,47,45,47,47,45,45,-1,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
-1,-1,-1,-1,5,29,5,29,9,-1,
|
||||
9,-1,5,29,5,29,12,-1,9,-1,
|
||||
19,-1,26,-1,26,-1,5,29,5,29,
|
||||
5,29,-1,-1,9,-1,2,2,2,-1,
|
||||
-1,-1,5,-1,-1,-1,9,-1,-1,-1,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,49,49,
|
||||
49,49,49,49,49,49,49,49,49,49,
|
||||
49,49,49,49,49,49,-1,-1,-1,-1,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
-1,-1,-1,-1,-1,-1,43,37,43,37,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
-1,-1};
|
||||
int rtopl[55] {
|
||||
0,-1,1,2,-1,3,4,5,-1,6,
|
||||
7,-1,8,9,10,11,12,13,-1,14,
|
||||
15,16,17,18,19,-1,20,21,-1,22,
|
||||
23,-1,24,25,-1,26,-1,27,28,-1,
|
||||
29,30,-1,31,-1,32,-1,33,-1,34,
|
||||
35,-1,36,37,-1};
|
||||
int opreg[192] {
|
||||
15,15,15,15,15,15,15,15,0,0,
|
||||
7,15,15,15,15,15,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,15,15,15,15,15,15,15,0,
|
||||
0,0,8,8,15,8,8,15,15,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,15,15,15,15,15,0,
|
||||
15,0,15,15,15,15,11,0,15,0,
|
||||
14,0,15,0,15,0,15,15,15,15,
|
||||
15,15,15,15,15,0,15,15,15,0,
|
||||
0,0,15,0,0,0,15,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,15,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,15,15,15,15,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0};
|
||||
int opmem[192] {
|
||||
0,0,-1,0,-1,0,0,0,0,0,
|
||||
0,-1,0,-1,0,0,0,0,0,0,
|
||||
32,0,0,0,32,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,-1,0,-1,0,0,
|
||||
0,0,0,-1,0,-1,0,0,0,0,
|
||||
0,0,0,0,0,0,0,-1,0,-1,
|
||||
0,-1,0,0,0,0,-1,-1,-1,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,128,256,64,0,32,32,
|
||||
32,32,32,32,32,32,32,32,32,32,
|
||||
32,32,32,32,32,32,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,
|
||||
0,0};
|
||||
int mactab[192] {
|
||||
24,24,17,15,18,16,23,-1,-1,-1,
|
||||
-1,17,15,18,16,14,-1,-1,-1,-1,
|
||||
43,-1,-1,-1,44,-1,-1,-1,-1,-1,
|
||||
-1,-1,48,46,46,48,46,46,48,-1,
|
||||
-1,-1,47,47,48,47,47,48,48,-1,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
-1,-1,-1,-1,1,7,3,12,2,-1,
|
||||
4,-1,1,8,3,13,2,-1,4,-1,
|
||||
2,-1,5,-1,6,-1,1,9,1,10,
|
||||
1,11,-1,-1,4,-1,49,49,49,-1,
|
||||
-1,-1,1,-1,-1,-1,2,-1,-1,-1,
|
||||
-1,-1,45,45,45,45,45,-1,-1,-1,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,31,32,
|
||||
33,34,35,36,37,38,39,40,41,42,
|
||||
25,26,27,28,29,30,-1,-1,-1,-1,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
-1,-1,-1,-1,-1,-1,21,19,22,20,
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
-1,-1};
|
||||
int ntype { 4 };
|
||||
int nmem { 13 };
|
||||
int nac { 1 };
|
||||
int npc { 1 };
|
||||
int sv_area_sz { 1 };
|
||||
int nreg { 4 };
|
||||
char mcstuff[] {
|
||||
'\t', '#', 'O', '\t', '#', 'F', ',', '#', 'S', 0, '\t', '#',
|
||||
'O', '\t', '#', 'S', ',', '#', 'F', 0, '\t', '#', 'O', '\t',
|
||||
'#', 'F', ',', '#', 'S', 0, '\t', '#', 'O', '%', 'i', 'f',
|
||||
'm', '(', '#', '5', ',', '#', '6', ',', 'I', '\t', '#', 'F',
|
||||
'\\', ',', '#', '6', ',', '\t', '#', 'F', '\\', ',', '#', 'S',
|
||||
')', 0, '\t', '#', 'O', '\t', '#', 'F', ',', '#', 'S', 0,
|
||||
'\t', '#', 'O', '\t', '#', 'F', ',', '#', 'S', 0, '\t', '#',
|
||||
'O', '%', 'i', 'f', 'm', '(', '#', '5', ',', '#', '6', ',',
|
||||
'I', '\t', '#', 'F', '\\', ',', '#', '6', ',', '\t', '#', 'F',
|
||||
'\\', ',', '#', 'S', ')', 0, '\t', '#', 'O', '\t', '#', 'F',
|
||||
',', '#', 'S', 0, '\t', '#', 'O', '\t', '#', 'S', ',', '#',
|
||||
'F', 0, '\t', '#', 'O', '\t', '#', 'F', ',', '#', 'S', 0,
|
||||
'\t', 'L', 'S', 'H', '\t', '#', 'R', ',', '#', '6', 0, '\t',
|
||||
'L', 'S', 'H', '\t', '#', 'R', ',', '(', '#', 'S', ')', 0,
|
||||
'\t', 'L', 'S', 'H', '\t', '#', 'R', ',', '-', '#', '6', 0,
|
||||
'\t', 'M', 'O', 'V', 'N', '\t', '#', 'S', ',', '#', 'S', '\n',
|
||||
'\t', 'L', 'S', 'H', '\t', '#', 'R', ',', '(', '#', 'S', ')',
|
||||
0, '\t', 'A', 'D', 'D', 'B', '\t', '#', 'S', ',', '#', 'F',
|
||||
0, '\t', 'I', 'M', 'U', 'L', 'B', '\t', '#', 'S', ',', '#',
|
||||
'F', 0, '\t', 'A', 'N', 'D', 'B', '\t', '#', 'S', ',', '#',
|
||||
'F', 0, '\t', 'X', 'O', 'R', 'B', '\t', '#', 'S', ',', '#',
|
||||
'F', 0, '\t', 'I', 'O', 'R', 'B', '\t', '#', 'S', ',', '#',
|
||||
'F', 0, '\t', 'F', 'A', 'D', 'R', 'B', '\t', '#', 'S', ',',
|
||||
'#', 'F', 0, '\t', 'F', 'M', 'P', 'R', 'B', '\t', '#', 'S',
|
||||
',', '#', 'F', 0, '\t', 'M', 'O', 'V', 'E', 'I', '\t', '#',
|
||||
'R', ',', '#', 'F', 0, '\t', 'M', 'O', 'V', 'E', '\t', '#',
|
||||
'R', ',', '#', 'F', '\n', '\t', 'A', 'O', 'S', '\t', '#', 'F',
|
||||
0, '\t', 'M', 'O', 'V', 'E', '\t', '#', 'R', ',', '#', 'F',
|
||||
'\n', '\t', 'S', 'O', 'S', '\t', '#', 'F', 0, '\t', 'M', 'O',
|
||||
'V', 'E', 'I', '\t', '#', 'R', ',', '1', '\n', '\t', 'A', 'D',
|
||||
'D', 'B', '\t', '#', 'R', ',', '#', 'F', 0, '\t', 'A', 'O',
|
||||
'S', '\t', '#', 'F', 0, '\t', 'S', 'E', 'T', 'O', '\t', '#',
|
||||
'R', ',', '\n', '\t', 'A', 'D', 'D', 'B', '\t', '#', 'R', ',',
|
||||
'#', 'F', 0, '\t', 'S', 'O', 'S', '\t', '#', 'F', 0, '\t',
|
||||
'M', 'O', 'V', 'E', '\t', '#', 'R', ',', '#', 'F', '\n', '\t',
|
||||
'A', 'D', 'D', 'M', '\t', '#', 'S', ',', '#', 'F', 0, '\t',
|
||||
'M', 'O', 'V', 'E', '\t', '#', 'R', ',', '#', 'F', '\n', '\t',
|
||||
'M', 'O', 'V', 'N', '\t', '#', 'S', ',', '#', 'S', '\n', '\t',
|
||||
'A', 'D', 'D', 'M', '\t', '#', 'S', ',', '#', 'F', 0, '\t',
|
||||
'A', 'D', 'D', 'B', '\t', '#', 'S', ',', '#', 'F', 0, '\t',
|
||||
'M', 'O', 'V', 'N', '\t', '#', 'S', ',', '#', 'S', '\n', '\t',
|
||||
'A', 'D', 'D', 'B', '\t', '#', 'S', ',', '#', 'F', 0, '\t',
|
||||
'S', 'E', 'T', 'C', 'A', '\t', '#', 'R', ',', 0, '\t', 'S',
|
||||
'E', 'T', 'C', 'M', '\t', '#', 'R', ',', '#', 'F', 0, '\t',
|
||||
'M', 'O', 'V', 'N', '\t', '#', 'R', ',', '#', 'F', 0, '\t',
|
||||
'C', 'A', 'M', 'N', '\t', '#', 'F', ',', '#', 'S', '\n', '\t',
|
||||
'G', 'O', '\t', '#', 'R', 0, '\t', 'C', 'A', 'M', 'E', '\t',
|
||||
'#', 'F', ',', '#', 'S', '\n', '\t', 'G', 'O', '\t', '#', 'R',
|
||||
0, '\t', 'C', 'A', 'M', 'G', 'E', '\t', '#', 'F', ',', '#',
|
||||
'S', '\n', '\t', 'G', 'O', '\t', '#', 'R', 0, '\t', 'C', 'A',
|
||||
'M', 'L', 'E', '\t', '#', 'F', ',', '#', 'S', '\n', '\t', 'G',
|
||||
'O', '\t', '#', 'R', 0, '\t', 'C', 'A', 'M', 'G', '\t', '#',
|
||||
'F', ',', '#', 'S', '\n', '\t', 'G', 'O', '\t', '#', 'R', 0,
|
||||
'\t', 'C', 'A', 'M', 'L', '\t', '#', 'F', ',', '#', 'S', '\n',
|
||||
'\t', 'G', 'O', '\t', '#', 'R', 0, '%', 'i', 'f', 'm', '(',
|
||||
'#', '5', ',', '#', '6', ',', '%', 'i', 'f', '(', '#', '6',
|
||||
',', '\t', 'C', 'A', 'I', 'N', '\t', '#', 'F', '\\', ',', '#',
|
||||
'6', '\n', '\t', 'G', 'O', '\t', '#', 'R', ',', '\t', 'J', 'U',
|
||||
'M', 'P', 'E', '\t', '#', 'F', '\\', ',', '#', 'R', ')', ',',
|
||||
'\t', 'C', 'A', 'M', 'N', '\t', '#', 'F', '\\', ',', '#', 'S',
|
||||
'\n', '\t', 'G', 'O', '\t', '#', 'R', ')', 0, '%', 'i', 'f',
|
||||
'm', '(', '#', '5', ',', '#', '6', ',', '%', 'i', 'f', '(',
|
||||
'#', '6', ',', '\t', 'C', 'A', 'I', 'E', '\t', '#', 'F', '\\',
|
||||
',', '#', '6', '\n', '\t', 'G', 'O', '\t', '#', 'R', ',', '\t',
|
||||
'J', 'U', 'M', 'P', 'N', '\t', '#', 'F', '\\', ',', '#', 'R',
|
||||
')', ',', '\t', 'C', 'A', 'M', 'E', '\t', '#', 'F', '\\', ',',
|
||||
'#', 'S', '\n', '\t', 'G', 'O', '\t', '#', 'R', ')', 0, '%',
|
||||
'i', 'f', 'm', '(', '#', '5', ',', '#', '6', ',', '%', 'i',
|
||||
'f', '(', '#', '6', ',', '\t', 'C', 'A', 'I', 'G', 'E', '\t',
|
||||
'#', 'F', '\\', ',', '#', '6', '\n', '\t', 'G', 'O', '\t', '#',
|
||||
'R', ',', '\t', 'J', 'U', 'M', 'P', 'L', '\t', '#', 'F', '\\',
|
||||
',', '#', 'R', ')', ',', '\t', 'C', 'A', 'M', 'G', 'E', '\t',
|
||||
'#', 'F', '\\', ',', '#', 'S', '\n', '\t', 'G', 'O', '\t', '#',
|
||||
'R', ')', 0, '%', 'i', 'f', 'm', '(', '#', '5', ',', '#',
|
||||
'6', ',', '%', 'i', 'f', '(', '#', '6', ',', '\t', 'C', 'A',
|
||||
'I', 'L', 'E', '\t', '#', 'F', '\\', ',', '#', '6', '\n', '\t',
|
||||
'G', 'O', '\t', '#', 'R', ',', '\t', 'J', 'U', 'M', 'P', 'G',
|
||||
'\t', '#', 'F', '\\', ',', '#', 'R', ')', ',', '\t', 'C', 'A',
|
||||
'M', 'L', 'E', '\t', '#', 'F', '\\', ',', '#', 'S', '\n', '\t',
|
||||
'G', 'O', '\t', '#', 'R', ')', 0, '%', 'i', 'f', 'm', '(',
|
||||
'#', '5', ',', '#', '6', ',', '%', 'i', 'f', '(', '#', '6',
|
||||
',', '\t', 'C', 'A', 'I', 'G', '\t', '#', 'F', '\\', ',', '#',
|
||||
'6', '\n', '\t', 'G', 'O', '\t', '#', 'R', ',', '\t', 'J', 'U',
|
||||
'M', 'P', 'L', 'E', '\t', '#', 'F', '\\', ',', '#', 'R', ')',
|
||||
',', '\t', 'C', 'A', 'M', 'G', '\t', '#', 'F', '\\', ',', '#',
|
||||
'S', '\n', '\t', 'G', 'O', '\t', '#', 'R', ')', 0, '%', 'i',
|
||||
'f', 'm', '(', '#', '5', ',', '#', '6', ',', '%', 'i', 'f',
|
||||
'(', '#', '6', ',', '\t', 'C', 'A', 'I', 'L', '\t', '#', 'F',
|
||||
'\\', ',', '#', '6', '\n', '\t', 'G', 'O', '\t', '#', 'R', ',',
|
||||
'\t', 'J', 'U', 'M', 'P', 'G', 'E', '\t', '#', 'F', '\\', ',',
|
||||
'#', 'R', ')', ',', '\t', 'C', 'A', 'M', 'L', '\t', '#', 'F',
|
||||
'\\', ',', '#', 'S', '\n', '\t', 'G', 'O', '\t', '#', 'R', ')',
|
||||
0, '\t', 'F', 'S', 'B', 'R', '\t', '#', 'F', ',', '#', 'S',
|
||||
'\n', '\t', 'J', 'U', 'M', 'P', 'E', '\t', '#', 'F', ',', '#',
|
||||
'R', 0, '\t', 'F', 'S', 'B', 'R', '\t', '#', 'F', ',', '#',
|
||||
'S', '\n', '\t', 'J', 'U', 'M', 'P', 'N', '\t', '#', 'F', ',',
|
||||
'#', 'R', 0, '\t', 'F', 'S', 'B', 'R', '\t', '#', 'F', ',',
|
||||
'#', 'S', '\n', '\t', 'J', 'U', 'M', 'P', 'L', '\t', '#', 'F',
|
||||
',', '#', 'R', 0, '\t', 'F', 'S', 'B', 'R', '\t', '#', 'F',
|
||||
',', '#', 'S', '\n', '\t', 'J', 'U', 'M', 'P', 'G', '\t', '#',
|
||||
'F', ',', '#', 'R', 0, '\t', 'F', 'S', 'B', 'R', '\t', '#',
|
||||
'F', ',', '#', 'S', '\n', '\t', 'J', 'U', 'M', 'P', 'L', 'E',
|
||||
'\t', '#', 'F', ',', '#', 'R', 0, '\t', 'F', 'S', 'B', 'R',
|
||||
'\t', '#', 'F', ',', '#', 'S', '\n', '\t', 'J', 'U', 'M', 'P',
|
||||
'G', 'E', '\t', '#', 'F', ',', '#', 'R', 0, '\t', 'S', 'K',
|
||||
'I', 'P', 'N', '\t', '#', 'F', '\n', '\t', 'G', 'O', '\t', '#',
|
||||
'R', 0, '\t', 'J', 'U', 'M', 'P', 'E', '\t', '#', 'F', ',',
|
||||
'#', 'R', 0, '\t', 'S', 'K', 'I', 'P', 'E', '\t', '#', 'F',
|
||||
'\n', '\t', 'G', 'O', '\t', '#', 'R', 0, '\t', 'J', 'U', 'M',
|
||||
'P', 'N', '\t', '#', 'F', ',', '#', 'R', 0, '\t', 'M', 'O',
|
||||
'V', 'E', '\t', '#', 'R', ',', '#', 'F', 0, '\t', 'M', 'O',
|
||||
'V', 'E', 'M', '\t', '#', 'F', ',', '#', 'R', 0, '\t', 'M',
|
||||
'O', 'V', 'E', '\t', '#', 'R', ',', '#', 'F', 0, '\t', '%',
|
||||
'i', 'f', 'm', '(', '#', '3', ',', '#', '4', ',', 'M', 'O',
|
||||
'V', 'E', 'I', '\t', '#', 'R', '\\', ',', '#', '4', ',', '%',
|
||||
'i', 'f', 'm', '(', '#', '3', ',', '-', '#', '4', ',', 'M',
|
||||
'O', 'V', 'N', 'I', '\t', '#', 'R', '\\', ',', '-', '#', '4',
|
||||
',', 'M', 'O', 'V', 'E', '\t', '#', 'R', '\\', ',', '#', 'F',
|
||||
')', ')', 0, '\t', 'F', 'S', 'C', '\t', '#', 'R', ',', '1',
|
||||
'5', '5', 0, '\t', 'J', 'S', 'P', '\t', '0', ',', 'F', 'I',
|
||||
'X', 'I', 'F', 'Y', '"', 0, '\\', 0, '\t', 'P', 'P', 'U',
|
||||
'S', 'H', '\t', '#', 'F', 0, '\t', '#', '0', 0, '\t', '#',
|
||||
'R', 0, '\\', 0, '\t', 'C', 'C', 'A', 'L', 'L', '\t', '#',
|
||||
'0', ',', '#', 'F', 0, '.', 'P', 'D', 'A', 'T', 'A', '\n',
|
||||
'C', 'O', 'N', 'S', 'T', 'A', 'N', 'T', 'S', '\n', 'E', 'N',
|
||||
'D', 0, '\t', 'E', 'N', 'T', 'R', 'Y', '\t', '#', '0', 0,
|
||||
'\t', 'E', 'X', 'T', 'E', 'R', 'N', '\t', '#', '0', 0, '#',
|
||||
'0', ':', 0, '\t', 'G', 'O', '\t', '#', 'R', 0, '\t', 'T',
|
||||
'I', 'T', 'L', 'E', ' ', '%', 'p', 'n', 'a', 'm', 'e', '(',
|
||||
')', '\n', '\t', 'R', 'A', 'D', 'I', 'X', ' ', '1', '0', '.',
|
||||
'\n', '.', 'I', 'N', 'S', 'R', 'T', ' ', 'C', ';', 'N', 'C',
|
||||
' ', 'I', 'N', 'S', 'E', 'R', 'T', '\n', 0, '\n', ';', '\t',
|
||||
'L', 'I', 'N', 'E', ' ', '#', '0', '\n', 0, '%', 's', 'e',
|
||||
't', 'f', 'n', 'o', '(', '#', '0', ')', '\n', '\\', '%', 'A',
|
||||
'=', '=', '#', '2', '\n', '\t', '\\', '%', 'A', ',', ',', '[',
|
||||
'A', 'S', 'C', 'I', 'Z', '/', '%', 'm', '(', '#', '1', ')',
|
||||
'/', ']', '\n', '%', 'i', '(', '#', '1', ')', ':', '\t', 'A',
|
||||
'D', 'D', 'I', '\t', 'P', ',', 'F', 'S', '#', '0', 0, '\t',
|
||||
'S', 'U', 'B', 'I', '\t', 'P', ',', 'F', 'S', '#', '0', '+',
|
||||
'\\', '%', 'A', '+', '1', '\n', '\t', 'G', 'O', '\t', '@', '<',
|
||||
'\\', '%', 'A', '+', '1', '>', '(', 'P', ')', 0, '\t', 'S',
|
||||
'U', 'B', 'I', '\t', 'P', ',', 'F', 'S', '#', '0', '+', '\\',
|
||||
'%', 'A', '+', '1', '\n', '\t', 'G', 'O', '\t', '@', '<', '\\',
|
||||
'%', 'A', '+', '1', '>', '(', 'P', ')', '\n', 'F', 'S', '#',
|
||||
'0', '=', '=', '#', '1', '-', '1', 0, 'I', '#', '0', ':',
|
||||
0, '\t', 'B', 'L', 'O', 'C', 'K', '\t', '#', '0', 0, '\t',
|
||||
'%', 'f', 'f', '(', '#', '0', ')', 0, '\t', '-', '%', 'f',
|
||||
'f', '(', '#', '0', ')', 0, '%', 'i', 'f', '(', '#', '0',
|
||||
',', '%', 's', 'b', '(', '6', '8', ',', '#', '3', ',', '#',
|
||||
'4', ',', '#', '3', ',', '#', '4', ',', '-', '6', ',', '#',
|
||||
'0', ')', '\n', ',', ')', '\t', 'J', 'U', 'M', 'P', 'L', '\t',
|
||||
'#', 'F', ',', '#', 'R', '\n', '\t', 'C', 'A', 'I', 'L', 'E',
|
||||
'\t', '#', 'F', ',', '#', '5', '-', '#', '0', '\n', '\t', 'G',
|
||||
'O', '\t', '#', 'R', '\n', '\t', 'G', 'O', '\t', '@', '(', '#',
|
||||
'F', ')', '[', 0, '\t', ']', 0, '\t', 'M', 'O', 'V', 'E',
|
||||
'\t', 'B', ',', '[', '-', '#', '0', ',', ',', '[', 0, '\t',
|
||||
']', ']', '\n', '\t', 'C', 'A', 'M', 'N', '\t', '#', 'F', ',',
|
||||
'(', 'B', ')', '\n', '\t', 'G', 'O', '\t', '@', '#', '0', '(',
|
||||
'B', ')', '\n', '\t', 'A', 'O', 'B', 'J', 'N', '\t', 'B', ',',
|
||||
'.', '-', '2', '\n', '\t', 'G', 'O', '\t', '#', 'R', 0, '\t',
|
||||
'L', '#', '0', 0, 'L', '#', '0', ':', 0, '\t', 'S', '#',
|
||||
'0', 0, '.', 'C', 'O', 'D', 'E', 0, '.', 'P', 'D', 'A',
|
||||
'T', 'A', 0, '.', 'U', 'D', 'A', 'T', 'A', 0, '.', 'I',
|
||||
'D', 'A', 'T', 'A', };
|
||||
char *mcstore {mcstuff};
|
||||
int macdef[79] {
|
||||
0,0,29,51,66,69,84,99,102,105,
|
||||
108,111,114,117,120,123,126,129,144,159,
|
||||
162,165,168,171,186,189,192,195,198,201,
|
||||
204,207,210,213,216,219,222,225,228,231,
|
||||
234,237,240,243,258,273,302,305,308,311,
|
||||
314,317,320,323,326,329,332,335,338,341,
|
||||
344,347,350,353,356,359,362,365,368,371,
|
||||
374,377,380,383,386,389,392,395,398};
|
||||
char *nmacname[] {
|
||||
"sb",
|
||||
"in",
|
||||
"c",
|
||||
"ad0",
|
||||
"al",
|
||||
"ca",
|
||||
"end",
|
||||
"en",
|
||||
"ex",
|
||||
"eq",
|
||||
"go",
|
||||
"hd",
|
||||
"ln",
|
||||
"p",
|
||||
"rt",
|
||||
"ep",
|
||||
"st",
|
||||
"z",
|
||||
"f",
|
||||
"d",
|
||||
"nf",
|
||||
"nd",
|
||||
"ts",
|
||||
"ets",
|
||||
"ls",
|
||||
"els",
|
||||
"lc",
|
||||
"l",
|
||||
"sc",
|
||||
"pu",
|
||||
"pd",
|
||||
"im",
|
||||
"da"};
|
||||
int nmacdef[33] {
|
||||
2,50,50,51,52,53,54,55,56,57,
|
||||
58,59,60,61,62,63,64,65,66,66,
|
||||
67,67,68,69,70,71,72,73,74,75,
|
||||
76,77,78};
|
||||
int mdeflist[401] {
|
||||
1,15,1,15,0,0,0,2,-1,0,
|
||||
0,0,0,10,1,15,2,-65,0,0,
|
||||
20,1,15,2,64,0,0,30,-1,0,
|
||||
0,1,15,0,0,62,0,0,2,-65,
|
||||
0,0,72,0,0,2,64,0,0,82,
|
||||
-1,1,15,0,0,0,0,114,2,-1,
|
||||
0,0,0,0,124,-1,3,134,-1,0,
|
||||
0,2,64,0,0,144,0,0,1,15,
|
||||
0,0,155,-1,0,0,2,64,0,0,
|
||||
168,0,0,1,15,0,0,180,-1,3,
|
||||
205,-1,3,217,-1,3,230,-1,3,242,
|
||||
-1,3,254,-1,3,266,-1,3,279,-1,
|
||||
3,292,-1,3,305,-1,3,325,-1,0,
|
||||
0,0,0,1,15,345,0,0,0,0,
|
||||
2,-1,369,-1,0,0,0,0,1,15,
|
||||
377,0,0,0,0,2,-1,399,-1,3,
|
||||
407,-1,3,431,-1,3,467,-1,3,479,
|
||||
-1,1,15,0,0,0,0,503,2,-1,
|
||||
0,0,0,0,514,-1,3,527,-1,3,
|
||||
539,-1,3,558,-1,3,577,-1,3,597,
|
||||
-1,3,617,-1,3,636,-1,3,655,-1,
|
||||
3,729,-1,3,803,-1,3,879,-1,3,
|
||||
955,-1,3,1030,-1,3,1105,-1,3,1130,
|
||||
-1,3,1155,-1,3,1180,-1,3,1205,-1,
|
||||
3,1231,-1,2,-1,0,0,0,0,1257,
|
||||
1,15,0,0,0,0,1274,-1,2,-1,
|
||||
0,0,0,0,1287,1,15,0,0,0,
|
||||
0,1304,-1,1,15,0,0,1,15,1317,
|
||||
1,15,0,0,2,-1,1329,2,-65,0,
|
||||
0,1,15,1342,2,64,0,0,1,15,
|
||||
1354,-1,3,1419,-1,3,1431,-1,3,1446,
|
||||
-1,3,1448,-1,3,1458,-1,3,1462,-1,
|
||||
3,1466,-1,3,1468,-1,3,1481,-1,3,
|
||||
1502,-1,3,1512,-1,3,1523,-1,3,1527,
|
||||
-1,3,1534,-1,3,1581,-1,3,1593,-1,
|
||||
3,1655,-1,3,1690,-1,3,1736,-1,3,
|
||||
1741,-1,3,1751,-1,3,1760,-1,3,1770,
|
||||
-1,3,1852,-1,3,1855,-1,3,1871,-1,
|
||||
3,1919,-1,3,1924,-1,3,1929,-1,3,
|
||||
1934,-1,3,1940,-1,3,1947,-1,3,1954,
|
||||
-1};
|
||||
int nnmacs { 33 };
|
||||
int mdflsz { 401 };
|
||||
int nmacros { 79 };
|
||||
285
c20/gt/pdp11.gt
Normal file
285
c20/gt/pdp11.gt
Normal file
@@ -0,0 +1,285 @@
|
||||
typenames (char, int, float, double);
|
||||
regnames (r0, r2, r3, r1, fr0, fr1, fr2, fr3);
|
||||
memnames (reg, auto, ext, stat, param, label, intlit, floatlit,
|
||||
stringlit, ir0, ir2, ir3, ir1);
|
||||
size 1 (char), 2 (int, float), 4 (double);
|
||||
align 1 (char), 2 (int, float), 4 (double);
|
||||
class r (r0, r1, r2, r3), f (fr0, fr1, fr2, fr3);
|
||||
saveareasize 0;
|
||||
pointer p0 (1);
|
||||
offsetrange p0 (,);
|
||||
returnreg r0 (int, p0), fr0 (double);
|
||||
type char(r), int(r), float(f), double(f), p0(r);
|
||||
|
||||
.sw: r0|r2,,1[r1,r3];
|
||||
|
||||
+i: &: .OR: +p0: r,r,1; r,M,1; M,r,2;
|
||||
|
||||
-i: -p0: -p0p0: <<: >>: r,r,1; r,M,1;
|
||||
|
||||
*i: r1,r,r1;
|
||||
r3,r,r3;
|
||||
r1,M,r1;
|
||||
r3,M,r3;
|
||||
r0,r,r1[r0];
|
||||
r2,r,r3[r2];
|
||||
r0,M,r1[r0];
|
||||
r2,M,r3[r2];
|
||||
|
||||
/i: r1,r2|r3,r0[r1];
|
||||
r3,r0|r1,r2[r3];
|
||||
r1,M,r0[r1];
|
||||
r3,M,r2[r3];
|
||||
|
||||
%: r1,r2|r3,r1[r0];
|
||||
r3,r0|r1,r3[r2];
|
||||
r1,M,r1[r0];
|
||||
r3,M,r3[r1];
|
||||
|
||||
^: r,r,1;
|
||||
|
||||
+d: *d: f,f,1; f,M,1; M,f,2;
|
||||
|
||||
-d: /d: f,f,1; f,M,1;
|
||||
|
||||
=+i: =-i: =&: =OR:
|
||||
++bp0: --bp0: M,r,1; M,M,1;
|
||||
|
||||
=^: M,r,1;
|
||||
|
||||
.BNOT: -ui: r,,1;
|
||||
|
||||
-ud: f,,1;
|
||||
|
||||
&u0: M,,r;
|
||||
|
||||
++ai: ++ac: --ai: --ac: M,,r;
|
||||
|
||||
++ap0: --ap0: M,r,r; M,M,r;
|
||||
|
||||
++bi: ++bc:
|
||||
--bi: --bc: M,,1;
|
||||
|
||||
.ic: .ci: .ip0: .p0i: r,,1;
|
||||
|
||||
.df: .fd: f,,1;
|
||||
|
||||
.cf: .cd: r,,f;
|
||||
.if: .id: r,,f; M,,f;
|
||||
.fc: .dc: .fi: .di: f,,r;
|
||||
|
||||
==p0: !=p0: <p0: >p0: <=p0: >=p0:
|
||||
==i: !=i: <i: >i: <=i: >=i: r,r,label;
|
||||
r,M,label;
|
||||
M,r,label;
|
||||
M,M,label;
|
||||
|
||||
==d: !=d: <d: >d: <=d: >=d: f,f,label; M,f,label;
|
||||
|
||||
|
||||
macros
|
||||
|
||||
+i: .OR: +p0: +d: *d:
|
||||
|
||||
(r|f,,): " #O #S,#F"
|
||||
(M,,): " #O #F,#S"
|
||||
|
||||
-i: -p0: -p0p0: sb: ^: *i: -d: /d:
|
||||
|
||||
" #O #S,#F"
|
||||
/i: %:
|
||||
|
||||
" tst #F
|
||||
sxt #F-1
|
||||
#O #S,#F-1"
|
||||
|
||||
&:
|
||||
|
||||
(r,,):
|
||||
" mov #S,-(sp)
|
||||
com (sp)
|
||||
bic (sp)+,#F"
|
||||
|
||||
(M,,):
|
||||
" mov #F,-(sp)
|
||||
com (sp)
|
||||
bic (sp)+,#S"
|
||||
|
||||
<<: " ash #S,#F"
|
||||
>>:
|
||||
(,intlit,): " ash \#-#6.,#F"
|
||||
(,~intlit,):
|
||||
" mov #S,-(sp)
|
||||
neg (sp)
|
||||
ash (sp)+,#F"
|
||||
|
||||
=+i: ++bp0: " add #S,#F"
|
||||
=-i: --bp0: " sub #S,#F"
|
||||
=OR: " bis #S,#F"
|
||||
=^: " xor #S,#F"
|
||||
=&:
|
||||
|
||||
" mov #S,-(sp)
|
||||
com (sp)
|
||||
bic (sp)+,#F"
|
||||
|
||||
.BNOT: -ui: -ud:
|
||||
|
||||
" #O #R"
|
||||
|
||||
&u0:
|
||||
(auto,,):
|
||||
" mov sp,#R
|
||||
add \##4.,#R"
|
||||
(ext|stat|label|stringlit,,):
|
||||
" mov \##F,#R"
|
||||
(param,,):
|
||||
" mov r4,#R
|
||||
add \##4.,#R"
|
||||
|
||||
++ai:
|
||||
|
||||
" mov #F,#R
|
||||
inc #F"
|
||||
|
||||
++ac:
|
||||
|
||||
" movb #F,#R
|
||||
incb #F"
|
||||
|
||||
--ai:
|
||||
|
||||
" mov #F,#R
|
||||
dec #F"
|
||||
|
||||
--ac:
|
||||
|
||||
" movb #F,#R
|
||||
decb #F"
|
||||
|
||||
++ap0:
|
||||
|
||||
" mov #F,#R
|
||||
add #S,#F"
|
||||
|
||||
--ap0:
|
||||
|
||||
" mov #F,#R
|
||||
sub #S,#F"
|
||||
|
||||
++bi: " inc #R"
|
||||
--bi: " dec #R"
|
||||
++bc: " incb #R"
|
||||
--bc: " decb #R"
|
||||
|
||||
.ic:
|
||||
.ip0: .p0i:
|
||||
.df: .fd: "\"
|
||||
|
||||
.ci: " bic \#177400,#R"
|
||||
|
||||
.cf: .cd:
|
||||
|
||||
" bic \#177400,#F
|
||||
ldcid #F,#R"
|
||||
|
||||
.if: .id: " ldcid #F,#R"
|
||||
.fi: .di:
|
||||
.fc: .dc: " stcdi #F,#R"
|
||||
|
||||
==i: !=i: <i: >i: <=i: >=i:
|
||||
|
||||
" cmp #F,#S
|
||||
%bc(#'O) .+6
|
||||
jmp #R"
|
||||
|
||||
==d: !=d: <d: >d: <=d: >=d:
|
||||
|
||||
" cmpd #F,#S
|
||||
%bc(#'O) .+6
|
||||
jmp #R"
|
||||
|
||||
==p0: !=p0: <p0: >p0: <=p0: >=p0:
|
||||
|
||||
" cmp #F,#S
|
||||
%ubc(#'O) .+6
|
||||
jmp #R"
|
||||
|
||||
.cc: " movb #F,#R"
|
||||
.ii: .p0p0: " mov #F,#R"
|
||||
.ff:
|
||||
|
||||
(f,,f): " ldd #F,#R"
|
||||
(M,,f): " ldcfd #F,#R"
|
||||
(f,,M): " stcdf #F,#R"
|
||||
|
||||
.dd:
|
||||
|
||||
(,,f): " ldd #F,#R"
|
||||
(,,M): " std #F,#R"
|
||||
|
||||
in: " #0."
|
||||
ad0: " #R"
|
||||
c: " .byte #0."
|
||||
ca:
|
||||
|
||||
" jsr r5,#F
|
||||
#1.
|
||||
#0."
|
||||
|
||||
end: ".end"
|
||||
en: ex: ".globl #0"
|
||||
ep:
|
||||
|
||||
" jmp epilog
|
||||
fs#0=#1."
|
||||
|
||||
eq: "#0:"
|
||||
go: " jmp #R"
|
||||
hd:
|
||||
|
||||
".title %pname()
|
||||
.insrt c;c11 insert
|
||||
"
|
||||
|
||||
ln: "\n; line #0\n"
|
||||
p:
|
||||
|
||||
"
|
||||
%i(#1): jsr r0,prolog
|
||||
fs#0"
|
||||
|
||||
rt: " jmp epilog"
|
||||
st: "i#0:"
|
||||
z: " .blkb #0."
|
||||
|
||||
f: d: " %ff(#0)"
|
||||
nf: nd: " -%ff(#0)"
|
||||
|
||||
ts:
|
||||
"%if(#0,%sb(68,#'F,#'F,-6,#0)
|
||||
,) tst #F
|
||||
bge .+6
|
||||
jmp #R
|
||||
cmp #F,\#<#5.-#0.>
|
||||
bgt .+8.
|
||||
asl #F
|
||||
jmp @<.+8.>(#F)
|
||||
jmp #R"
|
||||
|
||||
ls:
|
||||
" mov \##0.,r1
|
||||
mov \#.+18.,r3
|
||||
cmp #F,(r3)+
|
||||
bne .+6
|
||||
jmp @2*#0.-2(r3)
|
||||
sob r1,.-8.
|
||||
jmp #R"
|
||||
|
||||
lc: " l#0"
|
||||
l: "l#0:"
|
||||
sc: " s#0"
|
||||
pu: pd: ".text"
|
||||
da: ".data"
|
||||
im: ".bss"
|
||||
|
||||
234
c20/gt/pdp20.gt
Normal file
234
c20/gt/pdp20.gt
Normal file
@@ -0,0 +1,234 @@
|
||||
typenames (char, int, float, double);
|
||||
regnames (a, c, d, b);
|
||||
memnames (reg, auto, ext, stat, param, label, intlit, floatlit,
|
||||
stringlit, ia, ic, id, ib);
|
||||
size 1 (char, int, float, double);
|
||||
align 1(char, int, float, double);
|
||||
class r (a, b, c, d);
|
||||
saveareasize 1;
|
||||
pointer p0 (1);
|
||||
offsetrange p0 (,);
|
||||
returnreg a (int, double, p0);
|
||||
type char(r), int(r), float(r), double(r), p0(r);
|
||||
|
||||
.sw: a|c|d,,1[b];
|
||||
.argi: .argd: .arg0: r,,1; M,,1;
|
||||
|
||||
+i: *i: &: ^: .OR: +p0:
|
||||
+d: *d: r,r,1; r,M,1; M,r,2;
|
||||
|
||||
-i: -p0: -p0p0: -d: /d: r,r,1; r,M,1;
|
||||
|
||||
/i: a,r,1[b]; b,r,1[c]; c,r,1[d];
|
||||
a,M,1[b]; b,M,1[c]; c,M,1[d];
|
||||
|
||||
%: a,r,b; b,r,c; c,r,d;
|
||||
a,M,b; b,M,c; c,M,d;
|
||||
|
||||
<<: >>: r,r,1; r,intlit,1;
|
||||
|
||||
=+i: =*i: =&: =^: =OR:
|
||||
=+d: =*d: M,r,1; M,r,2;
|
||||
|
||||
.BNOT: -ui: -ud: r,,1; M,,r;
|
||||
|
||||
&u0:
|
||||
++ai: ++ac: --ai: --ac: M,,r;
|
||||
|
||||
++ap0: --ap0: M,b,a|c|d; M,d,b;
|
||||
|
||||
++bi: ++bc:
|
||||
--bi: --bc: M,,r; M,,1;
|
||||
|
||||
++bp0: --bp0: M,r,2;
|
||||
|
||||
.ic: .ci: .ip0: .p0i: .df: .fd:
|
||||
.cf: .cd: .if: .id: r,,1;
|
||||
|
||||
.fc: .dc: .fi: .di: a,,b;
|
||||
|
||||
==p0: !=p0: <p0: >p0: <=p0: >=p0:
|
||||
==i: !=i: <i: >i: <=i: >=i:
|
||||
==d: !=d: <d: >d: <=d: >=d: r,r,label; r,M,label;
|
||||
|
||||
==0p0: !=0p0: r,,label; M,,label;
|
||||
|
||||
|
||||
|
||||
|
||||
macros
|
||||
|
||||
+i: *i: &: ^: .OR: +p0:
|
||||
|
||||
(r,r,): " #O #F,#S"
|
||||
(M,,): " #O #S,#F"
|
||||
(r,~intlit,): " #O #F,#S"
|
||||
(r,intlit,): " #O%ifm(#'S,I #F\,#6, #F\,#S)"
|
||||
|
||||
-i: /i: %: -p0: sb:
|
||||
|
||||
(,r,): " #O #F,#S"
|
||||
(,~intlit,): " #O #F,#S"
|
||||
(,intlit,): " #O%ifm(#'S,I #F\,#6, #F\,#S)"
|
||||
|
||||
+d: *d:
|
||||
|
||||
(r,,): " #O #F,#S"
|
||||
(M,,): " #O #S,#F"
|
||||
|
||||
-d: /d: -p0p0:
|
||||
|
||||
" #O #F,#S"
|
||||
|
||||
<<:
|
||||
(,intlit,): " LSH #R,#6"
|
||||
(,r,): " LSH #R,(#S)"
|
||||
>>:
|
||||
(,intlit,): " LSH #R,-#6"
|
||||
(,r,): " MOVN #S,#S\n LSH #R,(#S)"
|
||||
|
||||
=+i: " ADDB #S,#F"
|
||||
=*i: " IMULB #S,#F"
|
||||
=&: " ANDB #S,#F"
|
||||
=^: " XORB #S,#F"
|
||||
=OR: " IORB #S,#F"
|
||||
=+d: " FADRB #S,#F"
|
||||
=*d: " FMPRB #S,#F"
|
||||
|
||||
&u0: " MOVEI #R,#F"
|
||||
++ai: ++ac: " MOVE #R,#F\n AOS #F"
|
||||
--ai: --ac: " MOVE #R,#F\n SOS #F"
|
||||
++bi: ++bc:
|
||||
(,,r): " MOVEI #R,1\n ADDB #R,#F"
|
||||
(,,M): " AOS #F"
|
||||
--bi: --bc:
|
||||
(,,r): " SETO #R,\n ADDB #R,#F"
|
||||
(,,M): " SOS #F"
|
||||
++ap0: " MOVE #R,#F\n ADDM #S,#F"
|
||||
--ap0: " MOVE #R,#F\n MOVN #S,#S\n ADDM #S,#F"
|
||||
++bp0: " ADDB #S,#F"
|
||||
--bp0: " MOVN #S,#S\n ADDB #S,#F"
|
||||
.BNOT:
|
||||
(r,,): " SETCA #R,"
|
||||
(M,,): " SETCM #R,#F"
|
||||
-ui: -ud: " MOVN #R,#F"
|
||||
|
||||
==p0: " CAMN #F,#S\n GO #R"
|
||||
!=p0: " CAME #F,#S\n GO #R"
|
||||
<p0: " CAMGE #F,#S\n GO #R"
|
||||
>p0: " CAMLE #F,#S\n GO #R"
|
||||
<=p0: " CAMG #F,#S\n GO #R"
|
||||
>=p0: " CAML #F,#S\n GO #R"
|
||||
|
||||
==i: "%ifm(#'S,%if(#6,\tCAIN\t#F\,#6\n\tGO\t#R,\tJUMPE\t#F\,#R),\tCAMN\t#F\,#S\n\tGO\t#R)"
|
||||
!=i: "%ifm(#'S,%if(#6,\tCAIE\t#F\,#6\n\tGO\t#R,\tJUMPN\t#F\,#R),\tCAME\t#F\,#S\n\tGO\t#R)"
|
||||
<i: "%ifm(#'S,%if(#6,\tCAIGE\t#F\,#6\n\tGO\t#R,\tJUMPL\t#F\,#R),\tCAMGE\t#F\,#S\n\tGO\t#R)"
|
||||
>i: "%ifm(#'S,%if(#6,\tCAILE\t#F\,#6\n\tGO\t#R,\tJUMPG\t#F\,#R),\tCAMLE\t#F\,#S\n\tGO\t#R)"
|
||||
<=i: "%ifm(#'S,%if(#6,\tCAIG\t#F\,#6\n\tGO\t#R,\tJUMPLE\t#F\,#R),\tCAMG\t#F\,#S\n\tGO\t#R)"
|
||||
>=i: "%ifm(#'S,%if(#6,\tCAIL\t#F\,#6\n\tGO\t#R,\tJUMPGE\t#F\,#R),\tCAML\t#F\,#S\n\tGO\t#R)"
|
||||
|
||||
==d: " FSBR #F,#S\n JUMPE #F,#R"
|
||||
!=d: " FSBR #F,#S\n JUMPN #F,#R"
|
||||
<d: " FSBR #F,#S\n JUMPL #F,#R"
|
||||
>d: " FSBR #F,#S\n JUMPG #F,#R"
|
||||
<=d: " FSBR #F,#S\n JUMPLE #F,#R"
|
||||
>=d: " FSBR #F,#S\n JUMPGE #F,#R"
|
||||
|
||||
==0p0:
|
||||
(M,,): " SKIPN #F\n GO #R"
|
||||
(r,,): " JUMPE #F,#R"
|
||||
!=0p0:
|
||||
(M,,): " SKIPE #F\n GO #R"
|
||||
(r,,): " JUMPN #F,#R"
|
||||
|
||||
.cc: .ii:
|
||||
.ff: .dd:
|
||||
.p0p0:
|
||||
(r,,r): " MOVE #R,#F"
|
||||
(r,,M): " MOVEM #F,#R"
|
||||
(~intlit,,r): " MOVE #R,#F"
|
||||
(intlit,,r): " %ifm(#'F,MOVEI\t#R\,#4,%ifm(#3,-#4,MOVNI\t#R\,-#4,MOVE\t#R\,#F))"
|
||||
|
||||
.if: .id:
|
||||
.cf: .cd: " FSC #R,155"
|
||||
.di: .dc:
|
||||
.fi: .fc: " JSP 0,FIXIFY"""
|
||||
.ic: .ci:
|
||||
.ip0: .p0i:
|
||||
.df: .fd: "\"
|
||||
|
||||
.argi:
|
||||
.argd:
|
||||
.arg0: " PPUSH #F"
|
||||
|
||||
in: c: " #0"
|
||||
ad0: " #R"
|
||||
|
||||
al: "\"
|
||||
ca: " CCALL #0,#F"
|
||||
|
||||
end:
|
||||
".PDATA
|
||||
CONSTANTS
|
||||
END"
|
||||
|
||||
en: " ENTRY #0"
|
||||
ex: " EXTERN #0"
|
||||
eq: "#0:"
|
||||
go: " GO #R"
|
||||
hd:
|
||||
|
||||
" TITLE %pname()
|
||||
RADIX 10.
|
||||
.INSRT <C>NC
|
||||
"
|
||||
|
||||
ln: "\n; LINE #0\n"
|
||||
p:
|
||||
|
||||
"%setfno(#0)
|
||||
\%A==#2
|
||||
\%A,,[ASCIZ/%m(#1)/]
|
||||
%i(#1): ADDI P,FS#0"
|
||||
|
||||
rt:
|
||||
" SUBI P,FS#0+\%A+1
|
||||
GO @<\%A+1>(P)"
|
||||
ep:
|
||||
" SUBI P,FS#0+\%A+1
|
||||
GO @<\%A+1>(P)
|
||||
FS#0==#1-1"
|
||||
|
||||
st: "I#0:"
|
||||
z: " BLOCK #0"
|
||||
|
||||
f: d: " %ff(#0)"
|
||||
nf: nd: " -%ff(#0)"
|
||||
|
||||
ts:
|
||||
"%if(#0,%sb(68,#'F,#'F,-6,#0)
|
||||
,) JUMPL #F,#R
|
||||
CAILE #F,#5-#0
|
||||
GO #R
|
||||
GO @(#F)["
|
||||
|
||||
ets: " ]"
|
||||
|
||||
ls:
|
||||
" MOVE B,[-#0,,["
|
||||
|
||||
els:
|
||||
" ]]
|
||||
CAMN #F,(B)
|
||||
GO @#0(B)
|
||||
AOBJN B,.-2
|
||||
GO #R"
|
||||
|
||||
lc: " L#0"
|
||||
l: "L#0:"
|
||||
sc: " S#0"
|
||||
pu: ".CODE"
|
||||
pd: ".PDATA"
|
||||
im: ".UDATA"
|
||||
da: ".IDATA"
|
||||
|
||||
340
c20/gt/unix.gt
Normal file
340
c20/gt/unix.gt
Normal file
@@ -0,0 +1,340 @@
|
||||
typenames (char, int, float, double);
|
||||
regnames (r0, r2, r3, r1, fr0, fr1, fr2, fr3);
|
||||
memnames (reg, auto, ext, stat, param, label, intlit, floatlit,
|
||||
stringlit, ir0, ir2, ir3, ir1);
|
||||
size 1 (char), 2 (int), 4 (float), 8 (double);
|
||||
align 1 (char), 2 (int, float, double);
|
||||
class r (r0, r1, r2, r3), f (fr0, fr1, fr2, fr3);
|
||||
saveareasize 0;
|
||||
pointer p0 (1);
|
||||
offsetrange p0 (,);
|
||||
returnreg r0 (int, p0), fr0 (double);
|
||||
type char(r), int(r), float(f), double(f), p0(r);
|
||||
|
||||
.sw: r0|r2,,1[r1,r3];
|
||||
|
||||
+i: &: .OR: +p0: r,r,1; r,M,1; M,r,2;
|
||||
|
||||
-i: -p0: -p0p0: <<: >>: r,r,1; r,M,1;
|
||||
|
||||
*i: r1,r,r1;
|
||||
r3,r,r3;
|
||||
r1,M,r1;
|
||||
r3,M,r3;
|
||||
r0,r,r1[r0];
|
||||
r2,r,r3[r2];
|
||||
r0,M,r1[r0];
|
||||
r2,M,r3[r2];
|
||||
|
||||
/i: r1,r2|r3,r0[r1];
|
||||
r3,r0|r1,r2[r3];
|
||||
r1,M,r0[r1];
|
||||
r3,M,r2[r3];
|
||||
|
||||
%: r1,r2|r3,r1[r0];
|
||||
r3,r0|r1,r3[r2];
|
||||
r1,M,r1[r0];
|
||||
r3,M,r3[r1];
|
||||
|
||||
^: r,r,1;
|
||||
|
||||
+d: *d: f,f,1; f,~floatlit,1; ~floatlit,f,2;
|
||||
|
||||
-d: /d: f,f,1; f,~floatlit,1;
|
||||
|
||||
=+i: =-i: =&: =OR:
|
||||
++bp0: --bp0: M,r,1; M,M,1;
|
||||
|
||||
=^: M,r,1;
|
||||
|
||||
.BNOT: -ui: r,,1;
|
||||
|
||||
-ud: f,,1;
|
||||
|
||||
&u0: M,,r;
|
||||
|
||||
++ai: ++ac: --ai: --ac: M,,r;
|
||||
|
||||
++ap0: --ap0: M,r,r; M,M,r;
|
||||
|
||||
++bi: ++bc:
|
||||
--bi: --bc: M,,1;
|
||||
|
||||
.ic: .ci: .ip0: .p0i: r,,1;
|
||||
|
||||
.df: .fd: f,,1;
|
||||
|
||||
.cf: .cd: r,,f;
|
||||
.if: .id: r,,f; M,,f;
|
||||
.fc: .dc: .fi: .di: f,,r;
|
||||
|
||||
==p0: !=p0: <p0: >p0: <=p0: >=p0:
|
||||
==i: !=i: <i: >i: <=i: >=i: r,r,label;
|
||||
r,M,label;
|
||||
M,r,label;
|
||||
M,M,label;
|
||||
|
||||
==d: !=d: <d: >d: <=d: >=d: f,f,label; ~floatlit,f,label;
|
||||
|
||||
macros
|
||||
|
||||
+i: .OR: +p0: +d: *d:
|
||||
|
||||
(r|f,,): " #O #S,#F"
|
||||
(M,,): " #O #F,#S"
|
||||
|
||||
-i: -p0: -p0p0: sb: ^: *i: -d: /d:
|
||||
|
||||
" #O #S,#F"
|
||||
/i: %:
|
||||
|
||||
" tst #F
|
||||
sxt #F-1
|
||||
#O #S,#F-1"
|
||||
|
||||
&:
|
||||
|
||||
(r,,):
|
||||
" mov #S,-(sp)
|
||||
com (sp)
|
||||
bic (sp)+,#F"
|
||||
|
||||
(M,,):
|
||||
" mov #F,-(sp)
|
||||
com (sp)
|
||||
bic (sp)+,#S"
|
||||
|
||||
<<: " ash #S,#F"
|
||||
>>:
|
||||
(,intlit,): " ash $-#6.,#F"
|
||||
(,~intlit,):
|
||||
" mov #S,-(sp)
|
||||
neg (sp)
|
||||
ash +(sp),#F"
|
||||
|
||||
=+i: ++bp0: " add #S,#F"
|
||||
=-i: --bp0: " sub #S,#F"
|
||||
=OR: " bis #S,#F"
|
||||
=^: " xor #S,#F"
|
||||
=&:
|
||||
|
||||
" mov #S,-(sp)
|
||||
com (sp)
|
||||
bic (sp)+,#F"
|
||||
|
||||
.BNOT: -ui: -ud:
|
||||
|
||||
" #O #R"
|
||||
|
||||
&u0:
|
||||
(auto,,):
|
||||
" mov sp,#R
|
||||
add $#4.,#R"
|
||||
(ext|stat|label|stringlit,,):
|
||||
" mov $#F,#R"
|
||||
(param,,):
|
||||
" mov r4,#R
|
||||
add $#4.,#R"
|
||||
|
||||
++ai:
|
||||
|
||||
" mov #F,#R
|
||||
inc #F"
|
||||
|
||||
++ac:
|
||||
|
||||
" movb #F,#R
|
||||
incb #F"
|
||||
|
||||
--ai:
|
||||
|
||||
" mov #F,#R
|
||||
dec #F"
|
||||
|
||||
--ac:
|
||||
|
||||
" movb #F,#R
|
||||
decb #F"
|
||||
|
||||
++ap0:
|
||||
|
||||
" mov #F,#R
|
||||
add #S,#F"
|
||||
|
||||
--ap0:
|
||||
|
||||
" mov #F,#R
|
||||
sub #S,#F"
|
||||
|
||||
++bi: " inc #R"
|
||||
--bi: " dec #R"
|
||||
++bc: " incb #R"
|
||||
--bc: " decb #R"
|
||||
|
||||
.ic:
|
||||
.ip0: .p0i:
|
||||
.df: .fd: "\"
|
||||
|
||||
.ci: " bic $177400,#R"
|
||||
|
||||
.cf: .cd:
|
||||
|
||||
" bic $177400,#F
|
||||
movif #F,#R"
|
||||
|
||||
.if: .id: " movif #F,#R"
|
||||
.fi: .di:
|
||||
.fc: .dc: " movfi #F,#R"
|
||||
|
||||
==i:
|
||||
==p0:
|
||||
|
||||
" cmp #F,#S
|
||||
jeq #R"
|
||||
|
||||
!=i:
|
||||
!=p0:
|
||||
|
||||
" cmp #F,#S
|
||||
jne #R"
|
||||
|
||||
<i:
|
||||
|
||||
" cmp #F,#S
|
||||
jlt #R"
|
||||
|
||||
>i:
|
||||
|
||||
" cmp #F,#S
|
||||
jgt #R"
|
||||
|
||||
<=i:
|
||||
|
||||
" cmp #F,#S
|
||||
jle #R"
|
||||
|
||||
>=i:
|
||||
|
||||
" cmp #F,#S
|
||||
jge #R"
|
||||
|
||||
==d:
|
||||
|
||||
" cmpf #F,#S
|
||||
jeq #R"
|
||||
|
||||
!=d:
|
||||
|
||||
" cmpf #F,#S
|
||||
jne #R"
|
||||
|
||||
<d:
|
||||
|
||||
" cmpf #F,#S
|
||||
jlt #R"
|
||||
|
||||
>d:
|
||||
|
||||
" cmpf #F,#S
|
||||
jgt #R"
|
||||
|
||||
<=d:
|
||||
|
||||
" cmpf #F,#S
|
||||
jle #R"
|
||||
|
||||
>=d:
|
||||
|
||||
" cmpf #F,#S
|
||||
jge #R"
|
||||
|
||||
<p0:
|
||||
|
||||
" cmp #F,#S
|
||||
jlo #R"
|
||||
|
||||
>p0:
|
||||
|
||||
" cmp #F,#S
|
||||
jhi #R"
|
||||
|
||||
<=p0:
|
||||
|
||||
" cmp #F,#S
|
||||
jlos #R"
|
||||
|
||||
>=p0:
|
||||
|
||||
" cmp #F,#S
|
||||
jhis #R"
|
||||
|
||||
.cc: " movb #F,#R"
|
||||
.ii: .p0p0: " mov #F,#R"
|
||||
.ff:
|
||||
|
||||
(f,,f): " movf #F,#R"
|
||||
(M,,f): " movof #F,#R"
|
||||
(f,,M): " movfo #F,#R"
|
||||
|
||||
.dd:
|
||||
|
||||
(~floatlit,,f): " movf #F,#R"
|
||||
(,,M): " movf #F,#R"
|
||||
(floatlit,,f):
|
||||
" movf 0f,#R
|
||||
.data
|
||||
0: %ff(#4)
|
||||
.text"
|
||||
|
||||
in: " #0."
|
||||
ad0: " #0"
|
||||
c: " .byte #0."
|
||||
al: ".even"
|
||||
ca: " jsr r5,#F; #1.; #0."
|
||||
|
||||
end: "\"
|
||||
en: ex: ".globl #0"
|
||||
ep:
|
||||
|
||||
" jmp epilog
|
||||
fs#0=#1."
|
||||
|
||||
eq: "#0:"
|
||||
go: " jbr #R"
|
||||
hd: ".globl prolog,epilog"
|
||||
|
||||
ln: "\n/ line #0\n"
|
||||
p: "\n%i(#1): jsr r0,prolog; fs#0"
|
||||
|
||||
rt: " jmp epilog"
|
||||
st: "i#0:"
|
||||
z: ".=.+#0."
|
||||
|
||||
f: d: " %ff(#0)"
|
||||
nf: nd: " %nff(#0)"
|
||||
|
||||
ts:
|
||||
"%if(#0,%sb(68,#'F,#'F,-6,#0)
|
||||
,) cmp #F,$#5.-[#0.]
|
||||
jhi #R
|
||||
asl #F
|
||||
jmp *0f(#F)
|
||||
0:"
|
||||
|
||||
ls:
|
||||
" mov $#0.,r1
|
||||
mov $0f,r3
|
||||
2: cmp #F,(r3)+
|
||||
beq 1f
|
||||
sob r1,2b
|
||||
jbr #R
|
||||
1: jmp *2*#0.-2(r3)
|
||||
0:"
|
||||
|
||||
lc: " l#0"
|
||||
l: "l#0:"
|
||||
sc: " s#0"
|
||||
pu: pd: ".text"
|
||||
da: ".data"
|
||||
im: ".bss"
|
||||
|
||||
51
c20/lex.h
Normal file
51
c20/lex.h
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
/*
|
||||
* lex library header file -- accessed through
|
||||
* #include <lex.h>
|
||||
*/
|
||||
|
||||
/*
|
||||
* description of scanning
|
||||
* tables.
|
||||
* the entries at the front of
|
||||
* the struct must remain in
|
||||
* place for the assembler routines
|
||||
* to find.
|
||||
*/
|
||||
struct lextab {
|
||||
int llendst; /* Last state number */
|
||||
char *lldefault; /* Default state table */
|
||||
char *llnext; /* Next state table */
|
||||
char *llcheck; /* Check table */
|
||||
int *llbase; /* Base table */
|
||||
int llnxtmax; /* Last in base table */
|
||||
|
||||
int (*llmove)(); /* Move between states */
|
||||
int *llfinal; /* Final state descriptions */
|
||||
int (*llactr)(); /* Action routine */
|
||||
int *lllook; /* Look ahead vector if != NULL */
|
||||
char *llign; /* Ignore char vec if != NULL */
|
||||
char *llbrk; /* Break char vec if != NULL */
|
||||
char *llill; /* Illegal char vec if != NULL */
|
||||
};
|
||||
|
||||
extern struct lextab *_tabp;
|
||||
|
||||
/* extern FILE *lexin; */ /* scanner input file */
|
||||
|
||||
/*PLB #define lexval yylval */
|
||||
#define LEXERR 256
|
||||
#define LEXSKIP (-1)
|
||||
/*
|
||||
* #define LEXECHO(fp) {lexecho((fp));}
|
||||
*/
|
||||
extern int lexval;
|
||||
extern int yyline;
|
||||
|
||||
extern char llbuf[];
|
||||
extern char *llend;
|
||||
#define lextext llbuf
|
||||
#define lexlast llend
|
||||
|
||||
#define _lmovb _lmvb
|
||||
#define _lmovi _lmvi
|
||||
250
c20/lex/base.c
Normal file
250
c20/lex/base.c
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*
|
||||
* Modified 02-Dec-80 Bob Denny -- Conditionalize debug code to reduce size
|
||||
* More 29-May-81 Bob Denny -- RSX overlaying
|
||||
* More 19-Mar-82 Bob Denny -- New C library & compiler
|
||||
* More 28-Aug-82 Bob Denny -- Reference "a" to shut up compiler
|
||||
*/
|
||||
|
||||
/*
|
||||
* lex -- find and set base values for `move' vector
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
extern struct set *chase();
|
||||
|
||||
/*
|
||||
* Choose the best default
|
||||
* state for `st'.
|
||||
* Only states previous to the
|
||||
* current state are considered,
|
||||
* as these are guaranteed to
|
||||
* exist.
|
||||
*/
|
||||
struct dfa *
|
||||
defalt(st, xsep)
|
||||
struct dfa *st;
|
||||
struct xset **xsep;
|
||||
{
|
||||
register struct dfa *dp;
|
||||
register unsigned minv, u;
|
||||
struct dfa *def;
|
||||
struct xset *xse;
|
||||
int i;
|
||||
|
||||
xse = *xsep;
|
||||
if ((i = xse-sets)==0)
|
||||
return(NULL);
|
||||
#ifdef DEBUG
|
||||
if (lldebug>1)
|
||||
fprintf(stderr, "State %d, default:\n", st-dfa);
|
||||
#endif
|
||||
minv = -1;
|
||||
def = NULL;
|
||||
for (dp = dfa; dp < st; dp++) {
|
||||
u = compat(st, dp, xse);
|
||||
#ifdef DEBUG
|
||||
if (lldebug > 1)
|
||||
fprintf(stderr, "\t%d rates %d\n", dp-dfa, u);
|
||||
#endif
|
||||
if (u < minv) {
|
||||
def = dp;
|
||||
minv = u;
|
||||
}
|
||||
}
|
||||
if (minv == -1 || 10*(i-(int)minv) < i)
|
||||
def = NULL;
|
||||
#ifdef DEBUG
|
||||
if (lldebug>1 && def)
|
||||
fprintf(stderr, "\t%d chosen\n", def-dfa);
|
||||
#endif
|
||||
if (def)
|
||||
resolve(st, def, xsep);
|
||||
return(def);
|
||||
}
|
||||
|
||||
/*
|
||||
* State `b' is compatible with,
|
||||
* and hence a suitable default state
|
||||
* for state `a',
|
||||
* if its transitions agree with
|
||||
* those of `a', except those for
|
||||
* which `a' has transitions to the
|
||||
* (alleged) default.
|
||||
* Circularity of the default
|
||||
* relation is also not allowed.
|
||||
* If the state `b' has at least
|
||||
* twice as many transitions as `a',
|
||||
* it is not even worth considering.
|
||||
*/
|
||||
compat(a, b, xse)
|
||||
struct dfa *a, *b;
|
||||
struct xset *xse;
|
||||
{
|
||||
register struct dfa *dp;
|
||||
struct xset *xs;
|
||||
register nt;
|
||||
|
||||
if (a==b || b->df_ntrans >= a->df_ntrans*2)
|
||||
return(-1);
|
||||
for (dp = b; dp; dp = dp->df_default)
|
||||
if (dp == a)
|
||||
return(-1);
|
||||
nt = b->df_ntrans + a->df_ntrans;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
if (chase(b, xs->x_char) == xs->x_set)
|
||||
nt -= 2;
|
||||
return(nt);
|
||||
}
|
||||
|
||||
struct set *
|
||||
chase(st, c)
|
||||
register struct dfa *st;
|
||||
register c;
|
||||
{
|
||||
register struct move *dp;
|
||||
|
||||
c &= 0377;
|
||||
while ((dp = st->df_base) != NULL &&
|
||||
((dp += c) >= st->df_max || dp->m_check != st))
|
||||
if ((st = st->df_default) == NULL)
|
||||
return(NULL);
|
||||
if (dp)
|
||||
dp = dp->m_next;
|
||||
return(dp);
|
||||
}
|
||||
|
||||
/*
|
||||
* set `sets' to indicate those
|
||||
* characters on which the state `a'
|
||||
* and its default agree and
|
||||
* those characters on which `a'
|
||||
* should go to `error' (as the default
|
||||
* accepts it, but `a' does not).
|
||||
*/
|
||||
resolve(a, def, xsep)
|
||||
struct dfa *a, *def;
|
||||
struct xset **xsep;
|
||||
{
|
||||
register struct move *dp;
|
||||
register c, i;
|
||||
struct xset *xs, *xse;
|
||||
|
||||
a = a; /* Quiet compiler the easy way */
|
||||
|
||||
xse = *xsep;
|
||||
i = xse-sets;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
xs->x_defsame = 0;
|
||||
for (; def; def = def->df_default)
|
||||
for (dp = def->df_base; dp < def->df_max; dp++)
|
||||
if (dp->m_check == def) {
|
||||
c = dp - def->df_base;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
if (c==(xs->x_char&0377)) {
|
||||
if (xs->x_set==dp->m_next) {
|
||||
xs->x_defsame++;
|
||||
i--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (xs >= xse) {
|
||||
xs->x_defsame = 0;
|
||||
xs->x_char = c;
|
||||
xs->x_set = NULL;
|
||||
i++;
|
||||
xse++;
|
||||
}
|
||||
}
|
||||
*xsep = xse;
|
||||
return(i);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose a base in `move'
|
||||
* for the current state.
|
||||
* The transitions of that
|
||||
* state are in the vector
|
||||
* `sets'.
|
||||
*/
|
||||
struct move *
|
||||
stbase(xse)
|
||||
struct xset *xse;
|
||||
{
|
||||
register a;
|
||||
register struct move *base;
|
||||
register conflicts;
|
||||
struct xset *xs;
|
||||
|
||||
if (xse==sets)
|
||||
return(NULL);
|
||||
base = move;
|
||||
do {
|
||||
if (base-move >= NNEXT) {
|
||||
error("No space in `move' (stbase)");
|
||||
#ifdef DEBUG
|
||||
if (lldebug>1)
|
||||
dfaprint();
|
||||
#endif
|
||||
exit(1);
|
||||
}
|
||||
conflicts = 0;
|
||||
for (xs = sets; xs < xse; xs++) {
|
||||
a = xs->x_char&0377;
|
||||
if (xs->x_defsame==0 &&
|
||||
(base+a>=move+NNEXT || base[a].m_check!=NULL)) {
|
||||
conflicts++;
|
||||
base++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (conflicts);
|
||||
return(base);
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a state,
|
||||
* its `base' value in `move',
|
||||
* and the set of transitions in
|
||||
* `sets' (ending near `xse'),
|
||||
* set the `move' values.
|
||||
*/
|
||||
setbase(st, base, xse)
|
||||
struct dfa *st;
|
||||
register struct move *base;
|
||||
struct xset *xse;
|
||||
{
|
||||
register struct move *dp;
|
||||
register struct xset *xs;
|
||||
struct move *maxdp;
|
||||
|
||||
st->df_base = base;
|
||||
st->df_max = base;
|
||||
#ifdef DEBUG
|
||||
if (lldebug>1)
|
||||
fprintf(stderr, "Setbase: state %d\n", st-dfa);
|
||||
if (lldebug>1 && base==0)
|
||||
fprintf(stderr, "\tno base\n");
|
||||
#endif
|
||||
if (base==NULL)
|
||||
return;
|
||||
maxdp = base;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
if (xs->x_defsame==0) {
|
||||
dp = base + (xs->x_char&0377);
|
||||
if (dp > maxdp)
|
||||
maxdp = dp;
|
||||
dp->m_next = xs->x_set;
|
||||
dp->m_check = st;
|
||||
if (dp-move > llnxtmax)
|
||||
llnxtmax = dp-move;
|
||||
#ifdef DEBUG
|
||||
if (lldebug>1)
|
||||
fprintf(stderr, "\t%c nets %d\n",
|
||||
xs->x_char&0377, dp-move);
|
||||
#endif
|
||||
}
|
||||
st->df_max = maxdp+1;
|
||||
}
|
||||
250
c20/lex/base.old
Normal file
250
c20/lex/base.old
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*
|
||||
* Modified 02-Dec-80 Bob Denny -- Conditionalize debug code to reduce size
|
||||
* More 29-May-81 Bob Denny -- RSX overlaying
|
||||
* More 19-Mar-82 Bob Denny -- New C library & compiler
|
||||
* More 28-Aug-82 Bob Denny -- Reference "a" to shut up compiler
|
||||
*/
|
||||
|
||||
/*
|
||||
* lex -- find and set base values for `move' vector
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
extern struct set *chase();
|
||||
|
||||
/*
|
||||
* Choose the best default
|
||||
* state for `st'.
|
||||
* Only states previous to the
|
||||
* current state are considered,
|
||||
* as these are guaranteed to
|
||||
* exist.
|
||||
*/
|
||||
struct dfa *
|
||||
defalt(st, xsep)
|
||||
struct dfa *st;
|
||||
struct xset **xsep;
|
||||
{
|
||||
register struct dfa *dp;
|
||||
register unsigned minv, u;
|
||||
struct dfa *def;
|
||||
struct xset *xse;
|
||||
int i;
|
||||
|
||||
xse = *xsep;
|
||||
if ((i = xse-sets)==0)
|
||||
return(NULL);
|
||||
#ifdef DEBUG
|
||||
if (lldebug>1)
|
||||
fprintf(stderr, "State %d, default:\n", st-dfa);
|
||||
#endif
|
||||
minv = -1;
|
||||
def = NULL;
|
||||
for (dp = dfa; dp < st; dp++) {
|
||||
u = compat(st, dp, xse);
|
||||
#ifdef DEBUG
|
||||
if (lldebug > 1)
|
||||
fprintf(stderr, "\t%d rates %d\n", dp-dfa, u);
|
||||
#endif
|
||||
if (u < minv) {
|
||||
def = dp;
|
||||
minv = u;
|
||||
}
|
||||
}
|
||||
if (minv == -1 || 10*(i-(int)minv) < i)
|
||||
def = NULL;
|
||||
#ifdef DEBUG
|
||||
if (lldebug>1 && def)
|
||||
fprintf(stderr, "\t%d chosen\n", def-dfa);
|
||||
#endif
|
||||
if (def)
|
||||
resolve(st, def, xsep);
|
||||
return(def);
|
||||
}
|
||||
|
||||
/*
|
||||
* State `b' is compatible with,
|
||||
* and hence a suitable default state
|
||||
* for state `a',
|
||||
* if its transitions agree with
|
||||
* those of `a', except those for
|
||||
* which `a' has transitions to the
|
||||
* (alleged) default.
|
||||
* Circularity of the default
|
||||
* relation is also not allowed.
|
||||
* If the state `b' has at least
|
||||
* twice as many transitions as `a',
|
||||
* it is not even worth considering.
|
||||
*/
|
||||
compat(a, b, xse)
|
||||
struct dfa *a, *b;
|
||||
struct xset *xse;
|
||||
{
|
||||
register struct dfa *dp;
|
||||
struct xset *xs;
|
||||
register nt;
|
||||
|
||||
if (a==b || b->df_ntrans >= a->df_ntrans*2)
|
||||
return(-1);
|
||||
for (dp = b; dp; dp = dp->df_default)
|
||||
if (dp == a)
|
||||
return(-1);
|
||||
nt = b->df_ntrans + a->df_ntrans;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
if (chase(b, xs->x_char) == xs->x_set)
|
||||
nt -= 2;
|
||||
return(nt);
|
||||
}
|
||||
|
||||
struct set *
|
||||
chase(st, c)
|
||||
register struct dfa *st;
|
||||
register c;
|
||||
{
|
||||
register struct move *dp;
|
||||
|
||||
c &= 0377;
|
||||
while ((dp = st->df_base) != NULL &&
|
||||
((dp += c) >= st->df_max || dp->m_check != st))
|
||||
if ((st = st->df_default) == NULL)
|
||||
return(NULL);
|
||||
if (dp)
|
||||
dp = dp->m_next;
|
||||
return(dp);
|
||||
}
|
||||
|
||||
/*
|
||||
* set `sets' to indicate those
|
||||
* characters on which the state `a'
|
||||
* and its default agree and
|
||||
* those characters on which `a'
|
||||
* should go to `error' (as the default
|
||||
* accepts it, but `a' does not).
|
||||
*/
|
||||
resolve(a, def, xsep)
|
||||
struct dfa *a, *def;
|
||||
struct xset **xsep;
|
||||
{
|
||||
register struct move *dp;
|
||||
register c, i;
|
||||
struct xset *xs, *xse;
|
||||
|
||||
a = a; /* Quiet compiler the easy way */
|
||||
|
||||
xse = *xsep;
|
||||
i = xse-sets;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
xs->x_defsame = 0;
|
||||
for (; def; def = def->df_default)
|
||||
for (dp = def->df_base; dp < def->df_max; dp++)
|
||||
if (dp->m_check == def) {
|
||||
c = dp - def->df_base;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
if (c==(xs->x_char&0377)) {
|
||||
if (xs->x_set==dp->m_next) {
|
||||
xs->x_defsame++;
|
||||
i--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (xs >= xse) {
|
||||
xs->x_defsame = 0;
|
||||
xs->x_char = c;
|
||||
xs->x_set = NULL;
|
||||
i++;
|
||||
xse++;
|
||||
}
|
||||
}
|
||||
*xsep = xse;
|
||||
return(i);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose a base in `move'
|
||||
* for the current state.
|
||||
* The transitions of that
|
||||
* state are in the vector
|
||||
* `sets'.
|
||||
*/
|
||||
struct move *
|
||||
stbase(xse)
|
||||
struct xset *xse;
|
||||
{
|
||||
register a;
|
||||
register struct move *base;
|
||||
register conflicts;
|
||||
struct xset *xs;
|
||||
|
||||
if (xse==sets)
|
||||
return(NULL);
|
||||
base = move;
|
||||
do {
|
||||
if (base-move >= NNEXT) {
|
||||
error("No space in `move' (stbase)");
|
||||
#ifdef DEBUG
|
||||
if (lldebug>1)
|
||||
dfaprint();
|
||||
#endif
|
||||
exit(1);
|
||||
}
|
||||
conflicts = 0;
|
||||
for (xs = sets; xs < xse; xs++) {
|
||||
a = xs->x_char&0377;
|
||||
if (xs->x_defsame==0 &&
|
||||
(base+a>=move+NNEXT || base[a].m_check!=NULL)) {
|
||||
conflicts++;
|
||||
base++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (conflicts);
|
||||
return(base);
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a state,
|
||||
* its `base' value in `move',
|
||||
* and the set of transitions in
|
||||
* `sets' (ending near `xse'),
|
||||
* set the `move' values.
|
||||
*/
|
||||
setbase(st, base, xse)
|
||||
struct dfa *st;
|
||||
register struct move *base;
|
||||
struct xset *xse;
|
||||
{
|
||||
register struct move *dp;
|
||||
register struct xset *xs;
|
||||
struct move *maxdp;
|
||||
|
||||
st->df_base = base;
|
||||
st->df_max = base;
|
||||
#ifdef DEBUG
|
||||
if (lldebug>1)
|
||||
fprintf(stderr, "Setbase: state %d\n", st-dfa);
|
||||
if (lldebug>1 && base==0)
|
||||
fprintf(stderr, "\tno base\n");
|
||||
#endif
|
||||
if (base==NULL)
|
||||
return;
|
||||
maxdp = base;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
if (xs->x_defsame==0) {
|
||||
dp = base + (xs->x_char&0377);
|
||||
if (dp > maxdp)
|
||||
maxdp = dp;
|
||||
dp->m_next = xs->x_set;
|
||||
dp->m_check = st;
|
||||
if (dp-move > llnxtmax)
|
||||
llnxtmax = dp-move;
|
||||
#ifdef DEBUG
|
||||
if (lldebug>1)
|
||||
fprintf(stderr, "\t%c nets %d\n",
|
||||
xs->x_char&0377, dp-move);
|
||||
#endif
|
||||
}
|
||||
st->df_max = maxdp+1;
|
||||
}
|
||||
149
c20/lex/bcpl.lxi
Normal file
149
c20/lex/bcpl.lxi
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* bcpl syntax
|
||||
*/
|
||||
digit = [0-9];
|
||||
letter = [a-zA-Z_];
|
||||
name = letter (letter|digit)*;
|
||||
integer = [123456789]digit*;
|
||||
hexdigit = [0-9a-fA-F];
|
||||
octal = #[0-7][0-7]*;
|
||||
hex = #[xX]hexdigit*;
|
||||
realdigits = integer "." [0-9]*
|
||||
| "." [0-9][0-9]*
|
||||
;
|
||||
real = realdigits ("e" ([+-]|"") integer | "");
|
||||
any = [\n\t \014];
|
||||
illegal = [^a-zA-Z\n\t \014#+-*/^%0-9~!=<>:'"&|()[\]{}`@?,.];
|
||||
%%
|
||||
AND {return(AND);}
|
||||
BE {return(BE);}
|
||||
BREAK {return(BREAK);}
|
||||
BY {return(BY);}
|
||||
CASE {return(CASE);}
|
||||
DO {return(DO);}
|
||||
DEFAULT {return(DEFAULT);}
|
||||
EQ {return('=');}
|
||||
EQV {return(EQV);}
|
||||
ELSE {return(OR);}
|
||||
ENDCASE {return(ENDCASE);}
|
||||
FALSE {return(FALSE);}
|
||||
FOR {return(FOR);}
|
||||
FINISH {return(FINISH);}
|
||||
GOTO {return(GOTO);}
|
||||
GE {return(GE);}
|
||||
GR {return('>');}
|
||||
GLOBAL {return(GLOBAL);}
|
||||
GET {return(GET);}
|
||||
IF {return(IF);}
|
||||
INTO {return(INTO);}
|
||||
LET {return(LET);}
|
||||
LV {return('@');}
|
||||
LE {return(LE);}
|
||||
LS {return('<');}
|
||||
LOGOR {return('|');}
|
||||
LOGAND {return('&');}
|
||||
LOOP {return(LOOP);}
|
||||
LSHIFT {return(LSHIFT);}
|
||||
MANIFEST {return(MANIFEST);}
|
||||
NE {return(NE);}
|
||||
NOT {return('~');}
|
||||
NEQV {return(NEQV);}
|
||||
OR {return(OR);}
|
||||
RESULTIS {return(RESULTIS);}
|
||||
RETURN {return(RETURN);}
|
||||
REM {return(REM);}
|
||||
RSHIFT {return(RSHIFT);}
|
||||
RV {return('!');}
|
||||
REPEAT {return(REPEAT);}
|
||||
REPEATWHILE {return(REPEATWHILE);}
|
||||
REPEATUNTIL {return(REPEATUNTIL);}
|
||||
SWITCHON {return(SWITCHON);}
|
||||
STATIC {return(STATIC);}
|
||||
TO {return(TO);}
|
||||
TEST {return(TEST);}
|
||||
TRUE {return(TRUE);}
|
||||
THEN {return(THEN);}
|
||||
TABLE {return(TABLE);}
|
||||
UNTIL {return(UNTIL);}
|
||||
UNLESS {return(UNLESS);}
|
||||
VEC {return(VEC);}
|
||||
VALOF {return(VALOF);}
|
||||
WHILE {return(WHILE);}
|
||||
|
||||
name {
|
||||
gettoken(token, sizeof token);
|
||||
lexval = lookup(token, 0);
|
||||
return(IDENTIFIER);
|
||||
}
|
||||
hex {return(number(16));}
|
||||
octal {return(number(8));}
|
||||
integer {return(number(10));}
|
||||
|
||||
"<" {single: return(*token(0));}
|
||||
">" {goto single;}
|
||||
"%" {goto single;}
|
||||
"/" {goto single;}
|
||||
"*" {goto single;}
|
||||
"&" {goto single;}
|
||||
"|" {goto single;}
|
||||
"^" {goto single;}
|
||||
"+" {goto single;}
|
||||
"-" {goto single;}
|
||||
"!" {goto single;}
|
||||
"@" {goto single;}
|
||||
"~" {goto single;}
|
||||
"(" {goto single;}
|
||||
")" {goto single;}
|
||||
"{" {goto single;}
|
||||
"}" {goto single;}
|
||||
":" {goto single;}
|
||||
";" {goto single;}
|
||||
"," {goto single;}
|
||||
|
||||
":=" {return(GETS);}
|
||||
"<=" {return(LE);}
|
||||
"~=" {return(NE);}
|
||||
">=" {return(GE);}
|
||||
"<<" {return(LS);}
|
||||
">>" {return(RS);}
|
||||
"&&" {return('&');}
|
||||
"||" {return('|');}
|
||||
"$(" {return('{');}
|
||||
"$)" {return('}');}
|
||||
"->" {return(ARROW);}
|
||||
|
||||
"+:=" {return(ASPLUS);}
|
||||
"-:=" {return(ASMINUS);}
|
||||
"/:=" {return(ASDIV);}
|
||||
"REM:=" {return(ASMOD);}
|
||||
"*:=" {return(ASTIMES);}
|
||||
"<<:=" {return(ASLSHIFT);}
|
||||
">>:=" {return(ASRSHIFT);}
|
||||
"|:=" {return(ASOR);}
|
||||
"&:=" {return(ASAND);}
|
||||
"NEQV:=" {return(ASEXOR);}
|
||||
|
||||
"/*" {comment("*/");}
|
||||
"'" {;}
|
||||
"\"" {
|
||||
lexval = calloc(2, sizeof lexval);
|
||||
string(lexval);
|
||||
return(STRING);
|
||||
}
|
||||
any {
|
||||
gettoken(token, sizeof token);
|
||||
c = *token;
|
||||
if (c=='\n')
|
||||
yyline++;
|
||||
}
|
||||
%%
|
||||
|
||||
number(radix)
|
||||
{
|
||||
long l;
|
||||
char digits[30];
|
||||
|
||||
gettoken(digits, sizeof digits);
|
||||
l = integ(digits, radix);
|
||||
return(l);
|
||||
}
|
||||
170
c20/lex/btob.c
Normal file
170
c20/lex/btob.c
Normal file
@@ -0,0 +1,170 @@
|
||||
#
|
||||
#include <stdio.h>
|
||||
#include <lex.h>
|
||||
|
||||
extern int _lmovb();
|
||||
|
||||
#line 4 "BTOB.LXI"
|
||||
|
||||
struct maptab {
|
||||
char *old;
|
||||
char *new;
|
||||
} maptab[] {
|
||||
"=+", "+=",
|
||||
"=-", "-=",
|
||||
"=*", "*=",
|
||||
"=%", "%=",
|
||||
"=&", "&=",
|
||||
"=|", "|=",
|
||||
"=<<", "<<=",
|
||||
"=>>", ">>=",
|
||||
"=/", "/=",
|
||||
"=^", "^=",
|
||||
0,
|
||||
};
|
||||
struct maptab *mp;
|
||||
char tbuf[10];
|
||||
char *token();
|
||||
|
||||
main()
|
||||
{
|
||||
while (yylex())
|
||||
;
|
||||
}
|
||||
_Alextab(__na__) {
|
||||
switch (__na__) {
|
||||
case 0:
|
||||
|
||||
#line 33 "BTOB.LXI"
|
||||
|
||||
gettoken(tbuf, sizeof tbuf);
|
||||
for (mp = maptab; mp->old; mp++)
|
||||
if (equal(tbuf, mp->old)) {
|
||||
printf("%s", mp->new);
|
||||
break;
|
||||
}
|
||||
if (mp->old==0)
|
||||
fprintf(stderr, "error\n");
|
||||
return(1);
|
||||
|
||||
break;
|
||||
case 1:
|
||||
|
||||
#line 44 "BTOB.LXI"
|
||||
|
||||
relat:
|
||||
gettoken(tbuf, sizeof tbuf);
|
||||
printf(tbuf);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
|
||||
#line 49 "BTOB.LXI"
|
||||
goto relat;
|
||||
break;
|
||||
case 3:
|
||||
|
||||
#line 50 "BTOB.LXI"
|
||||
printf("="); return(1);
|
||||
break;
|
||||
case 4:
|
||||
|
||||
#line 51 "BTOB.LXI"
|
||||
putchar(*token(NULL)); return(1);
|
||||
break;
|
||||
}
|
||||
return(LEXSKIP);
|
||||
}
|
||||
|
||||
#line 52 "BTOB.LXI"
|
||||
|
||||
int _Flextab[] {
|
||||
-1, 4, 4, 1, 4, 0, 0, 0, 0, 0, 0, 2051, 0, 2051, 0, 2,
|
||||
0, 2, 0, -1,
|
||||
};
|
||||
|
||||
#line 52 "BTOB.LXI"
|
||||
|
||||
#define LLTYPE1 char
|
||||
|
||||
LLTYPE1 _Nlextab[] {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 2, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
3, 8, 7, 11, 13, 16, 14, 12, 18, 10, 19, 9, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 17, 3, 15, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 5, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 6,
|
||||
};
|
||||
|
||||
LLTYPE1 _Clextab[] {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
2, 4, 4, 10, 12, 15, 4, 4, 17, 4, -1, 4, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, 4, 4, 4, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, 4,
|
||||
};
|
||||
|
||||
LLTYPE1 _Dlextab[] {
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19,
|
||||
};
|
||||
|
||||
int _Blextab[] {
|
||||
0, 0, 195, 0, 220, 0, 0, 0, 0, 0, 214, 0, 217, 0, 0, 199,
|
||||
0, 204, 0, 0,
|
||||
};
|
||||
char *llsave[1];
|
||||
|
||||
int _Llextab[] {
|
||||
00, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,
|
||||
00, 00, 00, 0,
|
||||
};
|
||||
|
||||
struct lextab lextab {
|
||||
19, /* last state */
|
||||
_Dlextab, /* defaults */
|
||||
_Nlextab, /* next */
|
||||
_Clextab, /* check */
|
||||
_Blextab, /* base */
|
||||
344, /* last in base */
|
||||
_lmovb, /* byte-int move routines */
|
||||
_Flextab, /* final state descriptions */
|
||||
_Alextab, /* action routine */
|
||||
_Llextab, /* look-ahead vector */
|
||||
0, /* no ignore class */
|
||||
0, /* no break class */
|
||||
0, /* no illegal class */
|
||||
};
|
||||
51
c20/lex/btob.lxi
Normal file
51
c20/lex/btob.lxi
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* btob -- convert old b operators to new b form
|
||||
*/
|
||||
%{
|
||||
struct maptab {
|
||||
char *old;
|
||||
char *new;
|
||||
} maptab[] {
|
||||
"=+", "+=",
|
||||
"=-", "-=",
|
||||
"=*", "*=",
|
||||
"=%", "%=",
|
||||
"=&", "&=",
|
||||
"=|", "|=",
|
||||
"=<<", "<<=",
|
||||
"=>>", ">>=",
|
||||
"=/", "/=",
|
||||
"=^", "^=",
|
||||
0,
|
||||
};
|
||||
struct maptab *mp;
|
||||
char tbuf[10];
|
||||
char *token();
|
||||
|
||||
main()
|
||||
{
|
||||
while (yylex())
|
||||
;
|
||||
}
|
||||
%}
|
||||
%%
|
||||
|
||||
"=" (<< | >> | "*" | + | - | "/" | "%" | "&" | "|" | "^") {
|
||||
gettoken(tbuf, sizeof tbuf);
|
||||
for (mp = maptab; mp->old; mp++)
|
||||
if (equal(tbuf, mp->old)) {
|
||||
printf("%s", mp->new);
|
||||
break;
|
||||
}
|
||||
if (mp->old==0)
|
||||
fprintf(stderr, "error\n");
|
||||
return(1);
|
||||
}
|
||||
[<=>!]"=" {
|
||||
relat:
|
||||
gettoken(tbuf, sizeof tbuf);
|
||||
printf(tbuf);
|
||||
}
|
||||
"="[<>] {goto relat;}
|
||||
"=" / (++ | --) {printf("="); return(1);}
|
||||
[\0-\377] {putchar(*token(NULL)); return(1);}
|
||||
177
c20/lex/cap.c
Normal file
177
c20/lex/cap.c
Normal file
@@ -0,0 +1,177 @@
|
||||
#include <stdio.h>
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
extern int _lmovb();
|
||||
|
||||
#line 10 "cap.lxi"
|
||||
|
||||
extern char *token();
|
||||
|
||||
main()
|
||||
{
|
||||
while (yylex())
|
||||
;
|
||||
}
|
||||
extern struct lextab cap;
|
||||
|
||||
/* Standard I/O selected */
|
||||
extern FILE *lexin;
|
||||
|
||||
llstin()
|
||||
{
|
||||
if(lexin == NULL)
|
||||
lexin = stdin;
|
||||
if(_tabp == NULL)
|
||||
lexswitch(&cap);
|
||||
}
|
||||
|
||||
_Acap(__na__) /* Action routine */
|
||||
{
|
||||
|
||||
#line 20 "cap.lxi"
|
||||
|
||||
register char *cp;
|
||||
char *et;
|
||||
switch (__na__) {
|
||||
case 0:
|
||||
|
||||
#line 25 "cap.lxi"
|
||||
|
||||
cp = token(&et);
|
||||
while (cp < et)
|
||||
putchar(*cp++);
|
||||
|
||||
break;
|
||||
case 1:
|
||||
|
||||
#line 30 "cap.lxi"
|
||||
putchar(token(0)[1]);
|
||||
break;
|
||||
case 2:
|
||||
|
||||
#line 31 "cap.lxi"
|
||||
putchar(*token(0)+'a'-'A');
|
||||
break;
|
||||
case 3:
|
||||
|
||||
#line 32 "cap.lxi"
|
||||
putchar(*token(0));
|
||||
break;
|
||||
}
|
||||
return(LEXSKIP);
|
||||
}
|
||||
|
||||
#line 33 "cap.lxi"
|
||||
|
||||
|
||||
int _Fcap[] = {
|
||||
-1, 3, 2, 3, 1, 3, -1, 0, -1, -1, -1, -1, 3, -1, -1, -1,
|
||||
-1,
|
||||
};
|
||||
|
||||
#line 34 "cap.lxi"
|
||||
|
||||
#define LLTYPE1 char
|
||||
|
||||
LLTYPE1 _Ncap[] = {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 5, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 12, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5,
|
||||
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 8, 14, 6, 15, 16,
|
||||
8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
9, 16, 11, 10, 16, 16, 16, 11, 16, 11, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 8, 16, 16, 16, 16, 8, 8, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 16, 16,
|
||||
6, 16, 16, 16, 16, 16, 16, 16, 6, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 10, 16, 8, 9, 16, 11, 16, 8, 8, 16, 11, 9, 11,
|
||||
11, 16, 16, 16, 16, 11, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 13, 8,
|
||||
16, 16, 16, 16, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7,
|
||||
};
|
||||
|
||||
LLTYPE1 _Ccap[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 6, 13, 9, 14, -1,
|
||||
6, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
5, -1, 5, 9, -1, -1, -1, 5, -1, 5, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 8, -1, -1, -1, -1, 8, 8, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, -1, -1,
|
||||
11, -1, -1, -1, -1, -1, -1, -1, 12, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, 10, -1, 10, 11, -1, 11, -1, 10, 10, -1, 11, 12, 11,
|
||||
12, -1, -1, -1, -1, 12, -1, 12, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 12, 15,
|
||||
-1, -1, -1, -1, 15, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15,
|
||||
};
|
||||
|
||||
LLTYPE1 _Dcap[] = {
|
||||
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||
|
||||
};
|
||||
|
||||
int _Bcap[] = {
|
||||
0, 0, 0, 191, 0, 272, 249, 0, 306, 275, 387, 390, 398, 204, 276, 445,
|
||||
0,
|
||||
};
|
||||
|
||||
struct lextab cap = {
|
||||
16, /* last state */
|
||||
_Dcap, /* defaults */
|
||||
_Ncap, /* next */
|
||||
_Ccap, /* check */
|
||||
_Bcap, /* base */
|
||||
535, /* last in base */
|
||||
_lmovb, /* byte-int move routines */
|
||||
_Fcap, /* final state descriptions */
|
||||
_Acap, /* action routine */
|
||||
NULL, /* look-ahead vector */
|
||||
0, /* no ignore class */
|
||||
0, /* no break class */
|
||||
0, /* no illegal class */
|
||||
};
|
||||
33
c20/lex/cap.lxi
Normal file
33
c20/lex/cap.lxi
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* capitalise things
|
||||
*/
|
||||
|
||||
letter = [A-Z];
|
||||
open = ["'(];
|
||||
close = ["')];
|
||||
any = [\0-\377];
|
||||
eos = [.?!];
|
||||
%{
|
||||
extern char *token();
|
||||
|
||||
main()
|
||||
{
|
||||
while (yylex())
|
||||
;
|
||||
}
|
||||
%}
|
||||
%%
|
||||
%{
|
||||
register char *cp;
|
||||
char *et;
|
||||
%}
|
||||
|
||||
(".PP\n"|eos close* " "* (" "|"\n"))open*letter {
|
||||
cp = token(&et);
|
||||
while (cp < et)
|
||||
putchar(*cp++);
|
||||
}
|
||||
$letter {putchar(token(0)[1]);}
|
||||
letter {putchar(*token(0)+'a'-'A');}
|
||||
any {putchar(*token(0));}
|
||||
%%
|
||||
4
c20/lex/cap.stinkr
Normal file
4
c20/lex/cap.stinkr
Normal file
@@ -0,0 +1,4 @@
|
||||
x clib:stdio
|
||||
x lex:lexlib
|
||||
l cap
|
||||
o cap.exe
|
||||
539
c20/lex/clex.c
Normal file
539
c20/lex/clex.c
Normal file
@@ -0,0 +1,539 @@
|
||||
#include <stdio.h>
|
||||
#include <lex.h>
|
||||
|
||||
extern int _lmovb();
|
||||
|
||||
#line 4 "CLEX.LXI"
|
||||
|
||||
extern char *install();
|
||||
|
||||
#line 11 "CLEX.LXI"
|
||||
|
||||
main()
|
||||
{
|
||||
register int i;
|
||||
char buffer[80];
|
||||
extern char *token();
|
||||
|
||||
while (i = yylex()) {
|
||||
gettoken(buffer, sizeof buffer);
|
||||
printf("yylex returns %d, token = \"%s\"\n",
|
||||
i, buffer);
|
||||
if (i == LEXERR) {
|
||||
error("LEXERR -- abort");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_Alextab(__na__) {
|
||||
|
||||
#line 30 "CLEX.LXI"
|
||||
|
||||
register int c;
|
||||
switch (__na__) {
|
||||
case 0:
|
||||
|
||||
#line 33 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 1:
|
||||
|
||||
#line 34 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 2:
|
||||
|
||||
#line 35 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 3:
|
||||
|
||||
#line 36 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 4:
|
||||
|
||||
#line 37 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 5:
|
||||
|
||||
#line 38 "CLEX.LXI"
|
||||
return(-1);
|
||||
break;
|
||||
case 6:
|
||||
|
||||
#line 39 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 7:
|
||||
|
||||
#line 40 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 8:
|
||||
|
||||
#line 41 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 9:
|
||||
|
||||
#line 42 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 10:
|
||||
|
||||
#line 43 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 11:
|
||||
|
||||
#line 44 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 12:
|
||||
|
||||
#line 45 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 13:
|
||||
|
||||
#line 46 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 14:
|
||||
|
||||
#line 47 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 15:
|
||||
|
||||
#line 48 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 16:
|
||||
|
||||
#line 49 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 17:
|
||||
|
||||
#line 50 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 18:
|
||||
|
||||
#line 51 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 19:
|
||||
|
||||
#line 52 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 20:
|
||||
|
||||
#line 53 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 21:
|
||||
|
||||
#line 54 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 22:
|
||||
|
||||
#line 55 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 23:
|
||||
|
||||
#line 56 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 24:
|
||||
|
||||
#line 57 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 25:
|
||||
|
||||
#line 58 "CLEX.LXI"
|
||||
|
||||
lexval = install();
|
||||
return(6);
|
||||
|
||||
break;
|
||||
case 26:
|
||||
|
||||
#line 62 "CLEX.LXI"
|
||||
|
||||
lexval = install();
|
||||
return(7);
|
||||
|
||||
break;
|
||||
case 27:
|
||||
|
||||
#line 66 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 28:
|
||||
|
||||
#line 67 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 29:
|
||||
|
||||
#line 68 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 30:
|
||||
|
||||
#line 69 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 31:
|
||||
|
||||
#line 70 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 32:
|
||||
|
||||
#line 71 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 33:
|
||||
|
||||
#line 72 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 34:
|
||||
|
||||
#line 73 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 35:
|
||||
|
||||
#line 74 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 36:
|
||||
|
||||
#line 75 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 37:
|
||||
|
||||
#line 76 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 38:
|
||||
|
||||
#line 77 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 39:
|
||||
|
||||
#line 78 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 40:
|
||||
|
||||
#line 79 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 41:
|
||||
|
||||
#line 80 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 42:
|
||||
|
||||
#line 81 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 43:
|
||||
|
||||
#line 82 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 44:
|
||||
|
||||
#line 83 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 45:
|
||||
|
||||
#line 84 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 46:
|
||||
|
||||
#line 85 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 47:
|
||||
|
||||
#line 86 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 48:
|
||||
|
||||
#line 87 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 49:
|
||||
|
||||
#line 88 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 50:
|
||||
|
||||
#line 89 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 51:
|
||||
|
||||
#line 90 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 52:
|
||||
|
||||
#line 91 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 53:
|
||||
|
||||
#line 92 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 54:
|
||||
|
||||
#line 93 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 55:
|
||||
|
||||
#line 94 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 56:
|
||||
|
||||
#line 95 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 57:
|
||||
|
||||
#line 96 "CLEX.LXI"
|
||||
|
||||
comment("*/");
|
||||
return(LEXSKIP);
|
||||
|
||||
break;
|
||||
case 58:
|
||||
|
||||
#line 100 "CLEX.LXI"
|
||||
|
||||
if ((c = mapch('\'', '\\')) != -1)
|
||||
while (mapch('\'', '\\') != -1)
|
||||
lexerror("Long character constant");
|
||||
printf("%c", c);
|
||||
return(__na__);
|
||||
|
||||
break;
|
||||
case 59:
|
||||
|
||||
#line 107 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 60:
|
||||
|
||||
#line 108 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 61:
|
||||
|
||||
#line 109 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 62:
|
||||
|
||||
#line 110 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 63:
|
||||
|
||||
#line 111 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 64:
|
||||
|
||||
#line 112 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 65:
|
||||
|
||||
#line 113 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 66:
|
||||
|
||||
#line 114 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 67:
|
||||
|
||||
#line 115 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 68:
|
||||
|
||||
#line 116 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 69:
|
||||
|
||||
#line 117 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
case 70:
|
||||
|
||||
#line 118 "CLEX.LXI"
|
||||
return(__na__);
|
||||
break;
|
||||
}
|
||||
return(LEXSKIP);
|
||||
}
|
||||
|
||||
#line 119 "CLEX.LXI"
|
||||
|
||||
char *
|
||||
install()
|
||||
/*
|
||||
* Install the current token in the symbol table
|
||||
*/
|
||||
{
|
||||
register char *buffer; /* Where to put the character */
|
||||
register char *first; /* -> first byte of the token */
|
||||
char *last; /* Can't be in a register */
|
||||
extern char *token();
|
||||
|
||||
first = token(&last); /* Find first/last of token */
|
||||
if ((buffer = alloc((last - first) + 1)) == NULL) {
|
||||
error("Out of space in install");
|
||||
exit(1);
|
||||
}
|
||||
first = copy(buffer, first, (last - first));
|
||||
*first = '\0';
|
||||
return(buffer);
|
||||
}
|
||||
|
||||
int _Flextab[] {
|
||||
-1, 70, 69, 68, 67, 66, 65, 62, 61, 60, 59, 58, 56, 55, 54, 53,
|
||||
50, 52, 49, 51, 46, 63, 45, 64, 41, 40, 57, 39, 32, 34, 31, -1,
|
||||
30, 29, 48, 47, -1, 44, -1, 43, 42, 38, 37, 36, 35, 27, 33, 28,
|
||||
26, 26, 25, 25, 25, 25, 25, 25, 25, 24, 25, 25, 25, 25, 25, 25,
|
||||
23, 25, 25, 21, 25, 25, 25, 25, 25, 25, 20, 19, 25, 25, 25, 25,
|
||||
17, 25, 25, 25, 25, 25, 25, 25, 18, 25, 25, 16, 25, 25, 25, 25,
|
||||
13, 25, 12, 25, 25, 25, 10, 25, 25, 25, 25, 25, 11, 25, 25, 25,
|
||||
25, 25, 9, 25, 25, 25, 14, 25, 25, 25, 25, 7, 25, 25, 25, 6,
|
||||
25, 25, 25, 25, 25, 22, 25, 25, 25, 25, 15, 25, 25, 25, 25, 8,
|
||||
25, 25, 25, 5, -1, -1, -1, -1, -1, -1, -1, 4, -1, -1, -1, 3,
|
||||
-1, -1, -1, -1, 2, -1, -1, 1, -1, -1, -1, -1, -1, 0, -1,
|
||||
};
|
||||
|
||||
#line 140 "CLEX.LXI"
|
||||
|
||||
#define LLTYPE1 char
|
||||
|
||||
LLTYPE1 _Nlextab[] {
|
||||
174, 174, 174, 174, 174, 174, 174, 174, 174, 7, 9, 174, 174, 174, 174, 174,
|
||||
174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174,
|
||||
8, 31, 10, 148, 50, 27, 22, 11, 6, 5, 24, 18, 12, 16, 13, 25,
|
||||
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 17, 15, 45, 33, 28, 14,
|
||||
19, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 4, 23, 3, 26, 50,
|
||||
32, 124, 76, 81, 68, 115, 65, 99, 50, 97, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 103, 128, 58, 53, 50, 92, 50, 50, 50, 2, 20, 1, 21, 30,
|
||||
29, 41, 34, 37, 39, 54, 40, 44, 55, 43, 56, 42, 46, 47, 49, 49,
|
||||
49, 49, 49, 49, 49, 49, 49, 49, 38, 57, 36, 59, 52, 60, 61, 62,
|
||||
63, 64, 66, 67, 70, 71, 72, 73, 51, 51, 51, 51, 51, 51, 51, 51,
|
||||
51, 51, 74, 77, 78, 79, 80, 83, 84, 52, 52, 52, 52, 52, 52, 52,
|
||||
52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
|
||||
52, 52, 52, 85, 86, 87, 88, 52, 35, 52, 52, 52, 52, 52, 52, 52,
|
||||
52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
|
||||
52, 52, 52, 69, 89, 90, 91, 93, 94, 95, 96, 98, 100, 75, 101, 102,
|
||||
104, 109, 82, 106, 107, 108, 110, 111, 112, 113, 114, 116, 117, 118, 105, 120,
|
||||
121, 122, 123, 125, 126, 127, 129, 119, 130, 131, 132, 133, 135, 136, 137, 138,
|
||||
140, 139, 141, 142, 134, 143, 145, 146, 147, 168, 160, 156, 151, 152, 149, 153,
|
||||
154, 144, 155, 150, 157, 158, 159, 165, 162, 161, 163, 164, 166, 167, 169, 170,
|
||||
171, 172, 173,
|
||||
};
|
||||
|
||||
LLTYPE1 _Clextab[] {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0,
|
||||
18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 25, 0,
|
||||
31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 28,
|
||||
28, 33, 33, 36, 38, 53, 33, 33, 54, 33, 55, 33, 45, 45, 48, 48,
|
||||
48, 48, 48, 48, 48, 48, 48, 48, 33, 56, 33, 58, 50, 59, 60, 61,
|
||||
62, 63, 65, 66, 69, 70, 71, 72, 50, 50, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 73, 76, 77, 78, 79, 82, 83, 50, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 50, 84, 85, 86, 87, 50, 33, 50, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 50, 68, 81, 89, 90, 92, 93, 94, 95, 97, 99, 68, 100, 101,
|
||||
103, 104, 81, 105, 106, 107, 109, 110, 111, 112, 113, 115, 116, 117, 104, 119,
|
||||
120, 121, 122, 124, 125, 126, 128, 115, 129, 130, 131, 132, 134, 135, 136, 137,
|
||||
139, 128, 140, 141, 128, 142, 144, 145, 146, 148, 148, 149, 150, 151, 148, 152,
|
||||
153, 139, 154, 149, 156, 157, 158, 160, 161, 160, 162, 163, 165, 166, 168, 169,
|
||||
170, 171, 172,
|
||||
};
|
||||
|
||||
LLTYPE1 _Dlextab[] {
|
||||
174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174,
|
||||
174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174,
|
||||
174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174,
|
||||
174, 48, 174, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
|
||||
50, 50, 50, 50, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174,
|
||||
174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174,
|
||||
};
|
||||
|
||||
int _Blextab[] {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
13, 0, 21, 0, 2, 0, 54, 0, 0, 52, 0, 0, 66, 0, 0, 35,
|
||||
0, 92, 0, 0, 69, 0, 72, 0, 0, 0, 0, 0, 0, 80, 0, 0,
|
||||
94, 0, 120, 0, 0, 23, 31, 27, 43, 0, 34, 45, 57, 59, 59, 59,
|
||||
0, 51, 49, 0, 142, 62, 68, 49, 59, 62, 0, 0, 65, 79, 84, 75,
|
||||
0, 147, 73, 68, 106, 102, 96, 113, 0, 130, 145, 0, 143, 143, 141, 149,
|
||||
0, 149, 0, 141, 138, 144, 0, 155, 154, 142, 146, 151, 0, 157, 148, 148,
|
||||
164, 152, 0, 159, 153, 168, 0, 155, 171, 159, 164, 0, 158, 160, 166, 0,
|
||||
173, 158, 180, 171, 181, 0, 179, 169, 187, 183, 0, 191, 174, 186, 194, 0,
|
||||
177, 196, 180, 0, 197, 197, 201, 193, 186, 204, 205, 0, 208, 208, 208, 0,
|
||||
203, 212, 209, 213, 0, 201, 216, 0, 217, 217, 215, 211, 221, 0, 0,
|
||||
};
|
||||
|
||||
struct lextab lextab {
|
||||
174, /* last state */
|
||||
_Dlextab, /* defaults */
|
||||
_Nlextab, /* next */
|
||||
_Clextab, /* check */
|
||||
_Blextab, /* base */
|
||||
322, /* last in base */
|
||||
_lmovb, /* byte-int move routines */
|
||||
_Flextab, /* final state descriptions */
|
||||
_Alextab, /* action routine */
|
||||
NULL, /* look-ahead vector */
|
||||
0, /* no ignore class */
|
||||
0, /* no break class */
|
||||
0, /* no illegal class */
|
||||
};
|
||||
139
c20/lex/clex.lxi
Normal file
139
c20/lex/clex.lxi
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* C lex
|
||||
*/
|
||||
%{
|
||||
extern char *install();
|
||||
%}
|
||||
digit = [0-9];
|
||||
letter = [a-zA-Z_$];
|
||||
name = letter (letter|digit)*;
|
||||
integer = digit digit*;
|
||||
%{
|
||||
main()
|
||||
{
|
||||
register int i;
|
||||
char buffer[80];
|
||||
extern char *token();
|
||||
|
||||
while (i = yylex()) {
|
||||
gettoken(buffer, sizeof buffer);
|
||||
printf("yylex returns %d, token = \"%s\"\n",
|
||||
i, buffer);
|
||||
if (i == LEXERR) {
|
||||
error("LEXERR -- abort");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
%}
|
||||
%%
|
||||
%{
|
||||
register int c;
|
||||
%}
|
||||
#DEFINE { return(__na__); }
|
||||
#ELSE { return(__na__); }
|
||||
#ENDIF { return(__na__); }
|
||||
#IFDEF { return(__na__); }
|
||||
#INCLUDE { return(__na__); }
|
||||
STRUCT { return(-1); }
|
||||
AUTO { return(__na__); }
|
||||
EXTERN { return(__na__); }
|
||||
STATIC { return(__na__); }
|
||||
REGISTER { return(__na__); }
|
||||
GOTO { return(__na__); }
|
||||
RETURN { return(__na__); }
|
||||
IF { return(__na__); }
|
||||
WHILE { return(__na__); }
|
||||
ELSE { return(__na__); }
|
||||
SWITCH { return(__na__); }
|
||||
CASE { return(__na__); }
|
||||
BREAK { return(__na__); }
|
||||
CONTINUE { return(__na__); }
|
||||
DO { return(__na__); }
|
||||
DEFAULT { return(__na__); }
|
||||
FOR { return(__na__); }
|
||||
SIZEOF { return(__na__); }
|
||||
TYPEDEF { return(__na__); }
|
||||
UNION { return(__na__); }
|
||||
name {
|
||||
lexval = install();
|
||||
return(6);
|
||||
}
|
||||
integer {
|
||||
lexval = install();
|
||||
return(7);
|
||||
}
|
||||
"<" { return(__na__); }
|
||||
"<=" { return(__na__); }
|
||||
"=" { return(__na__); }
|
||||
"!=" { return(__na__); }
|
||||
">=" { return(__na__); }
|
||||
">" { return(__na__); }
|
||||
"<<" { return(__na__); }
|
||||
">>" { return(__na__); }
|
||||
"=+" { return(__na__); }
|
||||
"=-" { return(__na__); }
|
||||
"=/" { return(__na__); }
|
||||
"=%" { return(__na__); }
|
||||
"%" { return(__na__); }
|
||||
"/" { return(__na__); }
|
||||
"*" { return(__na__); }
|
||||
"=*" { return(__na__); }
|
||||
"=<<" { return(__na__); }
|
||||
"=>>" { return(__na__); }
|
||||
"&" { return(__na__); }
|
||||
"|" { return(__na__); }
|
||||
"=|" { return(__na__); }
|
||||
"=&" { return(__na__); }
|
||||
"+" { return(__na__); }
|
||||
"-" { return(__na__); }
|
||||
"++" { return(__na__); }
|
||||
"--" { return(__na__); }
|
||||
";" { return(__na__); }
|
||||
"?" { return(__na__); }
|
||||
"." { return(__na__); }
|
||||
"," { return(__na__); }
|
||||
"/*" {
|
||||
comment("*/");
|
||||
return(LEXSKIP);
|
||||
}
|
||||
"'" {
|
||||
if ((c = mapch('\'', '\\')) != -1)
|
||||
while (mapch('\'', '\\') != -1)
|
||||
lexerror("Long character constant");
|
||||
printf("%c", c);
|
||||
return(__na__);
|
||||
}
|
||||
"\"" { return(__na__); } /* This should call "lexswitch" */
|
||||
"\n" { return(__na__); }
|
||||
" " { return(__na__); }
|
||||
"\t" { return(__na__); }
|
||||
"||" { return(__na__); }
|
||||
"&&" { return(__na__); }
|
||||
"(" { return(__na__); }
|
||||
")" { return(__na__); }
|
||||
"[" { return(__na__); }
|
||||
"]" { return(__na__); }
|
||||
"{" { return(__na__); }
|
||||
"}" { return(__na__); }
|
||||
%%
|
||||
char *
|
||||
install()
|
||||
/*
|
||||
* Install the current token in the symbol table
|
||||
*/
|
||||
{
|
||||
register char *buffer; /* Where to put the character */
|
||||
register char *first; /* -> first byte of the token */
|
||||
char *last; /* Can't be in a register */
|
||||
extern char *token();
|
||||
|
||||
first = token(&last); /* Find first/last of token */
|
||||
if ((buffer = alloc((last - first) + 1)) == NULL) {
|
||||
error("Out of space in install");
|
||||
exit(1);
|
||||
}
|
||||
first = copy(buffer, first, (last - first));
|
||||
*first = '\0';
|
||||
return(buffer);
|
||||
}
|
||||
32
c20/lex/commen.c
Normal file
32
c20/lex/commen.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Bob Denny 28-Aug-82 Remove reference to stdio.h
|
||||
*/
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
comment(mat)
|
||||
char *mat;
|
||||
{
|
||||
register c;
|
||||
register char *cp;
|
||||
int lno;
|
||||
|
||||
lno = yyline;
|
||||
c = 1;
|
||||
for (cp = mat; *cp && c>=0;) {
|
||||
if ((c = lexchar())=='\n')
|
||||
yyline++;
|
||||
if (c!=*cp++)
|
||||
cp = mat;
|
||||
}
|
||||
if (c < 0) {
|
||||
yyline = lno;
|
||||
lexerror("End of file in comment");
|
||||
}
|
||||
}
|
||||
225
c20/lex/ctoc.c
Normal file
225
c20/lex/ctoc.c
Normal file
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* Created by DECUS LEX from file "CTOC.LXI" Mon Mar 22 12:44:32 1982
|
||||
*/
|
||||
#
|
||||
#include <stdio.h>
|
||||
#include <lex.h>
|
||||
|
||||
extern int _lmovb();
|
||||
|
||||
#line 19 "CTOC.LXI"
|
||||
|
||||
|
||||
char tbuf[80]; /* Token buffer */
|
||||
|
||||
main()
|
||||
{
|
||||
while (yylex())
|
||||
;
|
||||
}
|
||||
|
||||
_Alextab(__na__) {
|
||||
switch (__na__) {
|
||||
case 0:
|
||||
|
||||
#line 42 "CTOC.LXI"
|
||||
|
||||
gettoken(tbuf, sizeof tbuf);
|
||||
printf("%s=",tbuf+1);
|
||||
|
||||
break;
|
||||
case 1:
|
||||
|
||||
#line 48 "CTOC.LXI"
|
||||
|
||||
lexecho(stdout);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
|
||||
#line 53 "CTOC.LXI"
|
||||
|
||||
lexecho(stdout);
|
||||
|
||||
break;
|
||||
case 3:
|
||||
|
||||
#line 58 "CTOC.LXI"
|
||||
|
||||
lexecho(stdout);
|
||||
|
||||
break;
|
||||
case 4:
|
||||
|
||||
#line 63 "CTOC.LXI"
|
||||
|
||||
lexecho(stdout);
|
||||
|
||||
break;
|
||||
case 5:
|
||||
|
||||
#line 68 "CTOC.LXI"
|
||||
|
||||
lexecho(stdout);
|
||||
|
||||
break;
|
||||
}
|
||||
return(LEXSKIP);
|
||||
}
|
||||
|
||||
#line 71 "CTOC.LXI"
|
||||
|
||||
int _Flextab[] {
|
||||
-1, 5, 5, 4, -1, -1, -1, 5, 3, -1, -1, -1, 5, 1, 5, 0,
|
||||
0, 0, 0, 0, 0, 2050, 0, 2050, 0, 1, 0, 1, 0, -1,
|
||||
};
|
||||
|
||||
#line 71 "CTOC.LXI"
|
||||
|
||||
#define LLTYPE1 char
|
||||
|
||||
LLTYPE1 _Nlextab[] {
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 12, 2, 1, 1, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 12, 14, 12, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
13, 18, 17, 21, 23, 26, 24, 22, 28, 20, 29, 19, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 27, 13, 25, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 15, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 16,
|
||||
};
|
||||
|
||||
LLTYPE1 _Clextab[] {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
12, 14, 14, 20, 22, 25, 14, 14, 27, 14, -1, 14, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, 14, 14, 14, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 14, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, 14,
|
||||
};
|
||||
|
||||
LLTYPE1 _Dlextab[] {
|
||||
29, 29, 29, 29, 2, 29, 2, 29, 29, 7, 29, 7, 29, 29, 29, 29,
|
||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
|
||||
};
|
||||
|
||||
int _Blextab[] {
|
||||
0, 0, 256, 0, 0, 384, 0, 512, 0, 0, 640, 0, 707, 0, 732, 0,
|
||||
0, 0, 0, 0, 726, 0, 729, 0, 0, 711, 0, 716, 0, 0,
|
||||
};
|
||||
char *llsave[1];
|
||||
|
||||
int _Llextab[] {
|
||||
00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 01, 00,
|
||||
00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0,
|
||||
};
|
||||
|
||||
struct lextab lextab {
|
||||
29, /* last state */
|
||||
_Dlextab, /* defaults */
|
||||
_Nlextab, /* next */
|
||||
_Clextab, /* check */
|
||||
_Blextab, /* base */
|
||||
856, /* last in base */
|
||||
_lmovb, /* byte-int move routines */
|
||||
_Flextab, /* final state descriptions */
|
||||
_Alextab, /* action routine */
|
||||
_Llextab, /* look-ahead vector */
|
||||
0, /* no ignore class */
|
||||
0, /* no break class */
|
||||
0, /* no illegal class */
|
||||
};
|
||||
24
c20/lex/ctype.h
Normal file
24
c20/lex/ctype.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#define _U 01
|
||||
#define _L 02
|
||||
#define _N 04
|
||||
#define _S 010
|
||||
#define _P 020
|
||||
#define _C 040
|
||||
#define _X 0100
|
||||
|
||||
extern char _ctype_[];
|
||||
|
||||
#define isalpha(c) ((_ctype_+1)[c]&(_U|_L))
|
||||
#define isupper(c) ((_ctype_+1)[c]&_U)
|
||||
#define islower(c) ((_ctype_+1)[c]&_L)
|
||||
#define isdigit(c) ((_ctype_+1)[c]&_N)
|
||||
#define isxdigit(c) ((_ctype_+1)[c]&(_N|_X))
|
||||
#define isspace(c) ((_ctype_+1)[c]&_S)
|
||||
#define ispunct(c) ((_ctype_+1)[c]&_P)
|
||||
#define isalnum(c) ((_ctype_+1)[c]&(_U|_L|_N))
|
||||
#define isprint(c) ((_ctype_+1)[c]&(_P|_U|_L|_N))
|
||||
#define iscntrl(c) ((_ctype_+1)[c]&_C)
|
||||
#define isascii(c) ((unsigned)(c)<=0177)
|
||||
#define toupper(c) ((c)-'a'+'A')
|
||||
#define tolower(c) ((c)-'A'+'a')
|
||||
#define toascii(c) ((c)&0177)
|
||||
200
c20/lex/dfa.c
Normal file
200
c20/lex/dfa.c
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*
|
||||
* Modified 02-Dec-80 Bob Denny -- Conditionalize debug code for reduced size
|
||||
* Modified 29-May-81 Bob Denny -- Clean up overlay stuff for RSX.
|
||||
* More 19-Mar-82 Bob Denny -- New C library & compiler
|
||||
* More 03-May-82 Bob Denny -- Final touches, remove unreferenced autos
|
||||
* More 29-Aug-82 Bob Denny -- Clean up -d printouts
|
||||
* More 29-Aug-82 Bob Denny -- Reformat for readability and comment
|
||||
* while learning about LEX.
|
||||
*/
|
||||
|
||||
/*
|
||||
* *********
|
||||
* * DFA.C *
|
||||
* *********
|
||||
*
|
||||
* LEX -- DFA construction routines
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
extern struct set *eclosure(); /* Used only by DFA */
|
||||
extern struct dfa *defalt(); /* Used only by DFA */
|
||||
extern struct move *stbase(); /* Used only by DFA */
|
||||
|
||||
/*
|
||||
* Build the DFA from the NFA
|
||||
*/
|
||||
dfabuild()
|
||||
{
|
||||
struct trans *trp;
|
||||
struct nfa **vec, **tp, *np, *temp[MAXNFA+1];
|
||||
int a, i;
|
||||
struct set **sp, *stack[MAXDFA], **spp, *xp; /* DFA set stack */
|
||||
struct dfa *state; /* --> current DFA state */
|
||||
struct xset *xs, *xse;
|
||||
|
||||
/*
|
||||
* Simulate an epsilon transition from nfa state 0 to
|
||||
* the initial states of the machines for each
|
||||
* translation.
|
||||
*/
|
||||
nfa[0].n_char = EPSILON; /* Set NFA state 0 transition EPSILON */
|
||||
/*
|
||||
* Allocate a state vector, each node of which will
|
||||
* point to an NFA starting state. Each translation
|
||||
* generates an NFA, so the number of translations
|
||||
* equals the number of NFA start states.
|
||||
*/
|
||||
vec = lalloc(i = (trnsp-trans)+1, sizeof(*vec), "dfabuild");
|
||||
/*
|
||||
* Fill in the start state vector
|
||||
*/
|
||||
vec[0] = nfa; /* vec[0] always --> NFA state 0 */
|
||||
for (a = 1, trp = trans; trp < trnsp; trp++) /* For each translation */
|
||||
vec[a++] = trp->t_start; /* Pick up the NFA start state */
|
||||
/*
|
||||
* Now build the set sp --> e-CLOSURE(vec)
|
||||
*/
|
||||
sp = eclosure(newset(vec, i, 1));
|
||||
free(vec); /* Deallocate the start state vector */
|
||||
|
||||
/*
|
||||
* At this point state 0 of the DFA is constructed.
|
||||
* This is the start state of the DFA.
|
||||
* Mark it "added" and push it on to the stack.
|
||||
*/
|
||||
sp->s_flag |= ADDED;
|
||||
spp = stack;
|
||||
*spp++ = sp;
|
||||
/*
|
||||
* From state 0, which is now stacked, all further DFA
|
||||
* states will be derived.
|
||||
*/
|
||||
while (spp > stack)
|
||||
{
|
||||
sp = *--spp;
|
||||
for (a = 0; a < NCHARS; a++)
|
||||
insets[a] = 0;
|
||||
xse = sets;
|
||||
for (i = 0; i < sp->s_len; i++)
|
||||
xse = addset(sp->s_els[i], xse);
|
||||
state = newdfa();
|
||||
sp->s_state = state;
|
||||
state->df_name = sp;
|
||||
#ifdef DEBUG
|
||||
if (lldebug)
|
||||
{
|
||||
fprintf(lexlog, "build state %d ", state-dfa);
|
||||
pset(sp, 1);
|
||||
fprintf(lexlog, "\n");
|
||||
}
|
||||
#endif
|
||||
state->df_ntrans = xse-sets;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
{
|
||||
a = xs->x_char&0377;
|
||||
tp = temp;
|
||||
for (i = 0; i < sp->s_len; i++)
|
||||
if ((np = sp->s_els[i])->n_char==a ||
|
||||
np->n_char==CCL &&
|
||||
np->n_ccl[a/NBPC]&(1<<(a%NBPC)))
|
||||
add(temp, &tp, np->n_succ[0]);
|
||||
xp = newset(temp, tp-temp, 1);
|
||||
xp = eclosure(xp);
|
||||
#ifdef DEBUG
|
||||
if (lldebug)
|
||||
{
|
||||
putc('\t', lexlog);
|
||||
chprint(a);
|
||||
putc('\t', lexlog);
|
||||
pset(xp, 1);
|
||||
fprintf(lexlog, "\n");
|
||||
}
|
||||
#endif
|
||||
xs->x_set = xp;
|
||||
if (xp->s_state==0 && (xp->s_flag&ADDED)==0)
|
||||
{
|
||||
xp->s_flag |= ADDED;
|
||||
if (spp >= stack+MAXDFA)
|
||||
{
|
||||
error("dfabuild: stack overflow");
|
||||
exit(1);
|
||||
}
|
||||
*spp++ = xp;
|
||||
}
|
||||
}
|
||||
state->df_default = defalt(state, &xse);
|
||||
setbase(state, stbase(xse), xse);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If an nfa state is not
|
||||
* already a member of the vector
|
||||
* `base', add it.
|
||||
*/
|
||||
add(base, tpp, np)
|
||||
struct nfa ***tpp, **base, *np;
|
||||
{
|
||||
register struct nfa **tp;
|
||||
|
||||
for (tp = base; tp < *tpp; tp++)
|
||||
if (*tp == np)
|
||||
return;
|
||||
*(*tpp)++ = np;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add the character(s)
|
||||
* on which state `np'
|
||||
* branches to the transition
|
||||
* vector.
|
||||
*/
|
||||
addset(np, xse)
|
||||
register struct nfa *np;
|
||||
struct xset *xse;
|
||||
{
|
||||
register a;
|
||||
register char *ccl;
|
||||
|
||||
if ((a = np->n_char) < NCHARS)
|
||||
xse = addxset(a, xse);
|
||||
if (a != CCL)
|
||||
return(xse);
|
||||
ccl = np->n_ccl;
|
||||
for (a = 0; a < NCHARS; a++)
|
||||
if (ccl[a/NBPC]&(1<<(a%NBPC)))
|
||||
xse = addxset(a, xse);
|
||||
return(xse);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a character to the
|
||||
* transition vector, if it
|
||||
* isn't there already.
|
||||
*/
|
||||
addxset(a, xse)
|
||||
register a;
|
||||
struct xset *xse;
|
||||
{
|
||||
register struct xset *xs;
|
||||
register int temp;
|
||||
|
||||
/*
|
||||
* VMS native doesn't do this correctly:
|
||||
* if (insets[a]++)
|
||||
*/
|
||||
temp = insets[a];
|
||||
insets[a] += 1;
|
||||
if (temp)
|
||||
return(xse);
|
||||
xs = xse++;
|
||||
xs->x_char = a;
|
||||
xs->x_set = NULL;
|
||||
xs->x_defsame = 0;
|
||||
return(xse);
|
||||
}
|
||||
200
c20/lex/dfa.old
Normal file
200
c20/lex/dfa.old
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*
|
||||
* Modified 02-Dec-80 Bob Denny -- Conditionalize debug code for reduced size
|
||||
* Modified 29-May-81 Bob Denny -- Clean up overlay stuff for RSX.
|
||||
* More 19-Mar-82 Bob Denny -- New C library & compiler
|
||||
* More 03-May-82 Bob Denny -- Final touches, remove unreferenced autos
|
||||
* More 29-Aug-82 Bob Denny -- Clean up -d printouts
|
||||
* More 29-Aug-82 Bob Denny -- Reformat for readability and comment
|
||||
* while learning about LEX.
|
||||
*/
|
||||
|
||||
/*
|
||||
* *********
|
||||
* * DFA.C *
|
||||
* *********
|
||||
*
|
||||
* LEX -- DFA construction routines
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
extern struct set *eclosure(); /* Used only by DFA */
|
||||
extern struct dfa *defalt(); /* Used only by DFA */
|
||||
extern struct move *stbase(); /* Used only by DFA */
|
||||
|
||||
/*
|
||||
* Build the DFA from the NFA
|
||||
*/
|
||||
dfabuild()
|
||||
{
|
||||
struct trans *trp;
|
||||
struct nfa **vec, **tp, *np, *temp[MAXNFA+1];
|
||||
int a, i;
|
||||
struct set **sp, *stack[MAXDFA], **spp, *xp; /* DFA set stack */
|
||||
struct dfa *state; /* --> current DFA state */
|
||||
struct xset *xs, *xse;
|
||||
|
||||
/*
|
||||
* Simulate an epsilon transition from nfa state 0 to
|
||||
* the initial states of the machines for each
|
||||
* translation.
|
||||
*/
|
||||
nfa[0].n_char = EPSILON; /* Set NFA state 0 transition EPSILON */
|
||||
/*
|
||||
* Allocate a state vector, each node of which will
|
||||
* point to an NFA starting state. Each translation
|
||||
* generates an NFA, so the number of translations
|
||||
* equals the number of NFA start states.
|
||||
*/
|
||||
vec = lalloc(i = (transp-trans)+1, sizeof(*vec), "dfabuild");
|
||||
/*
|
||||
* Fill in the start state vector
|
||||
*/
|
||||
vec[0] = nfa; /* vec[0] always --> NFA state 0 */
|
||||
for (a = 1, trp = trans; trp < transp; trp++) /* For each translation */
|
||||
vec[a++] = trp->t_start; /* Pick up the NFA start state */
|
||||
/*
|
||||
* Now build the set sp --> e-CLOSURE(vec)
|
||||
*/
|
||||
sp = eclosure(newset(vec, i, 1));
|
||||
free(vec); /* Deallocate the start state vector */
|
||||
|
||||
/*
|
||||
* At this point state 0 of the DFA is constructed.
|
||||
* This is the start state of the DFA.
|
||||
* Mark it "added" and push it on to the stack.
|
||||
*/
|
||||
sp->s_flag |= ADDED;
|
||||
spp = stack;
|
||||
*spp++ = sp;
|
||||
/*
|
||||
* From state 0, which is now stacked, all further DFA
|
||||
* states will be derived.
|
||||
*/
|
||||
while (spp > stack)
|
||||
{
|
||||
sp = *--spp;
|
||||
for (a = 0; a < NCHARS; a++)
|
||||
insets[a] = 0;
|
||||
xse = sets;
|
||||
for (i = 0; i < sp->s_len; i++)
|
||||
xse = addset(sp->s_els[i], xse);
|
||||
state = newdfa();
|
||||
sp->s_state = state;
|
||||
state->df_name = sp;
|
||||
#ifdef DEBUG
|
||||
if (lldebug)
|
||||
{
|
||||
fprintf(lexlog, "build state %d ", state-dfa);
|
||||
pset(sp, 1);
|
||||
fprintf(lexlog, "\n");
|
||||
}
|
||||
#endif
|
||||
state->df_ntrans = xse-sets;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
{
|
||||
a = xs->x_char&0377;
|
||||
tp = temp;
|
||||
for (i = 0; i < sp->s_len; i++)
|
||||
if ((np = sp->s_els[i])->n_char==a ||
|
||||
np->n_char==CCL &&
|
||||
np->n_ccl[a/NBPC]&(1<<(a%NBPC)))
|
||||
add(temp, &tp, np->n_succ[0]);
|
||||
xp = newset(temp, tp-temp, 1);
|
||||
xp = eclosure(xp);
|
||||
#ifdef DEBUG
|
||||
if (lldebug)
|
||||
{
|
||||
putc('\t', lexlog);
|
||||
chprint(a);
|
||||
putc('\t', lexlog);
|
||||
pset(xp, 1);
|
||||
fprintf(lexlog, "\n");
|
||||
}
|
||||
#endif
|
||||
xs->x_set = xp;
|
||||
if (xp->s_state==0 && (xp->s_flag&ADDED)==0)
|
||||
{
|
||||
xp->s_flag |= ADDED;
|
||||
if (spp >= stack+MAXDFA)
|
||||
{
|
||||
error("dfabuild: stack overflow");
|
||||
exit(1);
|
||||
}
|
||||
*spp++ = xp;
|
||||
}
|
||||
}
|
||||
state->df_default = defalt(state, &xse);
|
||||
setbase(state, stbase(xse), xse);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If an nfa state is not
|
||||
* already a member of the vector
|
||||
* `base', add it.
|
||||
*/
|
||||
add(base, tpp, np)
|
||||
struct nfa ***tpp, **base, *np;
|
||||
{
|
||||
register struct nfa **tp;
|
||||
|
||||
for (tp = base; tp < *tpp; tp++)
|
||||
if (*tp == np)
|
||||
return;
|
||||
*(*tpp)++ = np;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add the character(s)
|
||||
* on which state `np'
|
||||
* branches to the transition
|
||||
* vector.
|
||||
*/
|
||||
addset(np, xse)
|
||||
register struct nfa *np;
|
||||
struct xset *xse;
|
||||
{
|
||||
register a;
|
||||
register char *ccl;
|
||||
|
||||
if ((a = np->n_char) < NCHARS)
|
||||
xse = addxset(a, xse);
|
||||
if (a != CCL)
|
||||
return(xse);
|
||||
ccl = np->n_ccl;
|
||||
for (a = 0; a < NCHARS; a++)
|
||||
if (ccl[a/NBPC]&(1<<(a%NBPC)))
|
||||
xse = addxset(a, xse);
|
||||
return(xse);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a character to the
|
||||
* transition vector, if it
|
||||
* isn't there already.
|
||||
*/
|
||||
addxset(a, xse)
|
||||
register a;
|
||||
struct xset *xse;
|
||||
{
|
||||
register struct xset *xs;
|
||||
register int temp;
|
||||
|
||||
/*
|
||||
* VMS native doesn't do this correctly:
|
||||
* if (insets[a]++)
|
||||
*/
|
||||
temp = insets[a];
|
||||
insets[a] += 1;
|
||||
if (temp)
|
||||
return(xse);
|
||||
xs = xse++;
|
||||
xs->x_char = a;
|
||||
xs->x_set = NULL;
|
||||
xs->x_defsame = 0;
|
||||
return(xse);
|
||||
}
|
||||
52
c20/lex/eclosu.c
Normal file
52
c20/lex/eclosu.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
/*
|
||||
* Construct the
|
||||
* epsilon closure of
|
||||
* a given set; this is
|
||||
* the set of states that may
|
||||
* be reached by some number of
|
||||
* epsilon transitions from
|
||||
* that state.
|
||||
*/
|
||||
struct set *
|
||||
eclosure(t)
|
||||
struct set *t;
|
||||
{
|
||||
register struct nfa *np, *xp;
|
||||
register i;
|
||||
struct nfa **sp, **tp, **ip, *stack[MAXNFA], *temp[MAXNFA];
|
||||
|
||||
tp = temp;
|
||||
for (sp = stack, i = 0; i < t->s_len; i++)
|
||||
if (sp <= stack+MAXNFA)
|
||||
*tp++ = *sp++ = t->s_els[i];
|
||||
else {
|
||||
error("Stack overflow in `eclosure'");
|
||||
exit(1);
|
||||
}
|
||||
while (sp > stack) {
|
||||
np = *--sp;
|
||||
if (np->n_char==EPSILON)
|
||||
for (i = 0; i < 2; i++)
|
||||
if (xp = np->n_succ[i]) {
|
||||
for (ip = temp; ip < tp;)
|
||||
if (*ip++ == xp)
|
||||
goto cont;
|
||||
if (tp >= temp+MAXNFA) {
|
||||
error("eclosure: list overflow");
|
||||
exit(1);
|
||||
}
|
||||
*sp++ = *tp++ = xp;
|
||||
cont:;
|
||||
}
|
||||
}
|
||||
t = newset(temp, tp-temp, 1);
|
||||
return(t);
|
||||
}
|
||||
|
||||
94
c20/lex/foo.c
Normal file
94
c20/lex/foo.c
Normal file
@@ -0,0 +1,94 @@
|
||||
#include <stdio.h>
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
extern int _lmovb();
|
||||
|
||||
#line 1 "foo.lxi"
|
||||
|
||||
main() {
|
||||
int res;
|
||||
res = yylex();
|
||||
printf("lexval=\t%d\nyylex()=\t%d\n", lexval, res);
|
||||
}
|
||||
extern struct lextab foo;
|
||||
|
||||
/* Standard I/O selected */
|
||||
extern FILE *lexin;
|
||||
|
||||
llstin()
|
||||
{
|
||||
if(lexin == NULL)
|
||||
lexin = stdin;
|
||||
if(_tabp == NULL)
|
||||
lexswitch(&foo);
|
||||
}
|
||||
|
||||
_Afoo(__na__) /* Action routine */
|
||||
{
|
||||
switch (__na__) {
|
||||
case 0:
|
||||
|
||||
#line 11 "foo.lxi"
|
||||
printf("foo");
|
||||
|
||||
break;
|
||||
}
|
||||
return(LEXSKIP);
|
||||
}
|
||||
|
||||
#line 13 "foo.lxi"
|
||||
|
||||
int _Ffoo[] = {
|
||||
-1, -1, -1, 0, -1,
|
||||
};
|
||||
|
||||
#line 13 "foo.lxi"
|
||||
|
||||
#define LLTYPE1 char
|
||||
|
||||
LLTYPE1 _Nfoo[] = {
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 2, 1, 2, 1, 2, 3, 2, 1,
|
||||
};
|
||||
|
||||
LLTYPE1 _Cfoo[] = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, 0, 0, 1, 1, 2, 2, 3, 3,
|
||||
};
|
||||
|
||||
LLTYPE1 _Dfoo[] = {
|
||||
4, 4, 4, 4,
|
||||
};
|
||||
|
||||
int _Bfoo[] = {
|
||||
0, 2, 4, 6, 0,
|
||||
};
|
||||
|
||||
struct lextab foo = {
|
||||
4, /* last state */
|
||||
_Dfoo, /* defaults */
|
||||
_Nfoo, /* next */
|
||||
_Cfoo, /* check */
|
||||
_Bfoo, /* base */
|
||||
104, /* last in base */
|
||||
_lmovb, /* byte-int move routines */
|
||||
_Ffoo, /* final state descriptions */
|
||||
_Afoo, /* action routine */
|
||||
NULL, /* look-ahead vector */
|
||||
0, /* no ignore class */
|
||||
0, /* no break class */
|
||||
0, /* no illegal class */
|
||||
};
|
||||
12
c20/lex/foo.lxi
Normal file
12
c20/lex/foo.lxi
Normal file
@@ -0,0 +1,12 @@
|
||||
%{
|
||||
main() {
|
||||
int res;
|
||||
res = yylex();
|
||||
printf("lexval=\t%d\nyylex()=\t%d\n", lexval, res);
|
||||
}
|
||||
%}
|
||||
|
||||
%%
|
||||
|
||||
("a" | "b")* "ab" { printf("foo");
|
||||
}
|
||||
58
c20/lex/foo.out
Normal file
58
c20/lex/foo.out
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
NFA for complete syntax
|
||||
state 0
|
||||
epsilon 7
|
||||
state 7
|
||||
epsilon 5
|
||||
epsilon 8
|
||||
|
||||
state 5
|
||||
epsilon 1
|
||||
epsilon 3
|
||||
|
||||
state 1
|
||||
a 2
|
||||
|
||||
state 2
|
||||
epsilon 6
|
||||
|
||||
state 6
|
||||
epsilon 5
|
||||
epsilon 8
|
||||
|
||||
state 8
|
||||
a 10
|
||||
|
||||
state 10
|
||||
b 11
|
||||
|
||||
state 11
|
||||
final state
|
||||
|
||||
state 3
|
||||
b 4
|
||||
|
||||
state 4
|
||||
epsilon 6
|
||||
|
||||
|
||||
Minimised DFA for complete syntax
|
||||
|
||||
state 0
|
||||
a 2
|
||||
b 1
|
||||
|
||||
state 1
|
||||
a 2
|
||||
b 1
|
||||
|
||||
state 2
|
||||
a 2
|
||||
b 3
|
||||
|
||||
state 3 (final 11[0],)
|
||||
a 2
|
||||
b 1
|
||||
|
||||
12/600 NFA states, 4/800 DFA states
|
||||
104/15000 entries in move vectors
|
||||
4
c20/lex/foo.stinkr
Normal file
4
c20/lex/foo.stinkr
Normal file
@@ -0,0 +1,4 @@
|
||||
x clib:stdio
|
||||
x lex:lexlib
|
||||
l foo
|
||||
o foo.exe
|
||||
24
c20/lex/gettok.c
Normal file
24
c20/lex/gettok.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Bob Denny 28-Aug-82 Remove reference to stdio.h
|
||||
*/
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
gettoken(lltb, lltbsiz)
|
||||
char *lltb;
|
||||
{
|
||||
register char *lp, *tp, *ep;
|
||||
|
||||
tp = lltb;
|
||||
ep = tp+lltbsiz-1;
|
||||
for (lp = llbuf; lp < llend && tp < ep;)
|
||||
*tp++ = *lp++;
|
||||
*tp = 0;
|
||||
return(tp-lltb);
|
||||
}
|
||||
219
c20/lex/hword.c
Normal file
219
c20/lex/hword.c
Normal file
@@ -0,0 +1,219 @@
|
||||
#
|
||||
#include <stdio.h>
|
||||
#include <lex.h>
|
||||
|
||||
extern int _lmovb();
|
||||
|
||||
#line 34 "hword.lxi"
|
||||
|
||||
|
||||
main()
|
||||
{
|
||||
while (yylex())
|
||||
;
|
||||
}
|
||||
_Alextab(__na__) {
|
||||
switch (__na__) {
|
||||
case 0:
|
||||
|
||||
#line 50 "hword.lxi"
|
||||
|
||||
output(TRUE);
|
||||
return(LEXSKIP);
|
||||
|
||||
break;
|
||||
case 1:
|
||||
|
||||
#line 58 "hword.lxi"
|
||||
|
||||
output(FALSE);
|
||||
return(LEXSKIP);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
|
||||
#line 68 "hword.lxi"
|
||||
|
||||
return(LEXSKIP);
|
||||
|
||||
break;
|
||||
case 3:
|
||||
|
||||
#line 77 "hword.lxi"
|
||||
|
||||
return(LEXSKIP);
|
||||
|
||||
break;
|
||||
}
|
||||
return(LEXSKIP);
|
||||
}
|
||||
|
||||
#line 81 "hword.lxi"
|
||||
|
||||
|
||||
output(flag)
|
||||
int flag;
|
||||
/*
|
||||
* Output the current token. The parameter is TRUE if this is
|
||||
* the start of a hyphenated word.
|
||||
*/
|
||||
{
|
||||
register char *tokptr; /* Locate token start */
|
||||
char *tokend; /* Locate token end */
|
||||
char *token();
|
||||
|
||||
|
||||
tokptr = token(&tokend);
|
||||
/*
|
||||
* Skip over leading and trailing non-alpha stuff
|
||||
*/
|
||||
while (!isalpha(*tokptr) && tokptr < tokend)
|
||||
tokptr++;
|
||||
while (!isalpha(*--tokend) && tokend > tokptr);
|
||||
printf("%.?s", (tokend - tokptr + 1), tokptr);
|
||||
if (!flag)
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
int _Flextab[] {
|
||||
-1, 3, 3, 2, 2, 3, 2, 1, 1, -1, -1, 2048, -1, 1, -1, 3,
|
||||
2, -1, -1, -1,
|
||||
};
|
||||
|
||||
#line 106 "hword.lxi"
|
||||
|
||||
#define LLTYPE1 char
|
||||
|
||||
LLTYPE1 _Nlextab[] {
|
||||
2, 1, 1, 1, 1, 1, 1, 1, 1, 4, 3, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
4, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 15, 15, 15, 15, 15,
|
||||
15, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 15, 15, 15, 15, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
6, 6, 9, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 6, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 14, 14, 14, 14, 14, 14, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 8, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
||||
13, 13, 13, 13, 13, 13, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
13, 13, 13, 13, 13, 13, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
13, 13, 13, 13, 12, 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 12, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 19, 19, 19, 19, 19, 19, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
19, 19, 19, 19, 19, 19, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
16, 16, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 16, 18, 18, 18, 18, 18, 18, 18, 18,
|
||||
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
|
||||
18, 18, 18, 18, 18, 18, 18, 18, 17, 17, 17, 17, 17, 17, 17, 17,
|
||||
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
||||
17, 17, 18, 18, 18, 18, 18, 18, 17, 17, 17, 17, 17, 17, 17, 17,
|
||||
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
||||
17, 17, 18, 18, 18, 18,
|
||||
};
|
||||
|
||||
LLTYPE1 _Clextab[] {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
5, 5, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 9, 9, 14, 14, 17, 17, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9, -1, 14, -1, 17,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, -1, -1, -1, -1, -1, -1, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||
9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
-1, -1, -1, -1, -1, -1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||
15, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15,
|
||||
};
|
||||
|
||||
LLTYPE1 _Dlextab[] {
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 7, 19, 19, 19, 9, 7, 5, 19,
|
||||
19, 14, 15,
|
||||
};
|
||||
|
||||
int _Blextab[] {
|
||||
0, 0, 0, 0, 0, 247, 0, 341, 248, 459, 517, 0, 0, 0, 461, 631,
|
||||
0, 463, 0, 0,
|
||||
};
|
||||
char *llsave[1];
|
||||
|
||||
int _Llextab[] {
|
||||
00, 00, 00, 00, 00, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00,
|
||||
00, 00, 00, 0,
|
||||
};
|
||||
|
||||
struct lextab lextab {
|
||||
19, /* last state */
|
||||
_Dlextab, /* defaults */
|
||||
_Nlextab, /* next */
|
||||
_Clextab, /* check */
|
||||
_Blextab, /* base */
|
||||
757, /* last in base */
|
||||
_lmovb, /* byte-int move routines */
|
||||
_Flextab, /* final state descriptions */
|
||||
_Alextab, /* action routine */
|
||||
_Llextab, /* look-ahead vector */
|
||||
0, /* no ignore class */
|
||||
0, /* no break class */
|
||||
0, /* no illegal class */
|
||||
};
|
||||
109
c20/lex/hword.lxi
Normal file
109
c20/lex/hword.lxi
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Word recognizer (with hyphenation)
|
||||
*
|
||||
* This program acts as a very simple filter for files of
|
||||
* text that may have hyphenated words at the end of an input
|
||||
* line. Output consists of each word on a seperate line
|
||||
* with hyphenated words rejoined. Note: a word is said to
|
||||
* start with the first alphabetic character and end with the
|
||||
* last alphabetic character. Embedded graphics will be removed.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Basic elements
|
||||
*/
|
||||
white = [\n\t ]; /* End of a word */
|
||||
bol = [\n] white*; /* Beginning of a line */
|
||||
eol = [\0\n]; /* End of input line */
|
||||
letter = [A-Za-z]; /* Is a letter */
|
||||
graphic = [!-@\[-`{-~]; /* Not a letter */
|
||||
text = [!-~]; /* All printing chars. */
|
||||
garbage = [\1-\377]; /* Whatever remains */
|
||||
|
||||
/*
|
||||
* A word contains "junk", at least one letter, then at
|
||||
* least another letter, then more junk.
|
||||
*
|
||||
* A hyphenated word is a word-<NEWLINE> followed by a word
|
||||
* on the next line.
|
||||
*/
|
||||
|
||||
word = graphic* letter text* letter graphic*;
|
||||
junk = (letter white) | (graphic* white);
|
||||
|
||||
%{
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define EOS 0
|
||||
|
||||
main()
|
||||
{
|
||||
while (yylex())
|
||||
;
|
||||
}
|
||||
%}
|
||||
|
||||
%%
|
||||
|
||||
/*
|
||||
* A hyphenated word
|
||||
*/
|
||||
|
||||
word "-" / bol letter letter
|
||||
{
|
||||
output(TRUE);
|
||||
return(LEXSKIP);
|
||||
}
|
||||
/*
|
||||
* An ordinary word
|
||||
*/
|
||||
|
||||
word {
|
||||
output(FALSE);
|
||||
return(LEXSKIP);
|
||||
}
|
||||
|
||||
/*
|
||||
* Junk (one letter words or all graphics)
|
||||
*/
|
||||
|
||||
junk
|
||||
{
|
||||
return(LEXSKIP);
|
||||
}
|
||||
|
||||
/*
|
||||
* Other stuff
|
||||
*/
|
||||
|
||||
eol | white | garbage
|
||||
{
|
||||
return(LEXSKIP);
|
||||
}
|
||||
|
||||
%%
|
||||
|
||||
output(flag)
|
||||
int flag;
|
||||
/*
|
||||
* Output the current token. The parameter is TRUE if this is
|
||||
* the start of a hyphenated word.
|
||||
*/
|
||||
{
|
||||
register char *tokptr; /* Locate token start */
|
||||
char *tokend; /* Locate token end */
|
||||
char *token();
|
||||
|
||||
|
||||
tokptr = token(&tokend);
|
||||
/*
|
||||
* Skip over leading and trailing non-alpha stuff
|
||||
*/
|
||||
while (!isalpha(*tokptr) && tokptr < tokend)
|
||||
tokptr++;
|
||||
while (!isalpha(*--tokend) && tokend > tokptr);
|
||||
printf("%.*s", (tokend - tokptr + 1), tokptr);
|
||||
if (!flag)
|
||||
putchar('\n');
|
||||
}
|
||||
65
c20/lex/impure.c
Normal file
65
c20/lex/impure.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* impure.c -- Impure data for ytab.c and min.c
|
||||
*
|
||||
* Created 02-Dec-80 Bob Denny -- Impure data from ytab.c and min.c moved
|
||||
* here so they can reside in overlays.
|
||||
* More 19-Mar-82 Bob Denny -- New C library & compiler
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
#include "ytab.h"
|
||||
|
||||
/*
|
||||
* min's
|
||||
*/
|
||||
struct set **oldpart;
|
||||
int **newpart;
|
||||
int nold;
|
||||
int nnew;
|
||||
|
||||
/*
|
||||
* ytab's
|
||||
*/
|
||||
|
||||
struct nlist {
|
||||
struct nlist *nl_next;
|
||||
struct nfa *nl_base;
|
||||
struct nfa *nl_end;
|
||||
struct nfa *nl_start;
|
||||
struct nfa *nl_final;
|
||||
} *nlist;
|
||||
|
||||
#ifndef YYSTYPE
|
||||
#define YYSTYPE int
|
||||
#endif
|
||||
|
||||
YYSTYPE yyval = 0;
|
||||
YYSTYPE *yypv;
|
||||
YYSTYPE yylval = 0;
|
||||
|
||||
int nlook = 0;
|
||||
int yyline = 0;
|
||||
char *breakc;
|
||||
char *ignore;
|
||||
char *illeg;
|
||||
|
||||
char buffer[150];
|
||||
int str_length;
|
||||
|
||||
char ccl[(NCHARS+1)/NBPC];
|
||||
|
||||
/*
|
||||
* Copied from ytab.c just before yyparse() ... kludgy.
|
||||
*/
|
||||
#define YYMAXDEPTH 150
|
||||
|
||||
/*
|
||||
* These are impure data for the parser driver yyparse().
|
||||
*/
|
||||
|
||||
int yydebug = 0; /* Make this 1 for yyparse() debugging */
|
||||
YYSTYPE yyv[YYMAXDEPTH];
|
||||
int yychar = -1;
|
||||
int yynerrs = 0;
|
||||
int yyerrflag = 0;
|
||||
|
||||
28
c20/lex/integ.c
Normal file
28
c20/lex/integ.c
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
/*
|
||||
* integ -- ascii to long (various bases)
|
||||
*/
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
long
|
||||
integ(cp, base)
|
||||
char *cp;
|
||||
register base;
|
||||
{
|
||||
register c;
|
||||
long n;
|
||||
|
||||
n = 0;
|
||||
while (c = *cp++) {
|
||||
if (c>='A' && c<='Z')
|
||||
c += 'a'-'A';
|
||||
if (c>='a' && c<='z')
|
||||
c = (c-'a')+10+'0';
|
||||
if (c < '0' || c > base+'0')
|
||||
break;
|
||||
n = n*base + c-'0';
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
1
c20/lex/lex-source-files.cmd
Normal file
1
c20/lex/lex-source-files.cmd
Normal file
@@ -0,0 +1 @@
|
||||
lex.c, lexsrt.c, impure.c, dfa.c, min.c, out.c, ytab.c, base.c, eclosu.c
|
||||
568
c20/lex/lex.c
Normal file
568
c20/lex/lex.c
Normal file
@@ -0,0 +1,568 @@
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*/
|
||||
|
||||
/*
|
||||
* lex -- initialisation, allocation, set creation
|
||||
*
|
||||
* Revised for PDP-11 (Decus) C by Martin Minow
|
||||
*/
|
||||
#ifdef DOCUMENTATION
|
||||
|
||||
title lex A Lexical Analyser Generator
|
||||
index A Lexical Analyser Generator
|
||||
|
||||
synopsis
|
||||
|
||||
lex [-options] [-i grammar] [-o outfile] [-t table]
|
||||
|
||||
description
|
||||
|
||||
Lex compiles a lexical analyser from a grammar and description of
|
||||
actions. It is described more fully in lex.doc: only usage is
|
||||
described. The following options are available:
|
||||
.lm +16
|
||||
.s.i-16;-a Disable recognition of non-ASCII characters
|
||||
(codes > 177 octal) for exception character classes (form [^ ...]).
|
||||
.s.i-16;-d Enable debugging code within lex. Normally
|
||||
needed only for debugging lex.
|
||||
.s.i-16;-e "Easy" command line. Saying "lex#-e#name" is the
|
||||
same as saying:
|
||||
.s.i 4;"lex -i name.lxi -o name.c -t name"
|
||||
.s
|
||||
Do not include devices or an extension on "name" or make it longer
|
||||
than 8 characters, or you'll get several error messages.
|
||||
.s.i-16;-i file Read the grammar from the file. If "-i" is not
|
||||
specified, input will be read from the standard input.
|
||||
.s.i-16;-m Enable state minimization. Currently not
|
||||
implemented, switch is a no-op.
|
||||
.s.i-16;-o file Write the output to the file. If "-o" is not
|
||||
specified, output will be written to file "lextab.c".
|
||||
.s.i-16;-s "Stand-alone" switch. Supresses the line
|
||||
"#include <stdio.h>" normally generated in the lex output. Use this
|
||||
if LEX is generating a module to be used in a program which does not
|
||||
use the "standard I/O" package.
|
||||
.s.i-16;-t table Name the recognizer "table" instead of the
|
||||
default "lextab". If -o is not given, output will be written to file
|
||||
"table.c".
|
||||
.s.i-16;-v [file] Verify -- write internal tables to the
|
||||
indicated file. If "-v" is given without a file name argument,
|
||||
tables will be written to "lex.out".
|
||||
.lm -16
|
||||
|
||||
diagnostics
|
||||
|
||||
The following error messages may occur on invocation. See lex
|
||||
documentation for information on compilation errors.
|
||||
.lm +8
|
||||
.s.i -8;Can't create ...
|
||||
.s.i -8;Cannot open ...
|
||||
.s.i -8;Illegal option.
|
||||
.s.i -8;Illegal switch combination.
|
||||
.s
|
||||
"-i", "-o" or "-t" given with "-e" or vice-versa
|
||||
.s.i -8;Table name too long.
|
||||
.s
|
||||
The table name (argument to "-t") must not be longer than 8 bytes.
|
||||
.s.i -8;Missing table name.
|
||||
.s.i -8;Missing input file.
|
||||
.s.i -8;Missing output file.
|
||||
.s.i -8;Missing name.
|
||||
.lm -8
|
||||
|
||||
author
|
||||
|
||||
Charles Forsyth
|
||||
Modified by Bob Denny
|
||||
bugs
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
extern char *lalloc();
|
||||
extern char *tolower();
|
||||
|
||||
struct nfa nfa[MAXNFA];
|
||||
struct nfa *nfap = &nfa[1];
|
||||
|
||||
struct xset sets[NCHARS];
|
||||
char insets[NCHARS];
|
||||
|
||||
struct trans trans[NTRANS];
|
||||
struct trans *trnsp = &trans[0]; /* transp */
|
||||
|
||||
char ccls[NCCLS][(NCHARS+1)/NBPC];
|
||||
int nccls;
|
||||
|
||||
int ndfa;
|
||||
struct dfa dfa[MAXDFA];
|
||||
struct move move[NNEXT];
|
||||
|
||||
char *tabname = "lextab";
|
||||
char tabfile[15];
|
||||
char *infile = NULL;
|
||||
char *outfile = NULL;
|
||||
|
||||
#ifdef DEBUG
|
||||
char *dumpfile = "lex.out";
|
||||
int lldebug = 0;
|
||||
#endif
|
||||
|
||||
int llnxtmax = 0;
|
||||
|
||||
FILE *llout;
|
||||
FILE *lexin;
|
||||
FILE *lexlog;
|
||||
|
||||
/*
|
||||
* Flags. Allow globals only for
|
||||
* those requiring same. Some only
|
||||
* used for checking for bad combos.
|
||||
*/
|
||||
int aflag = 0; /* Ignore non-ASCII in [^ ...] */
|
||||
static int eflag = 0; /* Easy command line */
|
||||
static int iflag = 0; /* "-i" given */
|
||||
int mflag = 0; /* Enable state minimization (not imp.) */
|
||||
static int oflag = 0; /* "-o" given */
|
||||
int sflag = 0; /* Supress "#include <stdio.h>" in output */
|
||||
static int tflag = 0; /* "-t" given */
|
||||
|
||||
struct set *setlist = 0;
|
||||
|
||||
main(argc, argv)
|
||||
char **argv;
|
||||
{
|
||||
register char *cp, *cp2;
|
||||
|
||||
#ifdef DEBUG
|
||||
int vflag;
|
||||
vflag = 0;
|
||||
#endif
|
||||
|
||||
for (; argc>1 && *argv[1]=='-'; argv++, argc--)
|
||||
switch (tolower(argv[1][1])) {
|
||||
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
* Create "verification" file, describing the
|
||||
* scanner.
|
||||
*/
|
||||
case 'v': /* -v => lex.out */
|
||||
vflag++; /* -v x.out => x.out */
|
||||
if (argc > 2 && argv[2][1] != '1') {
|
||||
--argc;
|
||||
dumpfile = (++argv)[1];
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* Enable debug displays
|
||||
*/
|
||||
case 'd':
|
||||
lldebug++;
|
||||
break;
|
||||
#endif
|
||||
/*
|
||||
* Enable state minimization. Currently not
|
||||
* implemented.
|
||||
*/
|
||||
case 'm':
|
||||
mflag++;
|
||||
break;
|
||||
|
||||
/*
|
||||
* Disable matching of non-ASCII characters (codes > 177(8))
|
||||
* for exception character classes (form "[^ ...]").
|
||||
*/
|
||||
case 'a':
|
||||
aflag++;
|
||||
break;
|
||||
|
||||
/*
|
||||
* Supress "#include <stdio.h>" in generated
|
||||
* code for programs not using standard I/O.
|
||||
*/
|
||||
case 's':
|
||||
sflag++;
|
||||
break;
|
||||
|
||||
/*
|
||||
* "Easy" command line
|
||||
*/
|
||||
case 'e':
|
||||
if(iflag || oflag || tflag) {
|
||||
error("Illegal switch combination\n");
|
||||
exit(1);
|
||||
}
|
||||
if (--argc <= 1) {
|
||||
error("Missing name\n");
|
||||
exit(1);
|
||||
}
|
||||
if (strlen(tabname = (++argv)[1]) > 8) {
|
||||
error("Name too long\n");
|
||||
exit(1);
|
||||
}
|
||||
infile = malloc(14);
|
||||
outfile = malloc(12);
|
||||
concat(infile, tabname, ".lxi", 0);
|
||||
/* if (freopen(infile, "r", stdin) == NULL) { */
|
||||
if ((lexin = fopen(infile, "r")) == NULL) {
|
||||
error("Cannot open input \"%s\"\n", infile);
|
||||
exit(1);
|
||||
}
|
||||
concat(outfile, tabname, ".c", 0);
|
||||
break;
|
||||
|
||||
/*
|
||||
* Specify input file name. Default = terminal (stdin)
|
||||
*/
|
||||
case 'i':
|
||||
if (eflag) {
|
||||
error("Illegal switch combination\n");
|
||||
exit(1);
|
||||
}
|
||||
iflag++;
|
||||
if (--argc <= 1) {
|
||||
error("Missing input file\n");
|
||||
exit(1);
|
||||
}
|
||||
infile = (++argv)[1];
|
||||
if (freopen(infile, "r", stdin) == NULL) {
|
||||
error("Cannot open input \"%s\"\n", infile);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* Specify output file name. Default = "lextab.c"
|
||||
*/
|
||||
case 'o':
|
||||
if (eflag) {
|
||||
error("Illegal switch combination\n");
|
||||
exit(1);
|
||||
}
|
||||
oflag++;
|
||||
if (--argc <= 1) {
|
||||
error("Missing output file");
|
||||
exit(1);
|
||||
}
|
||||
outfile = (++argv)[1];
|
||||
break;
|
||||
|
||||
/*
|
||||
* Specify table name. Default = "lextab". If "-o"
|
||||
* not given, output will go to "tabname.c".
|
||||
*/
|
||||
case 't':
|
||||
if (eflag) {
|
||||
error("Illegal switch combination\n");
|
||||
exit(1);
|
||||
}
|
||||
tflag++;
|
||||
if (--argc <= 1) {
|
||||
error("Missing table name");
|
||||
exit(1);
|
||||
}
|
||||
if (strlen(tabname = (++argv)[1]) > 8) {
|
||||
error("Table name too long\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
error("Illegal option: %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
/* lexin = stdin; */
|
||||
|
||||
#ifdef DEBUG
|
||||
cp = (vflag) ? dumpfile : "nul:"; /* Dec specific */
|
||||
if ((lexlog = fopen(cp, "w")) == NULL) {
|
||||
error("Cannot open \"%s\"", cp);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (infile == NULL) {
|
||||
infile = malloc(31);
|
||||
fgetname(lexin, infile);
|
||||
}
|
||||
cp = infile; /* Fold infile to lower case */
|
||||
while(*cp)
|
||||
*cp++ = tolower(*cp);
|
||||
cp = tabname; /* Fold tabname to lower case */
|
||||
while(*cp)
|
||||
*cp++ = tolower(*cp);
|
||||
if (outfile == NULL) {
|
||||
/*
|
||||
* Typical hacker's idiom!
|
||||
*/
|
||||
for (cp = tabname, cp2 = tabfile; *cp2 = *cp++;)
|
||||
cp2++;
|
||||
for (cp = ".c"; *cp2++ = *cp++;)
|
||||
;
|
||||
outfile = tabfile;
|
||||
}
|
||||
if ((llout = freopen(outfile, "w", stdout))==NULL) {
|
||||
error("Can't create %s\n", outfile);
|
||||
exit(1);
|
||||
}
|
||||
heading();
|
||||
if (yyparse())
|
||||
error("Parse failed\n");
|
||||
dfabuild(); /* 01+ */
|
||||
dfamin();
|
||||
dfaprint();
|
||||
dfawrite();
|
||||
/* stats(stdout); */
|
||||
#ifdef DEBUG
|
||||
stats(lexlog);
|
||||
#endif /* 01- */
|
||||
} /** END OF MAIN **/
|
||||
|
||||
/*
|
||||
* This module was moved here from out.c so it could be called from
|
||||
* ytab.c residing in same overlay region as out.c.
|
||||
* 02-Dec-80 Bob Denny.
|
||||
*/
|
||||
/* 01+ */
|
||||
/* here for overlaying
|
||||
ending()
|
||||
{
|
||||
static int ended;
|
||||
|
||||
if (ended++)
|
||||
return;
|
||||
fprintf(llout, "\t}\n\treturn(LEXSKIP);\n}\n");
|
||||
setlne();
|
||||
} */
|
||||
/* 01- */
|
||||
|
||||
stats(f)
|
||||
FILE *f;
|
||||
{
|
||||
fprintf(f, "\n");
|
||||
fprintf(f, "%d/%d NFA states, %d/%d DFA states\n",
|
||||
nfap-nfa, MAXNFA, ndfa, MAXDFA);
|
||||
fprintf(f, "%d/%d entries in move vectors\n", llnxtmax, NNEXT);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
* Print a state set on { ... } form on lexlog.
|
||||
*/
|
||||
pset(t, nf)
|
||||
register struct set *t;
|
||||
{
|
||||
register i;
|
||||
|
||||
fprintf(lexlog, "{");
|
||||
for (i = 0; i < t->s_len; i++)
|
||||
if (nf)
|
||||
fprintf(lexlog, " %d", t->s_els[i]-nfa); else
|
||||
fprintf(lexlog, " %d", t->s_els[i]);
|
||||
fprintf(lexlog, "}");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The following functions simply
|
||||
* allocate various kinds of
|
||||
* structures.
|
||||
*/
|
||||
struct nfa *
|
||||
newnfa(ch, nf1, nf2)
|
||||
struct nfa *nf1, *nf2;
|
||||
{
|
||||
register struct nfa *nf;
|
||||
|
||||
if ((nf = nfap++) >= &nfa[MAXNFA]) {
|
||||
error("Too many NFA states");
|
||||
exit(1);
|
||||
}
|
||||
nf->n_char = ch;
|
||||
nf->n_succ[0] = nf1;
|
||||
nf->n_succ[1] = nf2;
|
||||
nf->n_trans = 0;
|
||||
nf->n_flag = 0;
|
||||
nf->n_look = 0;
|
||||
return(nf);
|
||||
}
|
||||
|
||||
newdfa()
|
||||
{
|
||||
register struct dfa *df;
|
||||
|
||||
if ((df = &dfa[ndfa++]) >= &dfa[MAXDFA]) {
|
||||
error("Out of dfa states");
|
||||
exit(1);
|
||||
}
|
||||
return(df);
|
||||
}
|
||||
|
||||
char *
|
||||
newccl(ccl)
|
||||
char *ccl;
|
||||
{
|
||||
register char *p, *q;
|
||||
register i;
|
||||
int j;
|
||||
|
||||
for (j = 0; j < nccls; j++) {
|
||||
p = ccl;
|
||||
q = ccls[j];
|
||||
for (i = sizeof(ccls[j]); i--;)
|
||||
if (*p++ != *q++)
|
||||
goto cont;
|
||||
return(ccls[j]);
|
||||
cont:;
|
||||
}
|
||||
if (nccls >= NCCLS) {
|
||||
error("Too many character classes");
|
||||
exit(1);
|
||||
}
|
||||
p = ccl;
|
||||
q = ccls[j = nccls++];
|
||||
for (i = sizeof(ccls[j]); i--;)
|
||||
*q++ = *p++;
|
||||
return(ccls[j]);
|
||||
}
|
||||
|
||||
struct trans *
|
||||
newtrans(st, en)
|
||||
struct nfa *st, *en;
|
||||
{
|
||||
register struct trans *tp;
|
||||
|
||||
if ((tp = trnsp++) >= &trans[NTRANS]) {
|
||||
error("Too many translations");
|
||||
exit(1);
|
||||
}
|
||||
tp->t_start = st;
|
||||
tp->t_final = en;
|
||||
en->n_trans = tp;
|
||||
return(tp);
|
||||
}
|
||||
|
||||
/*
|
||||
* create a new set.
|
||||
* `sf', if set, indicates
|
||||
* that the elements of the
|
||||
* set are states of an NFA).
|
||||
* If `sf' is not set, the
|
||||
* elements are state numbers of
|
||||
* a DFA.
|
||||
*/
|
||||
struct set *
|
||||
newset(v, i, sf)
|
||||
register struct nfa **v;
|
||||
register i;
|
||||
{
|
||||
register struct set *t;
|
||||
register k;
|
||||
int setcomp();
|
||||
|
||||
qsort(v, i, sizeof(*v), setcomp);
|
||||
for (t = setlist; t; t = t->s_next)
|
||||
if (t->s_len==i && eqvec(t->s_els, v, i))
|
||||
return(t);
|
||||
t = lalloc(1, sizeof(*t)+i*sizeof(t->s_els[0]), "set nodes");
|
||||
t->s_next = setlist;
|
||||
setlist = t;
|
||||
t->s_final = 0;
|
||||
t->s_state = 0;
|
||||
t->s_flag = 0;
|
||||
t->s_len = i;
|
||||
t->s_group = 0;
|
||||
t->s_look = 0;
|
||||
for (v += i; i;) {
|
||||
--v;
|
||||
if (sf) {
|
||||
if ((*v)->n_char==FIN)
|
||||
t->s_final = (*v)-nfa;
|
||||
if ((*v)->n_flag&LOOK)
|
||||
t->s_look |= 1<<(*v)->n_look;
|
||||
} else {
|
||||
k = *v;
|
||||
dfa[k].df_name->s_group = t;
|
||||
}
|
||||
t->s_els[--i] = *v;
|
||||
}
|
||||
return(t);
|
||||
}
|
||||
|
||||
setcomp(n1p, n2p)
|
||||
struct nfa **n1p, **n2p;
|
||||
{
|
||||
register struct nfa *n1, *n2;
|
||||
|
||||
n1 = *n1p;
|
||||
n2 = *n2p;
|
||||
if (n1 > n2)
|
||||
return(1);
|
||||
if (n1==n2)
|
||||
return(0);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
eqvec(a, b, i)
|
||||
register *a, *b, i;
|
||||
{
|
||||
if (i)
|
||||
do {
|
||||
if (*a++ != *b++)
|
||||
return(0);
|
||||
} while (--i);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ask for core, and
|
||||
* complain if there is no more.
|
||||
*/
|
||||
char *
|
||||
lalloc(n, s, w)
|
||||
char *w;
|
||||
{
|
||||
register char *cp;
|
||||
|
||||
if ((cp = calloc(n, s)) == NULL) {
|
||||
fprintf(stderr, "No space for %s", w);
|
||||
#ifdef DEBUG
|
||||
if (lldebug)
|
||||
dfaprint();
|
||||
#endif
|
||||
exit(1);
|
||||
}
|
||||
return(cp);
|
||||
}
|
||||
|
||||
|
||||
/* Added -PB */
|
||||
error(s,x)
|
||||
char *s;
|
||||
{
|
||||
fprintf(stderr, s, x);
|
||||
}
|
||||
|
||||
fgetname(fd, s)
|
||||
FILE *fd;
|
||||
char *s;
|
||||
{
|
||||
SYSJFNS(mkbptr(s), cjfn(fd), 0);
|
||||
}
|
||||
|
||||
concat(out, in1, in2, in3) /* minimal version */
|
||||
char *out, *in1, *in2, *in3;
|
||||
{
|
||||
while( *in1 )
|
||||
*out++ = *in1++;
|
||||
|
||||
while( *in2 )
|
||||
*out++ = *in2++;
|
||||
|
||||
*out = '\0';
|
||||
}
|
||||
1
c20/lex/lex.ccl
Normal file
1
c20/lex/lex.ccl
Normal file
@@ -0,0 +1 @@
|
||||
/NOLOC BASE.REL, DFA.REL, ECLOSU.REL, LEX.REL, LEXSRT.REL, MIN.REL, OUT.REL, YTAB.REL, IMPURE.REL
|
||||
19
c20/lex/lex.ctl
Normal file
19
c20/lex/lex.ctl
Normal file
@@ -0,0 +1,19 @@
|
||||
; BUILD DECUS LEX FOR TOPS-20
|
||||
@DEF C: MSC:<C>, PS:<C>
|
||||
@DEF SS: MSC:
|
||||
@DEF CLIB: MSC:<C.PCC20LIB>
|
||||
@DEF SYS: SYS:, C:
|
||||
|
||||
@PCC20 BASE.C
|
||||
@PCC20 ECLOSU.C
|
||||
@PCC20 MIN.C
|
||||
@PCC20 DFA.C
|
||||
@PCC20 OUT.C
|
||||
@PCC20 LEX.C
|
||||
@PCC20 YTAB.C
|
||||
@PCC20 LEXSRT.C
|
||||
@PCC20 IMPURE.C
|
||||
|
||||
@STINKR
|
||||
*X LEX
|
||||
*Q
|
||||
51
c20/lex/lex.h
Normal file
51
c20/lex/lex.h
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
/*
|
||||
* lex library header file -- accessed through
|
||||
* #include <lex.h>
|
||||
*/
|
||||
|
||||
/*
|
||||
* description of scanning
|
||||
* tables.
|
||||
* the entries at the front of
|
||||
* the struct must remain in
|
||||
* place for the assembler routines
|
||||
* to find.
|
||||
*/
|
||||
struct lextab {
|
||||
int llendst; /* Last state number */
|
||||
char *lldefault; /* Default state table */
|
||||
char *llnext; /* Next state table */
|
||||
char *llcheck; /* Check table */
|
||||
int *llbase; /* Base table */
|
||||
int llnxtmax; /* Last in base table */
|
||||
|
||||
int (*llmove)(); /* Move between states */
|
||||
int *llfinal; /* Final state descriptions */
|
||||
int (*llactr)(); /* Action routine */
|
||||
int *lllook; /* Look ahead vector if != NULL */
|
||||
char *llign; /* Ignore char vec if != NULL */
|
||||
char *llbrk; /* Break char vec if != NULL */
|
||||
char *llill; /* Illegal char vec if != NULL */
|
||||
};
|
||||
|
||||
extern struct lextab *_tabp;
|
||||
|
||||
/* extern FILE *lexin; */ /* scanner input file */
|
||||
|
||||
/*PLB #define lexval yylval */
|
||||
#define LEXERR 256
|
||||
#define LEXSKIP (-1)
|
||||
/*
|
||||
* #define LEXECHO(fp) {lexecho((fp));}
|
||||
*/
|
||||
extern int lexval;
|
||||
extern int yyline;
|
||||
|
||||
extern char llbuf[];
|
||||
extern char *llend;
|
||||
#define lextext llbuf
|
||||
#define lexlast llend
|
||||
|
||||
#define _lmovb _lmvb
|
||||
#define _lmovi _lmvi
|
||||
BIN
c20/lex/lex.hlp
Normal file
BIN
c20/lex/lex.hlp
Normal file
Binary file not shown.
172
c20/lex/lex.log
Normal file
172
c20/lex/lex.log
Normal file
@@ -0,0 +1,172 @@
|
||||
|
||||
20-Feb-83 17:48:20
|
||||
|
||||
BATCON Version 104(4205) GLXLIB Version 1(1137)
|
||||
|
||||
Job LEX Req #6 for BUDNE in Stream 0
|
||||
|
||||
OUTPUT: Nolog TIME-LIMIT: 0:05:00
|
||||
UNIQUE: Yes BATCH-LOG: Supersede
|
||||
RESTART: Yes ASSISTANCE: Yes
|
||||
SEQUENCE: 3773
|
||||
|
||||
Input from => MSC:<C.LEX>LEX.CTL.5
|
||||
Output to => MSC:<C.LEX>LEX.LOG
|
||||
|
||||
|
||||
|
||||
17:48:20 MONTR MRFORT - The Fortran Development System, TOPS-20 Monitor 5.1(5050)
|
||||
17:48:20 MONTR Job 10 on TTY231 20-Feb-83 17:48:21
|
||||
17:48:21 USER FTN: mounted
|
||||
17:48:21 USER LNK: mounted
|
||||
17:48:21 USER TST: mounted
|
||||
17:48:21 USER MSC: mounted, accessed
|
||||
17:48:21 MONTR End of BATCH.CMD.2
|
||||
17:48:22 MONTR End of ORIGINAL.CMD.2
|
||||
17:48:22 MONTR @
|
||||
17:48:22 MONTR [CONNECTED TO MSC:<C.LEX>]
|
||||
; BUILD DECUS LEX FOR TOPS-20
|
||||
17:48:23 MONTR @DEF C: MSC:<C>, PS:<C>
|
||||
17:48:23 MONTR @@DEF SS: MSC:
|
||||
17:48:23 MONTR
|
||||
17:48:23 MONTR @@DEF CLIB: MSC:<C.PCC20LIB>
|
||||
17:48:23 MONTR
|
||||
17:48:23 MONTR @@DEF SYS: SYS:, C:
|
||||
17:48:23 MONTR
|
||||
17:48:23 MONTR @
|
||||
|
||||
17:48:23 MONTR @i lo job
|
||||
17:48:23 MONTR BP: => PS:<BUDNE>
|
||||
17:48:23 MONTR C: => MSC:<C>,PS:<C>
|
||||
17:48:23 MONTR CLIB: => MSC:<C.PCC20LIB>
|
||||
17:48:23 MONTR DSK: => DSK:,ME:
|
||||
17:48:23 MONTR F: => FTN:,M:,T:
|
||||
17:48:23 MONTR LEX: => MSC:<C.LEX>
|
||||
17:48:23 MONTR M: => MSC:
|
||||
17:48:23 MONTR ME: => M:<BUDNE>,BP:
|
||||
17:48:23 MONTR SS: => MSC:
|
||||
17:48:23 MONTR SYS: => SYS:,C:
|
||||
17:48:23 MONTR T: => TST:
|
||||
17:48:23 MONTR U: => PS:<UNSUPPORTED>
|
||||
17:48:23 MONTR @@v sys:pcc20*
|
||||
17:48:24 MONTR
|
||||
17:48:24 MONTR MSC:<C>
|
||||
17:48:24 MONTR PCC20.EXE.1;P777700 37 18944(36) 21-Dec-82 20:34:39 BUDNE
|
||||
17:48:24 MONTR .HLP.1;P777700 2 3227(7) 21-Dec-82 20:46:27 BUDNE
|
||||
17:48:24 MONTR PCC20LIB.DIRECTORY.1;P20200 0 0(0) 18-Feb-83 14:15:18 BUDNE
|
||||
17:48:24 MONTR
|
||||
17:48:24 MONTR Total of 39 pages in 3 files
|
||||
17:48:24 MONTR @@v c:pcc20*
|
||||
17:48:24 MONTR
|
||||
17:48:24 MONTR MSC:<C>
|
||||
17:48:24 MONTR PCC20.EXE.1;P777700 37 18944(36) 21-Dec-82 20:34:39 BUDNE
|
||||
17:48:24 MONTR .HLP.1;P777700 2 3227(7) 21-Dec-82 20:46:27 BUDNE
|
||||
17:48:24 MONTR PCC20LIB.DIRECTORY.1;P20200 0 0(0) 18-Feb-83 14:15:18 BUDNE
|
||||
17:48:24 MONTR
|
||||
17:48:24 MONTR Total of 39 pages in 3 files
|
||||
17:48:25 MONTR @
|
||||
|
||||
17:48:25 MONTR @PCC20 BASE.C
|
||||
17:48:27 USER ^[<^[[?2l"BASE.C", line 115: warning: illegal structure pointer combination, op =
|
||||
17:48:31 USER "BASE.C", line 116: warning: illegal structure pointer combination, op RETURN
|
||||
17:48:33 USER ^[<^[[?2l^[<^[[?2l^[<^[[?2l^[<^[[?2l@@PCC20 ECLOSU.C
|
||||
17:48:40 USER ^[<^[[?2l^[<^[[?2l^[<^[[?2l^[<^[[?2l^[<^[[?2l
|
||||
17:48:47 MONTR @@PCC20 MIN.C
|
||||
17:48:52 USER ^[<^[[?2l"MIN.C", line 74: warning: illegal pointer combination, op =
|
||||
17:48:55 USER "MIN.C", line 75: warning: illegal pointer combination, op =
|
||||
17:48:56 USER "MIN.C", line 76: warning: illegal pointer combination, op =
|
||||
17:48:56 USER "MIN.C", line 93: warning: illegal pointer combination, op =
|
||||
17:48:56 USER "MIN.C", line 96: warning: illegal pointer combination, op -
|
||||
17:48:56 USER "MIN.C", line 126: warning: illegal pointer combination, op =
|
||||
17:48:57 USER "MIN.C", line 130: warning: illegal pointer combination, op -
|
||||
17:48:57 USER "MIN.C", line 132: warning: illegal pointer/integer combination, op =
|
||||
17:48:57 USER "MIN.C", line 136: warning: illegal pointer combination, op -
|
||||
17:48:57 USER "MIN.C", line 138: warning: illegal pointer/integer combination, op =
|
||||
17:48:57 USER "MIN.C", line 143: warning: illegal pointer combination, op =
|
||||
17:48:58 USER ^[<^[[?2l^[<^[[?2l^[<^[[?2l^[<^[[?2l@@PCC20 DFA.C
|
||||
17:49:08 USER ^[<^[[?2l"DFA.C", line 52: warning: illegal pointer combination, op =
|
||||
17:49:11 USER "DFA.C", line 62: warning: illegal pointer combination, op =
|
||||
17:49:12 USER "DFA.C", line 70: warning: struct/union or struct/union pointer required
|
||||
17:49:12 USER "DFA.C", line 72: warning: illegal pointer combination, op =
|
||||
17:49:12 USER "DFA.C", line 79: warning: illegal pointer combination, op =
|
||||
17:49:12 USER "DFA.C", line 83: warning: struct/union or struct/union pointer required
|
||||
17:49:12 USER "DFA.C", line 84: warning: struct/union or struct/union pointer required
|
||||
17:49:12 USER "DFA.C", line 84: warning: illegal pointer/integer combination, op =
|
||||
17:49:12 USER "DFA.C", line 85: warning: illegal pointer/integer combination, op =
|
||||
17:49:12 USER "DFA.C", line 86: warning: struct/union or struct/union pointer required
|
||||
17:49:12 USER "DFA.C", line 87: warning: illegal pointer combination, op =
|
||||
17:49:13 USER "DFA.C", line 101: warning: struct/union or struct/union pointer required
|
||||
17:49:13 USER "DFA.C", line 102: warning: struct/union or struct/union pointer required
|
||||
17:49:14 USER "DFA.C", line 165: warning: illegal pointer/integer combination, op =
|
||||
17:49:14 USER "DFA.C", line 167: warning: illegal pointer/integer combination, op RETURN
|
||||
17:49:14 USER "DFA.C", line 171: warning: illegal pointer/integer combination, op =
|
||||
17:49:14 USER "DFA.C", line 172: warning: illegal pointer/integer combination, op RETURN
|
||||
17:49:14 USER "DFA.C", line 194: warning: illegal pointer/integer combination, op RETURN
|
||||
17:49:14 USER "DFA.C", line 199: warning: illegal pointer/integer combination, op RETURN
|
||||
17:49:14 USER ^[<^[[?2l^[<^[[?2l^[<^[[?2l^[<^[[?2l@@PCC20 OUT.C
|
||||
17:49:25 USER ^[<^[[?2l"OUT.C", line 144: warning: illegal pointer/integer combination, op =
|
||||
17:49:30 USER "OUT.C", line 165: warning: illegal pointer/integer combination, op RETURN
|
||||
17:49:31 USER "OUT.C", line 199: warning: illegal pointer/integer combination, op RETURN
|
||||
17:49:35 USER ^[<^[[?2l^[<^[[?2l^[<^[[?2l^[<^[[?2l@@PCC20 LEX.C
|
||||
17:49:47 USER ^[<^[[?2l"LEX.C", line 208: warning: illegal pointer/integer combination, op =
|
||||
17:49:52 USER "LEX.C", line 209: warning: illegal pointer/integer combination, op =
|
||||
17:49:53 USER "LEX.C", line 290: warning: illegal pointer/integer combination, op =
|
||||
17:49:54 USER "LEX.C", line 295: warning: illegal pointer/integer combination, op =
|
||||
17:49:54 USER "LEX.C", line 298: warning: illegal pointer/integer combination, op =
|
||||
17:49:55 USER "LEX.C", line 403: warning: illegal pointer/integer combination, op RETURN
|
||||
17:49:56 USER "LEX.C", line 472: warning: illegal pointer combination, op =
|
||||
17:49:56 USER "LEX.C", line 489: warning: illegal pointer/integer combination, op =
|
||||
17:49:59 USER ^[<^[[?2l^[<^[[?2l^[<^[[?2l^[<^[[?2l@@PCC20 YTAB.C
|
||||
17:50:12 USER ^[<^[[?2l"lex.y", line 65: warning: illegal pointer/integer combination, op =
|
||||
17:50:15 USER "lex.y", line 66: warning: illegal pointer/integer combination, op =
|
||||
17:50:15 USER "lex.y", line 77: warning: illegal pointer combination, op =
|
||||
17:50:15 USER "lex.y", line 90: warning: illegal pointer/integer combination, op =
|
||||
17:50:15 USER "lex.y", line 98: warning: illegal pointer/integer combination, op =
|
||||
17:50:16 USER "lex.y", line 104: warning: illegal pointer/integer combination, op =
|
||||
17:50:16 USER "lex.y", line 107: warning: illegal pointer/integer combination, op =
|
||||
17:50:16 USER "lex.y", line 110: warning: illegal pointer/integer combination, op =
|
||||
17:50:16 USER "lex.y", line 113: warning: illegal pointer/integer combination, op =
|
||||
17:50:17 USER "lex.y", line 116: warning: illegal pointer/integer combination, op =
|
||||
17:50:17 USER "lex.y", line 119: warning: illegal pointer/integer combination, op =
|
||||
17:50:17 USER "YTAB.C", line 169: warning: illegal pointer combination, op =
|
||||
17:50:17 USER "YTAB.C", line 169: warning: illegal pointer/integer combination, op =
|
||||
17:50:17 USER "lex.y", line 134: warning: illegal pointer/integer combination, op =
|
||||
17:50:17 USER "lex.y", line 134: warning: illegal pointer/integer combination, op =
|
||||
17:50:18 USER "lex.y", line 143: warning: illegal pointer/integer combination, op =
|
||||
17:50:18 USER "lex.y", line 143: warning: illegal pointer/integer combination, op =
|
||||
17:50:18 USER "lex.y", line 148: warning: illegal pointer/integer combination, op =
|
||||
17:50:18 USER "lex.y", line 154: warning: illegal pointer/integer combination, op =
|
||||
17:50:20 USER "lex.y", line 197: warning: illegal pointer/integer combination, op =
|
||||
17:50:20 USER "YTAB.C", line 269: warning: illegal pointer/integer combination, op =
|
||||
17:50:20 USER "YTAB.C", line 269: warning: illegal pointer/integer combination, op =
|
||||
17:50:21 USER "lex.y", line 248: warning: illegal pointer/integer combination, op =
|
||||
17:50:22 USER "lex.y", line 290: warning: illegal pointer/integer combination, op =
|
||||
17:50:22 USER "lex.y", line 300: warning: illegal pointer/integer combination, op =
|
||||
17:50:22 USER "lex.y", line 341: warning: illegal pointer/integer combination, op =
|
||||
17:50:24 USER "lex.y", line 403: warning: illegal pointer/integer combination, op =
|
||||
17:50:24 USER "lex.y", line 421: warning: illegal pointer/integer combination, op =
|
||||
17:50:24 USER "lex.y", line 431: warning: illegal pointer combination, op =
|
||||
17:50:25 USER "lex.y", line 503: warning: illegal pointer combination, op =
|
||||
17:50:32 USER ^[<^[[?2l^[<^[[?2l^[<^[[?2l^[<^[[?2l@@PCC20 LEXSRT.C
|
||||
17:50:46 USER ^[<^[[?2l^[<^[[?2l^[<^[[?2l^[<^[[?2l^[<^[[?2l
|
||||
17:50:55 MONTR @@PCC20 IMPURE.C
|
||||
17:50:59 USER ^[<^[[?2l^[<^[[?2l^[<^[[?2l^[<^[[?2l^[<^[[?2l
|
||||
17:51:07 MONTR @
|
||||
|
||||
17:51:07 MONTR @STINKR
|
||||
17:51:09 USER ^[<^[[?2l
|
||||
=^[K*X LEX
|
||||
17:51:09 USER X LEX
|
||||
17:51:19 USER
|
||||
=^[K*Q
|
||||
17:51:19 USER Q
|
||||
17:51:33 USER
|
||||
17:51:33 USER --- Segments ---
|
||||
17:51:33 USER
|
||||
17:51:33 USER 0 0140 - 0156667 (0156530=56664)
|
||||
17:51:33 USER 1 0157000 - 0214227 (035230=15000)
|
||||
17:51:33 USER 2 0214230 - 0215136 (0707=455)
|
||||
17:51:33 USER 3 0215137 - 0220173 (03035=1565)
|
||||
17:51:35 USER ^[<^[[?2l^[<^[[?2l
|
||||
17:51:36 MONTR @@
|
||||
17:51:42 MONTR Killed by OPERATOR, TTY 222
|
||||
1717
c20/lex/lex.mem
Normal file
1717
c20/lex/lex.mem
Normal file
File diff suppressed because it is too large
Load Diff
660
c20/lex/lex.old
Normal file
660
c20/lex/lex.old
Normal file
@@ -0,0 +1,660 @@
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*/
|
||||
|
||||
/*
|
||||
* lex -- initialisation, allocation, set creation
|
||||
*
|
||||
* Revised for PDP-11 (Decus) C by Martin Minow
|
||||
*/
|
||||
|
||||
/* Modified 02-Dec-80 Bob Denny -- Conditionalized debug code for smaller size
|
||||
* 01 -- Moved calls to dfa build, min, print, write
|
||||
* and to stat, and code for ending() into
|
||||
* this module so that 'ytab' could be put
|
||||
* into overlay region.
|
||||
* 29-May-81 Bob Denny -- More extern hacking for RSX overlaying.
|
||||
* More 19-Mar-82 Bob Denny -- New C library & compiler
|
||||
* More 03-May-82 Bob Denny -- Final touches, remove unreferenced autos
|
||||
* 28-Aug-82 Bob Denny -- Add "-s" switch to supress references to
|
||||
* "stdio.h" in generated code. Add switch
|
||||
* comments in code. Add -e for "easy" com-
|
||||
* mand line. "lex -e file" is the short way
|
||||
* of saying:
|
||||
* "lex -i file.lxi -o file.c -t file"
|
||||
* More(!) 30-Oct-82 Bob Denny -- Fix RSX ODL to put lots of FCS junk into
|
||||
* overlay, pick up (badly needed) 3KW for
|
||||
* NFA nodes, etc. Change static allocations
|
||||
* in LEXLEX.H for RSX so can do non-trivial
|
||||
* things. Task is now big on RSX and grows
|
||||
* from big to huge as it runs.
|
||||
* Fix "-s" support so it is again possible
|
||||
* to do a lexswitch() (dumb!).
|
||||
*/
|
||||
|
||||
|
||||
/*)BUILD $(PROGRAM) = lex
|
||||
$(INCLUDE) = { lexlex.h ytab.h }
|
||||
$(FILES) = { base dfa eclosu lex impure
|
||||
min out1 out2 lexsrt ytab }
|
||||
$(STACK) = 4000
|
||||
$(TKBOPTIONS) = {
|
||||
STACK = 3000
|
||||
TASK = ...LEX
|
||||
;DON'T TRY TO USE FCSRES (RBD)
|
||||
}
|
||||
$(ODL) = {
|
||||
;
|
||||
; ODL FOR BUILDING LEX ON RSX11M.
|
||||
; BOB DENNY 29-MAY-81
|
||||
; BOB DENNY 19-MAR-82
|
||||
; BOB DENNY 03-MAY-82
|
||||
; BOB DENNY 30-OCT-82 PUT SOME FCS JUNK IN OVERLAY. REORGANIZE FOR
|
||||
; SIMPLICITY.
|
||||
;
|
||||
.NAME OVR1
|
||||
.NAME FCSJNK
|
||||
.NAME LXPROC
|
||||
.NAME PARSER
|
||||
.ROOT L0,L1
|
||||
;
|
||||
L0: .FCTR LEX-IMPURE-OUT2-LB:[1,1]C/LB
|
||||
;
|
||||
L1: .FCTR OVR1-*(FCS,STAT,PARS)
|
||||
;
|
||||
FCS: .FCTR FCSJNK-(F1,F2)
|
||||
;
|
||||
F1: .FCTR LB:[1,1]SYSLIB/LB:.CSI1:.CSI2
|
||||
F2: .FCTR LB:[1,1]SYSLIB/LB:OPEN-(OP1,OP2)
|
||||
;
|
||||
OP1: .FCTR LB:[1,1]SYSLIB/LB:CREATE:CLOSE:DEL:FINIT:MKDL:OPFNB:RQLCB
|
||||
OP2: .FCTR LB:[1,1]SYSLIB/LB:PARSE
|
||||
;
|
||||
STAT: .FCTR LXPROC-LEXSRT-DFA-BASE-ECLOSU-MIN-OUT1-LB:[1,1]C/LB
|
||||
;
|
||||
PARS: .FCTR PARSER-YTAB-LB:[1,1]C/LB
|
||||
;
|
||||
.END
|
||||
}
|
||||
$(OVR) = {
|
||||
LEX
|
||||
LEXSRT
|
||||
IMPURE
|
||||
$(SUPORT)
|
||||
$(RTLIB)
|
||||
DFA/O:1
|
||||
MIN/O:1
|
||||
OUT1/O:1
|
||||
YTAB/O:1
|
||||
BASE/O:2
|
||||
OUT2/O:2
|
||||
ECLOSU/O:2
|
||||
}
|
||||
*/
|
||||
|
||||
#ifdef DOCUMENTATION
|
||||
|
||||
title lex A Lexical Analyser Generator
|
||||
index A Lexical Analyser Generator
|
||||
|
||||
synopsis
|
||||
|
||||
lex [-options] [-i grammar] [-o outfile] [-t table]
|
||||
|
||||
description
|
||||
|
||||
Lex compiles a lexical analyser from a grammar and description of
|
||||
actions. It is described more fully in lex.doc: only usage is
|
||||
described. The following options are available:
|
||||
.lm +16
|
||||
.s.i-16;-a Disable recognition of non-ASCII characters
|
||||
(codes > 177 octal) for exception character classes (form [^ ...]).
|
||||
.s.i-16;-d Enable debugging code within lex. Normally
|
||||
needed only for debugging lex.
|
||||
.s.i-16;-e "Easy" command line. Saying "lex#-e#name" is the
|
||||
same as saying:
|
||||
.s.i 4;"lex -i name.lxi -o name.c -t name"
|
||||
.s
|
||||
Do not include devices or an extension on "name" or make it longer
|
||||
than 8 characters, or you'll get several error messages.
|
||||
.s.i-16;-i file Read the grammar from the file. If "-i" is not
|
||||
specified, input will be read from the standard input.
|
||||
.s.i-16;-m Enable state minimization. Currently not
|
||||
implemented, switch is a no-op.
|
||||
.s.i-16;-o file Write the output to the file. If "-o" is not
|
||||
specified, output will be written to file "lextab.c".
|
||||
.s.i-16;-s "Stand-alone" switch. Supresses the line
|
||||
"#include <stdio.h>" normally generated in the lex output. Use this
|
||||
if LEX is generating a module to be used in a program which does not
|
||||
use the "standard I/O" package.
|
||||
.s.i-16;-t table Name the recognizer "table" instead of the
|
||||
default "lextab". If -o is not given, output will be written to file
|
||||
"table.c".
|
||||
.s.i-16;-v [file] Verify -- write internal tables to the
|
||||
indicated file. If "-v" is given without a file name argument,
|
||||
tables will be written to "lex.out".
|
||||
.lm -16
|
||||
|
||||
diagnostics
|
||||
|
||||
The following error messages may occur on invocation. See lex
|
||||
documentation for information on compilation errors.
|
||||
.lm +8
|
||||
.s.i -8;Can't create ...
|
||||
.s.i -8;Cannot open ...
|
||||
.s.i -8;Illegal option.
|
||||
.s.i -8;Illegal switch combination.
|
||||
.s
|
||||
"-i", "-o" or "-t" given with "-e" or vice-versa
|
||||
.s.i -8;Table name too long.
|
||||
.s
|
||||
The table name (argument to "-t") must not be longer than 8 bytes.
|
||||
.s.i -8;Missing table name.
|
||||
.s.i -8;Missing input file.
|
||||
.s.i -8;Missing output file.
|
||||
.s.i -8;Missing name.
|
||||
.lm -8
|
||||
|
||||
author
|
||||
|
||||
Charles Forsyth
|
||||
Modified by Bob Denny
|
||||
bugs
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
extern char *lalloc();
|
||||
extern char *tolower();
|
||||
|
||||
struct nfa nfa[MAXNFA];
|
||||
struct nfa *nfap = &nfa[1];
|
||||
|
||||
struct xset sets[NCHARS];
|
||||
char insets[NCHARS];
|
||||
|
||||
struct trans trans[NTRANS];
|
||||
struct trans *transp = &trans[0];
|
||||
|
||||
char ccls[NCCLS][(NCHARS+1)/NBPC];
|
||||
int nccls;
|
||||
|
||||
int ndfa;
|
||||
struct dfa dfa[MAXDFA];
|
||||
struct move move[NNEXT];
|
||||
|
||||
char *tabname = "lextab";
|
||||
char tabfile[15];
|
||||
char *infile = NULL;
|
||||
char *outfile = NULL;
|
||||
|
||||
#ifdef DEBUG
|
||||
char *dumpfile = "lex.out";
|
||||
int lldebug = 0;
|
||||
#endif
|
||||
|
||||
int llnxtmax = 0;
|
||||
|
||||
FILE *llout;
|
||||
FILE *lexin;
|
||||
FILE *lexlog;
|
||||
|
||||
/*
|
||||
* Flags. Allow globals only for
|
||||
* those requiring same. Some only
|
||||
* used for checking for bad combos.
|
||||
*/
|
||||
int aflag = 0; /* Ignore non-ASCII in [^ ...] */
|
||||
static int eflag = 0; /* Easy command line */
|
||||
static int iflag = 0; /* "-i" given */
|
||||
int mflag = 0; /* Enable state minimization (not imp.) */
|
||||
static int oflag = 0; /* "-o" given */
|
||||
int sflag = 0; /* Supress "#include <stdio.h>" in output */
|
||||
static int tflag = 0; /* "-t" given */
|
||||
|
||||
struct set *setlist = 0;
|
||||
|
||||
main(argc, argv)
|
||||
char **argv;
|
||||
{
|
||||
register char *cp, *cp2;
|
||||
|
||||
#ifdef DEBUG
|
||||
int vflag;
|
||||
vflag = 0;
|
||||
#endif
|
||||
|
||||
for (; argc>1 && *argv[1]=='-'; argv++, argc--)
|
||||
switch (tolower(argv[1][1])) {
|
||||
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
* Create "verification" file, describing the
|
||||
* scanner.
|
||||
*/
|
||||
case 'v': /* -v => lex.out */
|
||||
vflag++; /* -v x.out => x.out */
|
||||
if (argc > 2 && argv[2][1] != '1') {
|
||||
--argc;
|
||||
dumpfile = (++argv)[1];
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* Enable debug displays
|
||||
*/
|
||||
case 'd':
|
||||
lldebug++;
|
||||
break;
|
||||
#endif
|
||||
/*
|
||||
* Enable state minimization. Currently not
|
||||
* implemented.
|
||||
*/
|
||||
case 'm':
|
||||
mflag++;
|
||||
break;
|
||||
|
||||
/*
|
||||
* Disable matching of non-ASCII characters (codes > 177(8))
|
||||
* for exception character classes (form "[^ ...]").
|
||||
*/
|
||||
case 'a':
|
||||
aflag++;
|
||||
break;
|
||||
|
||||
/*
|
||||
* Supress "#include <stdio.h>" in generated
|
||||
* code for programs not using standard I/O.
|
||||
*/
|
||||
case 's':
|
||||
sflag++;
|
||||
break;
|
||||
|
||||
/*
|
||||
* "Easy" command line
|
||||
*/
|
||||
case 'e':
|
||||
if(iflag || oflag || tflag) {
|
||||
error("Illegal switch combination\n");
|
||||
exit(1);
|
||||
}
|
||||
if (--argc <= 1) {
|
||||
error("Missing name\n");
|
||||
exit(1);
|
||||
}
|
||||
if (strlen(tabname = (++argv)[1]) > 8) {
|
||||
error("Name too long\n");
|
||||
exit(1);
|
||||
}
|
||||
infile = malloc(14);
|
||||
outfile = malloc(12);
|
||||
concat(infile, tabname, ".lxi", 0);
|
||||
if (freopen(infile, "r", stdin) == NULL) {
|
||||
error("Cannot open input \"%s\"\n", infile);
|
||||
exit(1);
|
||||
}
|
||||
concat(outfile, tabname, ".c", 0);
|
||||
break;
|
||||
|
||||
/*
|
||||
* Specify input file name. Default = terminal (stdin)
|
||||
*/
|
||||
case 'i':
|
||||
if (eflag) {
|
||||
error("Illegal switch combination\n");
|
||||
exit(1);
|
||||
}
|
||||
iflag++;
|
||||
if (--argc <= 1) {
|
||||
error("Missing input file\n");
|
||||
exit(1);
|
||||
}
|
||||
infile = (++argv)[1];
|
||||
if (freopen(infile, "r", stdin) == NULL) {
|
||||
error("Cannot open input \"%s\"\n", infile);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* Specify output file name. Default = "lextab.c"
|
||||
*/
|
||||
case 'o':
|
||||
if (eflag) {
|
||||
error("Illegal switch combination\n");
|
||||
exit(1);
|
||||
}
|
||||
oflag++;
|
||||
if (--argc <= 1) {
|
||||
error("Missing output file");
|
||||
exit(1);
|
||||
}
|
||||
outfile = (++argv)[1];
|
||||
break;
|
||||
|
||||
/*
|
||||
* Specify table name. Default = "lextab". If "-o"
|
||||
* not given, output will go to "tabname.c".
|
||||
*/
|
||||
case 't':
|
||||
if (eflag) {
|
||||
error("Illegal switch combination\n");
|
||||
exit(1);
|
||||
}
|
||||
tflag++;
|
||||
if (--argc <= 1) {
|
||||
error("Missing table name");
|
||||
exit(1);
|
||||
}
|
||||
if (strlen(tabname = (++argv)[1]) > 8) {
|
||||
error("Table name too long\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
error("Illegal option: %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
lexin = stdin;
|
||||
|
||||
#ifdef DEBUG
|
||||
cp = (vflag) ? dumpfile : "nl:"; /* Dec specific */
|
||||
if ((lexlog = fopen(cp, "w")) == NULL) {
|
||||
error("Cannot open \"%s\"", cp);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (infile == NULL) {
|
||||
infile = malloc(31);
|
||||
fgetname(lexin, infile);
|
||||
}
|
||||
cp = infile; /* Fold infile to lower case */
|
||||
while(*cp)
|
||||
*cp++ = tolower(*cp);
|
||||
cp = tabname; /* Fold tabname to lower case */
|
||||
while(*cp)
|
||||
*cp++ = tolower(*cp);
|
||||
if (outfile == NULL) {
|
||||
/*
|
||||
* Typical hacker's idiom!
|
||||
*/
|
||||
for (cp = tabname, cp2 = tabfile; *cp2 = *cp++;)
|
||||
cp2++;
|
||||
for (cp = ".c"; *cp2++ = *cp++;)
|
||||
;
|
||||
outfile = tabfile;
|
||||
}
|
||||
if ((llout = freopen(outfile, "w", stdout))==NULL) {
|
||||
error("Can't create %s\n", outfile);
|
||||
exit(1);
|
||||
}
|
||||
heading();
|
||||
if (yyparse())
|
||||
error("Parse failed\n");
|
||||
dfabuild(); /* 01+ */
|
||||
dfamin();
|
||||
dfaprint();
|
||||
dfawrite();
|
||||
#ifdef DEBUG
|
||||
stats();
|
||||
#endif /* 01- */
|
||||
} /** END OF MAIN **/
|
||||
|
||||
/*
|
||||
* This module was moved here from out.c so it could be called from
|
||||
* ytab.c residing in same overlay region as out.c.
|
||||
* 02-Dec-80 Bob Denny.
|
||||
*/
|
||||
/* 01+ */
|
||||
ending()
|
||||
{
|
||||
static int ended;
|
||||
|
||||
if (ended++)
|
||||
return;
|
||||
fprintf(llout, "\t}\n\treturn(LEXSKIP);\n}\n");
|
||||
setline();
|
||||
}
|
||||
/* 01- */
|
||||
|
||||
#ifdef DEBUG
|
||||
stats()
|
||||
{
|
||||
fprintf(lexlog, "\n");
|
||||
fprintf(lexlog, "%d/%d NFA states, %d/%d DFA states\n",
|
||||
nfap-nfa, MAXNFA, ndfa, MAXDFA);
|
||||
fprintf(lexlog, "%d/%d entries in move vectors\n", llnxtmax, NNEXT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print a state set on { ... } form on lexlog.
|
||||
*/
|
||||
pset(t, nf)
|
||||
register struct set *t;
|
||||
{
|
||||
register i;
|
||||
|
||||
fprintf(lexlog, "{");
|
||||
for (i = 0; i < t->s_len; i++)
|
||||
if (nf)
|
||||
fprintf(lexlog, " %d", t->s_els[i]-nfa); else
|
||||
fprintf(lexlog, " %d", t->s_els[i]);
|
||||
fprintf(lexlog, "}");
|
||||
}
|
||||
|
||||
/*
|
||||
* Print a character to lexlog in readable form.
|
||||
* Returns the number of characters generated.
|
||||
*/
|
||||
chprint(ch)
|
||||
{
|
||||
register char *s;
|
||||
|
||||
ch &= 0377;
|
||||
switch (ch) {
|
||||
case '\t':
|
||||
s = "\\t";
|
||||
break;
|
||||
case '\n':
|
||||
s = "\\n";
|
||||
break;
|
||||
case '\b':
|
||||
s = "\\b";
|
||||
break;
|
||||
case '\r':
|
||||
s = "\\r";
|
||||
break;
|
||||
default:
|
||||
if(ch<040 || ch>=0177)
|
||||
{
|
||||
fprintf(lexlog, "\\%03o", ch);
|
||||
return(4);
|
||||
}
|
||||
else
|
||||
{
|
||||
putc(ch, lexlog);
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
fprintf(lexlog, s);
|
||||
return(2);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The following functions simply
|
||||
* allocate various kinds of
|
||||
* structures.
|
||||
*/
|
||||
struct nfa *
|
||||
newnfa(ch, nf1, nf2)
|
||||
struct nfa *nf1, *nf2;
|
||||
{
|
||||
register struct nfa *nf;
|
||||
|
||||
if ((nf = nfap++) >= &nfa[MAXNFA]) {
|
||||
error("Too many NFA states");
|
||||
exit(1);
|
||||
}
|
||||
nf->n_char = ch;
|
||||
nf->n_succ[0] = nf1;
|
||||
nf->n_succ[1] = nf2;
|
||||
nf->n_trans = 0;
|
||||
nf->n_flag = 0;
|
||||
nf->n_look = 0;
|
||||
return(nf);
|
||||
}
|
||||
|
||||
newdfa()
|
||||
{
|
||||
register struct dfa *df;
|
||||
|
||||
if ((df = &dfa[ndfa++]) >= &dfa[MAXDFA]) {
|
||||
error("Out of dfa states");
|
||||
exit(1);
|
||||
}
|
||||
return(df);
|
||||
}
|
||||
|
||||
char *
|
||||
newccl(ccl)
|
||||
char *ccl;
|
||||
{
|
||||
register char *p, *q;
|
||||
register i;
|
||||
int j;
|
||||
|
||||
for (j = 0; j < nccls; j++) {
|
||||
p = ccl;
|
||||
q = ccls[j];
|
||||
for (i = sizeof(ccls[j]); i--;)
|
||||
if (*p++ != *q++)
|
||||
goto cont;
|
||||
return(ccls[j]);
|
||||
cont:;
|
||||
}
|
||||
if (nccls >= NCCLS) {
|
||||
error("Too many character classes");
|
||||
exit(1);
|
||||
}
|
||||
p = ccl;
|
||||
q = ccls[j = nccls++];
|
||||
for (i = sizeof(ccls[j]); i--;)
|
||||
*q++ = *p++;
|
||||
return(ccls[j]);
|
||||
}
|
||||
|
||||
struct trans *
|
||||
newtrans(st, en)
|
||||
struct nfa *st, *en;
|
||||
{
|
||||
register struct trans *tp;
|
||||
|
||||
if ((tp = transp++) >= &trans[NTRANS]) {
|
||||
error("Too many translations");
|
||||
exit(1);
|
||||
}
|
||||
tp->t_start = st;
|
||||
tp->t_final = en;
|
||||
en->n_trans = tp;
|
||||
return(tp);
|
||||
}
|
||||
|
||||
/*
|
||||
* create a new set.
|
||||
* `sf', if set, indicates
|
||||
* that the elements of the
|
||||
* set are states of an NFA).
|
||||
* If `sf' is not set, the
|
||||
* elements are state numbers of
|
||||
* a DFA.
|
||||
*/
|
||||
struct set *
|
||||
newset(v, i, sf)
|
||||
register struct nfa **v;
|
||||
register i;
|
||||
{
|
||||
register struct set *t;
|
||||
register k;
|
||||
int setcomp();
|
||||
|
||||
qsort(v, i, sizeof(*v), setcomp);
|
||||
for (t = setlist; t; t = t->s_next)
|
||||
if (t->s_len==i && eqvec(t->s_els, v, i))
|
||||
return(t);
|
||||
t = lalloc(1, sizeof(*t)+i*sizeof(t->s_els[0]), "set nodes");
|
||||
t->s_next = setlist;
|
||||
setlist = t;
|
||||
t->s_final = 0;
|
||||
t->s_state = 0;
|
||||
t->s_flag = 0;
|
||||
t->s_len = i;
|
||||
t->s_group = 0;
|
||||
t->s_look = 0;
|
||||
for (v += i; i;) {
|
||||
--v;
|
||||
if (sf) {
|
||||
if ((*v)->n_char==FIN)
|
||||
t->s_final = (*v)-nfa;
|
||||
if ((*v)->n_flag&LOOK)
|
||||
t->s_look |= 1<<(*v)->n_look;
|
||||
} else {
|
||||
k = *v;
|
||||
dfa[k].df_name->s_group = t;
|
||||
}
|
||||
t->s_els[--i] = *v;
|
||||
}
|
||||
return(t);
|
||||
}
|
||||
|
||||
setcomp(n1p, n2p)
|
||||
struct nfa **n1p, **n2p;
|
||||
{
|
||||
register struct nfa *n1, *n2;
|
||||
|
||||
n1 = *n1p;
|
||||
n2 = *n2p;
|
||||
if (n1 > n2)
|
||||
return(1);
|
||||
if (n1==n2)
|
||||
return(0);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
eqvec(a, b, i)
|
||||
register *a, *b, i;
|
||||
{
|
||||
if (i)
|
||||
do {
|
||||
if (*a++ != *b++)
|
||||
return(0);
|
||||
} while (--i);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ask for core, and
|
||||
* complain if there is no more.
|
||||
*/
|
||||
char *
|
||||
lalloc(n, s, w)
|
||||
char *w;
|
||||
{
|
||||
register char *cp;
|
||||
|
||||
if ((cp = calloc(n, s)) == NULL) {
|
||||
fprintf(stderr, "No space for %s", w);
|
||||
#ifdef DEBUG
|
||||
if (lldebug)
|
||||
dfaprint();
|
||||
#endif
|
||||
exit(1);
|
||||
}
|
||||
return(cp);
|
||||
}
|
||||
75
c20/lex/lex.rnh
Normal file
75
c20/lex/lex.rnh
Normal file
@@ -0,0 +1,75 @@
|
||||
.lit
|
||||
lex A Lexical Analyser Generator
|
||||
|
||||
synopsis
|
||||
|
||||
lex [-options] [-i grammar] [-o outfile] [-t table]
|
||||
|
||||
description
|
||||
|
||||
Lex compiles a lexical analyser from a grammar and description of
|
||||
actions. It is described more fully in lex.doc: only usage is
|
||||
described. The following options are available:
|
||||
.el
|
||||
.lm +16
|
||||
.s.i-16;-a Disable recognition of non-ASCII characters
|
||||
(codes > 177 octal) for exception character classes (form [^ ...]).
|
||||
.s.i-16;-d Enable debugging code within lex. Normally
|
||||
needed only for debugging lex.
|
||||
.s.i-16;-e "Easy" command line. Saying "lex#-e#name" is the
|
||||
same as saying:
|
||||
.s.i 4;"lex -i name.lxi -o name.c -t name"
|
||||
.s
|
||||
Do not include devices or an extension on "name" or make it longer
|
||||
than 8 characters, or you'll get several error messages.
|
||||
.s.i-16;-i file Read the grammar from the file. If "-i" is not
|
||||
specified, input will be read from the standard input.
|
||||
.s.i-16;-m Enable state minimization. Currently not
|
||||
implemented, switch is a no-op.
|
||||
.s.i-16;-o file Write the output to the file. If "-o" is not
|
||||
specified, output will be written to file "lextab.c".
|
||||
.s.i-16;-s "Stand-alone" switch. Supresses the line
|
||||
"#include <stdio.h>" normally generated in the lex output. Use this
|
||||
if LEX is generating a module to be used in a program which does not
|
||||
use the "standard I/O" package.
|
||||
.s.i-16;-t table Name the recognizer "table" instead of the
|
||||
default "lextab". If -o is not given, output will be written to file
|
||||
"table.c".
|
||||
.s.i-16;-v [file] Verify -- write internal tables to the
|
||||
indicated file. If "-v" is given without a file name argument,
|
||||
tables will be written to "lex.out".
|
||||
.lm -16
|
||||
|
||||
.lit
|
||||
|
||||
diagnostics
|
||||
|
||||
The following error messages may occur on invocation. See lex
|
||||
documentation for information on compilation errors.
|
||||
|
||||
.el
|
||||
.lm +8
|
||||
.s.i -8;Can't create ...
|
||||
.s.i -8;Cannot open ...
|
||||
.s.i -8;Illegal option.
|
||||
.s.i -8;Illegal switch combination.
|
||||
.s
|
||||
"-i", "-o" or "-t" given with "-e" or vice-versa
|
||||
.s.i -8;Table name too long.
|
||||
.s
|
||||
The table name (argument to "-t") must not be longer than 8 bytes.
|
||||
.s.i -8;Missing table name.
|
||||
.s.i -8;Missing input file.
|
||||
.s.i -8;Missing output file.
|
||||
.s.i -8;Missing name.
|
||||
.lm -8
|
||||
|
||||
.lit
|
||||
|
||||
author
|
||||
|
||||
Charles Forsyth
|
||||
Modified by Bob Denny
|
||||
bugs
|
||||
|
||||
.el
|
||||
2084
c20/lex/lex.rno
Normal file
2084
c20/lex/lex.rno
Normal file
File diff suppressed because it is too large
Load Diff
11
c20/lex/lex.stinkr
Normal file
11
c20/lex/lex.stinkr
Normal file
@@ -0,0 +1,11 @@
|
||||
x clib:stdio
|
||||
l lex
|
||||
l lexsrt
|
||||
l dfa
|
||||
l min
|
||||
l out
|
||||
l ytab
|
||||
l base
|
||||
l eclosu
|
||||
l impure
|
||||
o lex.exe
|
||||
596
c20/lex/lex.y
Normal file
596
c20/lex/lex.y
Normal file
@@ -0,0 +1,596 @@
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*/
|
||||
|
||||
/*
|
||||
* W A R N I N G
|
||||
*
|
||||
* This file is NOT identical with ytab.c. Several changes which were
|
||||
* made directly to ytab.c have not been made to lex.y
|
||||
*
|
||||
* If you have access to yacc and rebuild ytab.c from lex.y, it is
|
||||
* essential that you compare the current ytab.c with the new version,
|
||||
* incorporating the necessary changes.
|
||||
*/
|
||||
|
||||
/*
|
||||
* lex -- grammar/lexical analyser
|
||||
*/
|
||||
|
||||
%{
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
char copr[] "Copyright (c) 1978 Charles H. Forsyth";
|
||||
struct des {
|
||||
struct nfa *d_start;
|
||||
struct nfa *d_final;
|
||||
};
|
||||
struct nlist {
|
||||
struct nlist *nl_next;
|
||||
struct nfa *nl_base;
|
||||
struct nfa *nl_end;
|
||||
struct nfa *nl_start;
|
||||
struct nfa *nl_final;
|
||||
char *nl_name;
|
||||
} *nlist;
|
||||
int strlen;
|
||||
extern struct nfa *elem();
|
||||
extern struct des *newdp();
|
||||
extern struct nlist *lookup();
|
||||
extern char *spccl();
|
||||
%}
|
||||
%term NAME CCLASS STRING CONCAT
|
||||
|
||||
%left ';'
|
||||
%left '='
|
||||
%left '/'
|
||||
%left '|'
|
||||
%left '(' NAME STRING CCLASS
|
||||
%left CONCAT
|
||||
%left '*'
|
||||
%%
|
||||
%{
|
||||
struct nfa *np, *nbase;
|
||||
char *cp;
|
||||
struct des *dp;
|
||||
struct trans *tp;
|
||||
struct nlist *nl;
|
||||
int i, c;
|
||||
%}
|
||||
lexfile:
|
||||
auxiliary_section translation_section
|
||||
|
|
||||
;
|
||||
|
||||
auxiliary_section:
|
||||
auxiliaries '%' '%'
|
||||
| '%' '%'
|
||||
;
|
||||
|
||||
auxiliaries:
|
||||
auxiliaries auxiliary
|
||||
| auxiliary
|
||||
;
|
||||
|
||||
auxiliary:
|
||||
namedef '=' regexp ';' ={
|
||||
dp = $3;
|
||||
nl = $1;
|
||||
np = nl->nl_base;
|
||||
nl->nl_start = dp->d_start;
|
||||
nl->nl_final = dp->d_final;
|
||||
nl->nl_end = nfap;
|
||||
printf("NFA for %s\n", nl->nl_name);
|
||||
nfaprint(dp->d_start, nl->nl_base);
|
||||
nbase = lalloc(i = nl->nl_end-nl->nl_base, sizeof(*nbase),
|
||||
"nfa storage");
|
||||
copynfa(nl, nbase, dp);
|
||||
nl->nl_start = dp->d_start;
|
||||
nl->nl_final = dp->d_final;
|
||||
nl->nl_end = nbase+i;
|
||||
nl->nl_base = nbase;
|
||||
nfap = np;
|
||||
ignore = spccl(nl->nl_name, "ignore", dp);
|
||||
breakc = spccl(nl->nl_name, "break", dp);
|
||||
illeg = spccl(nl->nl_name, "illegal", dp);
|
||||
}
|
||||
| '%' '{' ={ copycode(); }
|
||||
;
|
||||
|
||||
namedef:
|
||||
NAME ={
|
||||
$$ = lookup($1);
|
||||
$$->nl_base = nfap;
|
||||
if ($$->nl_start)
|
||||
error("%s redefined", $$->nl_name);
|
||||
}
|
||||
;
|
||||
|
||||
name:
|
||||
NAME ={ $$ = lookup($1); }
|
||||
;
|
||||
|
||||
regexp:
|
||||
CCLASS ={
|
||||
np = elem(CCL, $1);
|
||||
$$ = newdp(np, np->n_succ[0] = elem(FIN));
|
||||
}
|
||||
| STRING ={
|
||||
cp = $1;
|
||||
if (strlen == 0) {
|
||||
np = elem(EPSILON);
|
||||
$$ = newdp(np, np->n_succ[0] = elem(FIN));
|
||||
return;
|
||||
}
|
||||
$$ = np = elem(*cp++);
|
||||
while (--strlen > 0)
|
||||
np = np->n_succ[0] = elem(*cp++);
|
||||
$$ = newdp($$, np->n_succ[0] = elem(FIN));
|
||||
}
|
||||
| name ={
|
||||
if ((nl = $1)->nl_end == 0) {
|
||||
error("%s not defined", nl->nl_name);
|
||||
nl->nl_base = nl->nl_end = elem(FIN);
|
||||
nl->nl_start = nl->nl_final = nl->nl_base;
|
||||
}
|
||||
$$ = dp = lalloc(1, sizeof(*dp), "dfa input");
|
||||
nbase = nfap;
|
||||
i = nl->nl_end-nl->nl_base;
|
||||
if ((nfap += i) >= &nfa[MAXNFA]) {
|
||||
error("Out of NFA nodes");
|
||||
exit(1);
|
||||
}
|
||||
copynfa(nl, nbase, dp);
|
||||
}
|
||||
| regexp '*' ={
|
||||
$$ = dp = $1;
|
||||
dp->d_start = newnfa(EPSILON, np = dp->d_start, 0);
|
||||
dp->d_final->n_char = EPSILON;
|
||||
dp->d_final->n_succ[0] = np;
|
||||
dp->d_final->n_succ[1] = np = elem(FIN);
|
||||
dp->d_start->n_succ[1] = np;
|
||||
dp->d_final = np;
|
||||
}
|
||||
| regexp '|' regexp ={
|
||||
$$ = dp = $1;
|
||||
dp->d_start = newnfa(EPSILON, dp->d_start, $3->d_start);
|
||||
dp->d_final->n_char = EPSILON;
|
||||
dp->d_final = dp->d_final->n_succ[0] = np = elem(FIN);
|
||||
dp = $3;
|
||||
dp->d_final->n_char = EPSILON;
|
||||
dp->d_final->n_succ[0] = np;
|
||||
cfree($3);
|
||||
}
|
||||
| regexp regexp %prec CONCAT ={
|
||||
$$ = $1;
|
||||
dp = $2;
|
||||
np = $$->d_final;
|
||||
$$->d_final = dp->d_final;
|
||||
np->n_char = dp->d_start->n_char;
|
||||
np->n_ccl = dp->d_start->n_ccl;
|
||||
np->n_succ[0] = dp->d_start->n_succ[0];
|
||||
np->n_succ[1] = dp->d_start->n_succ[1];
|
||||
cfree($2);
|
||||
}
|
||||
| '(' regexp ')' ={ $$ = $2; }
|
||||
;
|
||||
|
||||
translation_section:
|
||||
translations ={
|
||||
ending();
|
||||
trans1:
|
||||
printf("\nNFA for complete syntax\n");
|
||||
printf("state 0\n");
|
||||
for (tp = trans; tp < transp; tp++)
|
||||
printf("\tepsilon\t%d\n", tp->t_start-nfa);
|
||||
for (tp = trans; tp < transp; tp++)
|
||||
nfaprint(tp->t_start, nfa);
|
||||
dfabuild();
|
||||
dfamin();
|
||||
dfaprint();
|
||||
dfawrite();
|
||||
stats();
|
||||
}
|
||||
| ={ goto trans1; }
|
||||
;
|
||||
|
||||
translations:
|
||||
translations translation
|
||||
| llactr translation
|
||||
;
|
||||
|
||||
llactr:
|
||||
={
|
||||
llactr();
|
||||
}
|
||||
;
|
||||
|
||||
translation:
|
||||
pattern action ={ dp = $1; newtrans(dp->d_start, dp->d_final); }
|
||||
| '%' '{' ={ copycode(); }
|
||||
| '%' '%' ={
|
||||
ending();
|
||||
while ((c = get()) != EOF)
|
||||
putc(c, llout);
|
||||
}
|
||||
;
|
||||
|
||||
action:
|
||||
'{' ={ action(); }
|
||||
;
|
||||
|
||||
pattern:
|
||||
regexp '/' regexp ={
|
||||
if (nlook >= NBPW)
|
||||
error("More than %d translations with lookahead",NBPW);
|
||||
$$ = dp = $1;
|
||||
np = dp->d_final;
|
||||
np->n_char = EPSILON;
|
||||
np->n_flag |= LOOK;
|
||||
np->n_succ[0] = $3->d_start;
|
||||
dp->d_final = $3->d_final;
|
||||
np->n_look = nlook;
|
||||
dp->d_final->n_look = nlook++;
|
||||
dp->d_final->n_flag |= FLOOK;
|
||||
cfree($3);
|
||||
}
|
||||
| regexp
|
||||
;
|
||||
|
||||
%%
|
||||
/*
|
||||
* Lexical analyser
|
||||
* (it isn't done with lex...)
|
||||
*/
|
||||
char buffer[150];
|
||||
|
||||
yylex()
|
||||
{
|
||||
register c;
|
||||
register char *cp;
|
||||
int lno;
|
||||
|
||||
if (yyline == 0)
|
||||
yyline++;
|
||||
loop:
|
||||
c = get();
|
||||
if (isupper(c)) {
|
||||
name(c);
|
||||
for (cp = yylval; c = *cp; cp++)
|
||||
if (isupper(c))
|
||||
*cp = tolower(c);
|
||||
return(STRING);
|
||||
} else if (islower(c) || c == '_') {
|
||||
name(c);
|
||||
return(NAME);
|
||||
}
|
||||
switch (c) {
|
||||
case EOF:
|
||||
return(0);
|
||||
|
||||
case '[':
|
||||
return(cclass());
|
||||
|
||||
case '(':
|
||||
case ')':
|
||||
case '{':
|
||||
case '}':
|
||||
case '*':
|
||||
case '|':
|
||||
case '=':
|
||||
case ';':
|
||||
case '%':
|
||||
return(c);
|
||||
|
||||
case '/':
|
||||
if ((c = get()) != '*') {
|
||||
unget(c);
|
||||
return('/');
|
||||
}
|
||||
lno = yyline;
|
||||
for (; c != EOF; c = get())
|
||||
if (c == '*')
|
||||
if ((c = get()) == '/')
|
||||
goto loop; else
|
||||
unget(c);
|
||||
yyline = lno;
|
||||
error("End of file in comment");
|
||||
|
||||
case '\'':
|
||||
case '"':
|
||||
yylval = buffer;
|
||||
string(c);
|
||||
return(STRING);
|
||||
|
||||
case '\n':
|
||||
case ' ':
|
||||
case '\t':
|
||||
goto loop;
|
||||
|
||||
default:
|
||||
yylval = buffer;
|
||||
if (c == '\\') {
|
||||
unget(c);
|
||||
c = mapch(EOF);
|
||||
}
|
||||
buffer[0] = c;
|
||||
buffer[1] = 0;
|
||||
strlen = 1;
|
||||
return(STRING);
|
||||
}
|
||||
}
|
||||
|
||||
char ccl[(NCHARS+1)/NBPC];
|
||||
|
||||
cclass()
|
||||
{
|
||||
register c, i, lc;
|
||||
int compl;
|
||||
|
||||
compl = 0;
|
||||
for (i = 0; i < sizeof ccl; i++)
|
||||
ccl[i] = 0;
|
||||
if ((c = get()) == '^')
|
||||
compl++; else
|
||||
unget(c);
|
||||
lc = -1;
|
||||
while ((c = mapc(']')) != EOF) {
|
||||
if (c == '-' && lc >= 0) {
|
||||
if ((c = mapc(']')) == EOF)
|
||||
break;
|
||||
for (i = lc; i <= c; i++)
|
||||
ccl[i/NBPC] |= 1<<(i%NBPC);
|
||||
lc = -1;
|
||||
continue;
|
||||
}
|
||||
ccl[c/NBPC] |= 1<<(c%NBPC);
|
||||
lc = c;
|
||||
}
|
||||
if (compl) {
|
||||
for (i = 0; i < sizeof ccl; i++)
|
||||
ccl[i] ^= -1;
|
||||
if (aflag == 0)
|
||||
for (i = 0200; i < (1<<NBPC); i++)
|
||||
ccl[i/NBPC] &= ~(1 << (i%NBPC));
|
||||
}
|
||||
yylval = newccl(ccl);
|
||||
return(CCLASS);
|
||||
}
|
||||
|
||||
string(ec)
|
||||
{
|
||||
register char *cp;
|
||||
register c;
|
||||
|
||||
for (cp = buffer; (c = mapc(ec)) != EOF;)
|
||||
*cp++ = c;
|
||||
*cp = 0;
|
||||
strlen = cp-buffer;
|
||||
}
|
||||
|
||||
mapc(ec)
|
||||
{
|
||||
register c, v, i;
|
||||
|
||||
if ((c = get()) == ec)
|
||||
return(EOF);
|
||||
switch(c) {
|
||||
case EOF:
|
||||
error("End of file in string");
|
||||
return(c);
|
||||
|
||||
case '\\':
|
||||
if ((c = get()) >= '0' && c <= '7') {
|
||||
i = 0;
|
||||
for (v = 0; c>='0' && c<='7' && i++<3; c = get())
|
||||
v = v*010 + c-'0';
|
||||
unget(c);
|
||||
return(v&0377);
|
||||
}
|
||||
switch (c) {
|
||||
case 'n':
|
||||
return('\n');
|
||||
|
||||
case 't':
|
||||
return('\t');
|
||||
|
||||
case 'b':
|
||||
return('\b');
|
||||
|
||||
case 'r':
|
||||
return('\r');
|
||||
|
||||
case '\n':
|
||||
yyline++;
|
||||
return(mapc(ec));
|
||||
}
|
||||
|
||||
default:
|
||||
return(c);
|
||||
}
|
||||
}
|
||||
|
||||
name(c)
|
||||
register c;
|
||||
{
|
||||
register char *cp;
|
||||
|
||||
for (yylval=cp=buffer; isalpha(c) || isdigit(c) || c=='_'; c=get())
|
||||
*cp++ = c;
|
||||
*cp = 0;
|
||||
strlen = cp-buffer;
|
||||
unget(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Miscellaneous functions
|
||||
* used only by lex.y
|
||||
*/
|
||||
struct nfa *
|
||||
elem(k, v)
|
||||
{
|
||||
struct nfa *fp;
|
||||
|
||||
fp = newnfa(k, 0, 0);
|
||||
if (k == CCL)
|
||||
fp->n_ccl = v;
|
||||
return(fp);
|
||||
}
|
||||
|
||||
struct des *
|
||||
newdp(st, fi)
|
||||
struct nfa *st, *fi;
|
||||
{
|
||||
register struct des *dp;
|
||||
|
||||
dp = lalloc(1, sizeof(*dp), "dfa input");
|
||||
dp->d_start = st;
|
||||
dp->d_final = fi;
|
||||
return(dp);
|
||||
}
|
||||
|
||||
action()
|
||||
{
|
||||
register c;
|
||||
int lno, lev;
|
||||
|
||||
newcase(transp-trans);
|
||||
lno = yyline;
|
||||
lev = 0;
|
||||
for (; (c = get()) != EOF && (c != '}' || lev); putc(c, llout))
|
||||
if (c == '{')
|
||||
lev++;
|
||||
else if (c == '}')
|
||||
lev--;
|
||||
else if (c == '\'' || c == '"') {
|
||||
putc(c, llout);
|
||||
skipstr(c);
|
||||
}
|
||||
fprintf(llout, "\n\tbreak;\n");
|
||||
if (c == EOF) {
|
||||
yyline = lno;
|
||||
error("End of file in action");
|
||||
}
|
||||
}
|
||||
|
||||
skipstr(ec)
|
||||
register ec;
|
||||
{
|
||||
register c;
|
||||
|
||||
while ((c = get()) != ec && c != EOF) {
|
||||
putc(c, llout);
|
||||
if (c == '\\' && (c = get()) != EOF)
|
||||
putc(c, llout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
copycode()
|
||||
{
|
||||
int lno;
|
||||
register c;
|
||||
|
||||
setline();
|
||||
lno = yyline;
|
||||
for (; (c = get()) != EOF; putc(c, llout))
|
||||
if (c == '%') {
|
||||
if ((c = get()) == '}')
|
||||
return;
|
||||
unget(c);
|
||||
c = '%';
|
||||
}
|
||||
yyline = lno;
|
||||
error("Incomplete %{ declaration");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct nlist *
|
||||
lookup(s)
|
||||
register char *s;
|
||||
{
|
||||
register struct nlist *nl;
|
||||
register char *cp;
|
||||
int i;
|
||||
|
||||
for (nl = nlist; nl; nl = nl->nl_next)
|
||||
if (streq(s, nl->nl_name))
|
||||
return(nl);
|
||||
nl = lalloc(1, sizeof(*nl), "namelist");
|
||||
nl->nl_start = nl->nl_end = nl->nl_base = nl->nl_end = 0;
|
||||
nl->nl_next = nlist;
|
||||
nlist = nl;
|
||||
i = 0;
|
||||
for (cp = s; *cp++;)
|
||||
i++;
|
||||
nl->nl_name = cp = lalloc(i+1, sizeof(*cp), "namelist");
|
||||
while (*cp++ = *s++)
|
||||
;
|
||||
return(nl);
|
||||
}
|
||||
|
||||
copynfa(nl, nbase, dp)
|
||||
struct nlist *nl;
|
||||
struct des *dp;
|
||||
struct nfa *nbase;
|
||||
{
|
||||
register struct nfa *np, *ob;
|
||||
register j;
|
||||
int i, ix;
|
||||
|
||||
ob = nl->nl_base;
|
||||
i = nl->nl_end-ob;
|
||||
copy(ob, sizeof(*np), i, nbase);
|
||||
for (np = nbase; i-- > 0; np++) {
|
||||
np->n_flag &= ~NPRT;
|
||||
for (j = 0; j < 2; j++)
|
||||
if (np->n_succ[j])
|
||||
np->n_succ[j] = (np->n_succ[j]-ob)+nbase;
|
||||
}
|
||||
dp->d_start = (nl->nl_start-ob)+nbase;
|
||||
dp->d_final = (nl->nl_final-ob)+nbase;
|
||||
}
|
||||
|
||||
char *
|
||||
spccl(nm, isit, dp)
|
||||
char *nm, *isit;
|
||||
register struct des *dp;
|
||||
{
|
||||
if (!streq(nm, isit))
|
||||
return(0);
|
||||
if (dp->d_start->n_char == CCL &&
|
||||
dp->d_start->n_succ[0] == dp->d_final)
|
||||
return(dp->d_start->n_ccl);
|
||||
error("Illegal %s class", isit);
|
||||
return(0);
|
||||
}
|
||||
|
||||
get()
|
||||
{
|
||||
register c;
|
||||
|
||||
if ((c = getc(stdin)) == '\n')
|
||||
yyline++;
|
||||
return(c);
|
||||
}
|
||||
|
||||
unget(c)
|
||||
register c;
|
||||
{
|
||||
if (c == '\n')
|
||||
yyline--;
|
||||
ungetc(c, stdin);
|
||||
}
|
||||
|
||||
error(s)
|
||||
char *s;
|
||||
{
|
||||
if (yyline)
|
||||
fprintf(stderr, "%d: ", yyline);
|
||||
fprintf(stderr, "%r", &s);
|
||||
if (yychar > 256)
|
||||
fprintf(stderr, " near `%s'", yysterm[yychar-256]);
|
||||
else if (yychar < 256 && yychar > 0)
|
||||
fprintf(stderr, " near `%c'", yychar);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
19
c20/lex/lexcha.c
Normal file
19
c20/lex/lexcha.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Bob Denny 28-Aug-82 Remove reference to stdio.h
|
||||
*/
|
||||
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
extern char *llp2;
|
||||
|
||||
lexchar()
|
||||
{
|
||||
return(llend<llp2? *llend++&0377: lexgetc());
|
||||
}
|
||||
28
c20/lex/lexech.c
Normal file
28
c20/lex/lexech.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* lexech.c
|
||||
*
|
||||
* Bob Denny 28-Aug-82
|
||||
* Move stdio dependencies to lexerr(), lexget(), lexech() and mapch()
|
||||
*
|
||||
* This is one of 4 modules in lexlib which depend
|
||||
* upon the standard I/O package.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
lexecho(fp)
|
||||
register FILE *fp;
|
||||
{
|
||||
register char *lp;
|
||||
|
||||
for (lp = llbuf; lp < llend;)
|
||||
putc(*lp++, fp);
|
||||
}
|
||||
20
c20/lex/lexerr.c
Normal file
20
c20/lex/lexerr.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* lexerr.c
|
||||
*
|
||||
* Bob Denny 28-Aug-82
|
||||
* Move stdio dependencies to lexerr(), lexget(), lexech() and mapch()
|
||||
*
|
||||
* This is one of 4 modules in lexlib which depend
|
||||
* upon the standard I/O package.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <lex.h>
|
||||
|
||||
lexerror(s)
|
||||
{
|
||||
if (yyline)
|
||||
fprintf(stderr, "%d: ", yyline);
|
||||
fprintf(stderr, "%s", s);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
31
c20/lex/lexerr.old
Normal file
31
c20/lex/lexerr.old
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* lexerr.c
|
||||
*
|
||||
* Bob Denny 28-Aug-82
|
||||
* Move stdio dependencies to lexerr(), lexget(), lexech() and mapch()
|
||||
*
|
||||
* This is one of 4 modules in lexlib which depend
|
||||
* upon the standard I/O package.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
lexerror(s)
|
||||
{
|
||||
if (yyline)
|
||||
fprintf(stderr, "%d: ", yyline);
|
||||
#ifdef vms
|
||||
fprintf(stderr, "%s", s);
|
||||
#else
|
||||
fprintf(stderr, "%r", &s);
|
||||
#endif
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
26
c20/lex/lexget.c
Normal file
26
c20/lex/lexget.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* lexget.c
|
||||
*
|
||||
* Bob Denny 28-Aug-82
|
||||
* Move stdio dependencies to lexerr(), lexget(), lexech() and mapch()
|
||||
*
|
||||
* This is one of 4 modules in lexlib which depend
|
||||
* upon the standard I/O package.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
FILE *lexin; /* File pointer moved to here */
|
||||
|
||||
lexgetc()
|
||||
{
|
||||
return(getc(lexin));
|
||||
}
|
||||
20
c20/lex/lexlen.c
Normal file
20
c20/lex/lexlen.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Bob Denny 28-Aug-82 Remove reference to stdio.h
|
||||
*/
|
||||
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
lexlength()
|
||||
/*
|
||||
* Return the length of the current token
|
||||
*/
|
||||
{
|
||||
return(llend - llbuf);
|
||||
}
|
||||
155
c20/lex/lexlex.h
Normal file
155
c20/lex/lexlex.h
Normal file
@@ -0,0 +1,155 @@
|
||||
|
||||
/*
|
||||
* lex -- header file for lex.c
|
||||
*/
|
||||
|
||||
#define DEBUG 1 /* Debuging */
|
||||
|
||||
#define NCHARS 0400 /* Size of character set */
|
||||
#define NCPW 2 /* # characters per word */
|
||||
#define NBPC 8 /* # bits per character */
|
||||
#define NBPW (NCPW*NBPC) /* # bits per word */
|
||||
|
||||
#define MAXNFA 600 /* Number of NFA states */
|
||||
#define MAXDFA 800 /* Number of DFA states */
|
||||
/*
|
||||
* Cut down maxnfa/maxdfa for Decus C
|
||||
*/
|
||||
#ifdef decus
|
||||
#ifdef rt11
|
||||
#define MAXNFA 300 /* Number of NFA states */
|
||||
#define MAXDFA 400 /* Number of DFA states */
|
||||
#else
|
||||
#define MAXNFA 200 /* Number of NFA states */
|
||||
#define MAXDFA 300 /* Number of DFA states */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define NTRANS 128 /* Number of translations */
|
||||
#define NCCLS 50 /* Number of character classes */
|
||||
#define NNEXT 15000 /* 2400 */ /* Size of dfa move vectors (later: allocate) */
|
||||
|
||||
/*
|
||||
* Special node characters.
|
||||
*/
|
||||
#define CCL NCHARS /* One of a character class */
|
||||
#define EPSILON NCHARS+1 /* Transition on epsilon */
|
||||
#define FIN NCHARS+2 /* Final state; NFA */
|
||||
|
||||
/*
|
||||
* Set of state numbers (dfa state name).
|
||||
*/
|
||||
struct set {
|
||||
struct set *s_next;
|
||||
struct dfa *s_state; /* pointer into dfa array */
|
||||
struct set *s_group; /* pointer to owning group (dfamin) */
|
||||
int s_final; /* nf state which matches */
|
||||
char s_flag; /* see below */
|
||||
int s_look; /* look-ahead bits */
|
||||
int s_len; /* number of elements in set */
|
||||
struct nfa *s_els[100];
|
||||
};
|
||||
|
||||
/*
|
||||
* State entry
|
||||
*/
|
||||
struct nfa {
|
||||
int n_char;
|
||||
char *n_ccl;
|
||||
char n_flag;
|
||||
char n_look; /* lookahead index */
|
||||
struct nfa *n_succ[2];
|
||||
struct trans *n_trans;
|
||||
};
|
||||
|
||||
/*
|
||||
* DFA transition entry.
|
||||
*/
|
||||
struct move {
|
||||
struct set *m_next;
|
||||
struct dfa *m_check;
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure of DFA vector.
|
||||
*/
|
||||
struct dfa {
|
||||
struct set *df_name;
|
||||
struct move *df_base;
|
||||
struct move *df_max;
|
||||
struct dfa *df_default;
|
||||
int df_ntrans;
|
||||
};
|
||||
|
||||
/*
|
||||
* s_flag values for DFA node
|
||||
*/
|
||||
#define LOOK 01 /* Lookahead mark */
|
||||
#define ADDED 02 /* DFA construction mark */
|
||||
#define FLOOK 04 /* Mark on final state of lookahead translation */
|
||||
|
||||
/*
|
||||
* Flag used to print node
|
||||
*/
|
||||
#define NPRT 010 /* NFA node printed */
|
||||
|
||||
/*
|
||||
* Transition set.
|
||||
*/
|
||||
struct xset {
|
||||
struct set *x_set;
|
||||
char x_char;
|
||||
char x_defsame;
|
||||
};
|
||||
|
||||
/*
|
||||
* Translations
|
||||
*/
|
||||
struct trans {
|
||||
struct nfa *t_start;
|
||||
struct nfa *t_final;
|
||||
};
|
||||
|
||||
/*
|
||||
* External definitions.
|
||||
*/
|
||||
extern struct trans trans[];
|
||||
extern struct trans *trnsp;
|
||||
extern struct nfa nfa[];
|
||||
extern struct nfa *nfap;
|
||||
extern struct dfa dfa[];
|
||||
extern int ndfa;
|
||||
extern struct move move[];
|
||||
extern struct xset sets[];
|
||||
extern char insets[];
|
||||
extern struct set *setlist;
|
||||
extern char ccls[][(NCHARS+1)/NBPC];
|
||||
extern int nccls;
|
||||
extern int nlook;
|
||||
extern int llnxtmax;
|
||||
extern char *tabname;
|
||||
extern FILE *llout;
|
||||
extern FILE *lexlog;
|
||||
extern FILE *lexin;
|
||||
extern int lldebug;
|
||||
extern int aflag;
|
||||
extern char *infile;
|
||||
|
||||
extern char *ignore;
|
||||
extern char *illeg;
|
||||
extern char *breakc;
|
||||
|
||||
extern struct nfa *newnfa();
|
||||
extern struct set *newset();
|
||||
extern struct set *eclosure();
|
||||
extern struct dfa *defalt();
|
||||
extern struct move *stbase();
|
||||
extern struct set *chase();
|
||||
extern char *newccl();
|
||||
extern char *lalloc();
|
||||
|
||||
/*
|
||||
* Yacc externals.
|
||||
*/
|
||||
extern int yyline;
|
||||
extern char *yysterm[];
|
||||
150
c20/lex/lexlex.old
Normal file
150
c20/lex/lexlex.old
Normal file
@@ -0,0 +1,150 @@
|
||||
|
||||
/*
|
||||
* lex -- header file for lex.c
|
||||
*/
|
||||
|
||||
#define NCHARS 0400 /* Size of character set */
|
||||
#define NCPW 2 /* # characters per word */
|
||||
#define NBPC 8 /* # bits per character */
|
||||
#define NBPW (NCPW*NBPC) /* # bits per word */
|
||||
|
||||
#define MAXNFA 600 /* Number of NFA states */
|
||||
#define MAXDFA 800 /* Number of DFA states */
|
||||
/*
|
||||
* Cut down maxnfa/maxdfa for Decus C
|
||||
*/
|
||||
#ifdef rt11
|
||||
#define MAXNFA 300 /* Number of NFA states */
|
||||
#define MAXDFA 400 /* Number of DFA states */
|
||||
#else
|
||||
#define MAXNFA 200 /* Number of NFA states */
|
||||
#define MAXDFA 300 /* Number of DFA states */
|
||||
#endif
|
||||
#define NTRANS 128 /* Number of translations */
|
||||
#define NCCLS 50 /* Number of character classes */
|
||||
#define NNEXT 2400 /* Size of dfa move vectors (later: allocate) */
|
||||
|
||||
/*
|
||||
* Special node characters.
|
||||
*/
|
||||
#define CCL NCHARS /* One of a character class */
|
||||
#define EPSILON NCHARS+1 /* Transition on epsilon */
|
||||
#define FIN NCHARS+2 /* Final state; NFA */
|
||||
|
||||
/*
|
||||
* Set of state numbers (dfa state name).
|
||||
*/
|
||||
struct set {
|
||||
struct set *s_next;
|
||||
struct dfa *s_state; /* pointer into dfa array */
|
||||
struct set *s_group; /* pointer to owning group (dfamin) */
|
||||
int s_final; /* nf state which matches */
|
||||
char s_flag; /* see below */
|
||||
int s_look; /* look-ahead bits */
|
||||
int s_len; /* number of elements in set */
|
||||
struct nfa *s_els[];
|
||||
};
|
||||
|
||||
/*
|
||||
* State entry
|
||||
*/
|
||||
struct nfa {
|
||||
int n_char;
|
||||
char *n_ccl;
|
||||
char n_flag;
|
||||
char n_look; /* lookahead index */
|
||||
struct nfa *n_succ[2];
|
||||
struct trans *n_trans;
|
||||
};
|
||||
|
||||
/*
|
||||
* DFA transition entry.
|
||||
*/
|
||||
struct move {
|
||||
struct set *m_next;
|
||||
struct dfa *m_check;
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure of DFA vector.
|
||||
*/
|
||||
struct dfa {
|
||||
struct set *df_name;
|
||||
struct move *df_base;
|
||||
struct move *df_max;
|
||||
struct dfa *df_default;
|
||||
int df_ntrans;
|
||||
};
|
||||
|
||||
/*
|
||||
* s_flag values for DFA node
|
||||
*/
|
||||
#define LOOK 01 /* Lookahead mark */
|
||||
#define ADDED 02 /* DFA construction mark */
|
||||
#define FLOOK 04 /* Mark on final state of lookahead translation */
|
||||
|
||||
/*
|
||||
* Flag used to print node
|
||||
*/
|
||||
#define NPRT 010 /* NFA node printed */
|
||||
|
||||
/*
|
||||
* Transition set.
|
||||
*/
|
||||
struct xset {
|
||||
struct set *x_set;
|
||||
char x_char;
|
||||
char x_defsame;
|
||||
};
|
||||
|
||||
/*
|
||||
* Translations
|
||||
*/
|
||||
struct trans {
|
||||
struct nfa *t_start;
|
||||
struct nfa *t_final;
|
||||
};
|
||||
|
||||
/*
|
||||
* External definitions.
|
||||
*/
|
||||
extern struct trans trans[];
|
||||
extern struct trans *transp;
|
||||
extern struct nfa nfa[];
|
||||
extern struct nfa *nfap;
|
||||
extern struct dfa dfa[];
|
||||
extern int ndfa;
|
||||
extern struct move move[];
|
||||
extern struct xset sets[];
|
||||
extern char insets[];
|
||||
extern struct set *setlist;
|
||||
extern char ccls[][(NCHARS+1)/NBPC];
|
||||
extern int nccls;
|
||||
extern int nlook;
|
||||
extern int llnxtmax;
|
||||
extern char *tabname;
|
||||
extern FILE *llout;
|
||||
extern FILE *lexlog;
|
||||
extern FILE *lexin;
|
||||
extern int lldebug;
|
||||
extern int aflag;
|
||||
extern char *infile;
|
||||
|
||||
extern char *ignore;
|
||||
extern char *illeg;
|
||||
extern char *breakc;
|
||||
|
||||
extern struct nfa *newnfa();
|
||||
extern struct set *newset();
|
||||
extern struct set *eclosure();
|
||||
extern struct dfa *defalt();
|
||||
extern struct move *stbase();
|
||||
extern struct set *chase();
|
||||
extern char *newccl();
|
||||
extern char *lalloc();
|
||||
|
||||
/*
|
||||
* Yacc externals.
|
||||
*/
|
||||
extern int yyline;
|
||||
extern char *yysterm[];
|
||||
23
c20/lex/lexlib.ctl
Normal file
23
c20/lex/lexlib.ctl
Normal file
@@ -0,0 +1,23 @@
|
||||
; BUILD DECUS LEX LIBRARY FOR TOPS-20
|
||||
@DEF C: MSC:<C>, PS:<C>
|
||||
@DEF SS: MSC:
|
||||
@DEF CLIB: MSC:<C.PCC20LIB>
|
||||
@DEF SYS: SYS:, C:
|
||||
|
||||
@pcc20 LEXSRT.C
|
||||
@pcc20 COMMEN.C
|
||||
@pcc20 GETTOK.C
|
||||
@pcc20 INTEG.C
|
||||
@pcc20 LEXCHA.C
|
||||
@pcc20 LEXECH.C
|
||||
@pcc20 LEXERR.C
|
||||
@pcc20 LEXGET.C
|
||||
@pcc20 LEXLEN.C
|
||||
@pcc20 LEXPEE.C
|
||||
@pcc20 LEXSWI.C
|
||||
@pcc20 LLSAVE.C
|
||||
@pcc20 LMOVB.C
|
||||
@pcc20 LMOVI.C
|
||||
@pcc20 TOKEN.C
|
||||
@pcc20 YYLEX.C
|
||||
@pcc20 MAPCH.C
|
||||
2
c20/lex/lexlib.mic
Normal file
2
c20/lex/lexlib.mic
Normal file
@@ -0,0 +1,2 @@
|
||||
@PIP
|
||||
*LEXLIB.REL=LEX:LEXSRT.REL,LEX:COMMEN.REL,LEX:GETTOK.REL,LEX:INTEG.REL,LEX:LEXCHA.REL,LEX:LEXECH.REL,LEX:LEXGET.REL,LEX:LEXLEN.REL,LEX:LEXPEE.REL,LEX:LEXSWI.REL,LEX:LMOVB.REL,LEX:LMOVI.REL,LEX:TOKEN.REL,LEX:YYLEX.REL,LEX:MAPCH.REL,LEX:LLSAVE.REL,LEX:LEXERR.REL
|
||||
16
c20/lex/lexlib.stinkr
Normal file
16
c20/lex/lexlib.stinkr
Normal file
@@ -0,0 +1,16 @@
|
||||
l lex:commen
|
||||
l lex:gettok
|
||||
l lex:integ
|
||||
l lex:lexcha
|
||||
l lex:lexech
|
||||
l lex:lexerr
|
||||
l lex:lexget
|
||||
l lex:lexlen
|
||||
l lex:lexpee
|
||||
l lex:lexswi
|
||||
l lex:lmovb
|
||||
l lex:lmovi
|
||||
l lex:token
|
||||
l lex:mapch
|
||||
l lex:yylex
|
||||
l lex:llsave
|
||||
17
c20/lex/lexpee.c
Normal file
17
c20/lex/lexpee.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
extern char *llp2;
|
||||
|
||||
lexpeekc()
|
||||
{
|
||||
return(llend<llp2? *llend&0377: EOF);
|
||||
}
|
||||
120
c20/lex/lexsrt.c
Normal file
120
c20/lex/lexsrt.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Note: probably should be replaced by qsort from the "useful" library
|
||||
*/
|
||||
|
||||
int (*qs__cmp)();
|
||||
static int size;
|
||||
|
||||
qsort(a, n, es, fc)
|
||||
char *a;
|
||||
int n, es;
|
||||
int (*fc)();
|
||||
{
|
||||
qs__cmp = fc;
|
||||
size = es;
|
||||
q_sort(a, a+n*es);
|
||||
}
|
||||
|
||||
q_sort(a, l)
|
||||
char *a, *l;
|
||||
{
|
||||
register char *i, *j;
|
||||
register int es;
|
||||
char *lp, *hp;
|
||||
int n, c;
|
||||
|
||||
|
||||
es = size;
|
||||
|
||||
start:
|
||||
if((n=l-a) <= es)
|
||||
return;
|
||||
n = es * ( n/(2*es));
|
||||
hp = lp = a+n;
|
||||
i = a;
|
||||
j = l-es;
|
||||
for(;;) {
|
||||
if(i < lp) {
|
||||
if((c = (*qs__cmp)(i, lp)) == 0) {
|
||||
q_exc(i, lp -= es);
|
||||
continue;
|
||||
}
|
||||
if(c < 0) {
|
||||
i += es;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
loop:
|
||||
if(j > hp) {
|
||||
if((c = (*qs__cmp)(hp, j)) == 0) {
|
||||
q_exc(hp += es, j);
|
||||
goto loop;
|
||||
}
|
||||
if(c > 0) {
|
||||
if(i == lp) {
|
||||
q_tex(i, hp += es, j);
|
||||
i = lp += es;
|
||||
goto loop;
|
||||
}
|
||||
q_exc(i, j);
|
||||
j -= es;
|
||||
i += es;
|
||||
continue;
|
||||
}
|
||||
j -= es;
|
||||
goto loop;
|
||||
}
|
||||
|
||||
|
||||
if(i == lp) {
|
||||
if(lp-a >= l-hp) {
|
||||
q_sort(hp+es, l);
|
||||
l = lp;
|
||||
} else {
|
||||
q_sort(a, lp);
|
||||
a = hp+es;
|
||||
}
|
||||
goto start;
|
||||
}
|
||||
|
||||
|
||||
q_tex(j, lp -= es, i);
|
||||
j = hp -= es;
|
||||
}
|
||||
}
|
||||
|
||||
q_exc(i, j)
|
||||
char *i, *j;
|
||||
{
|
||||
register char *ri, *rj, c;
|
||||
int n;
|
||||
|
||||
n = size;
|
||||
ri = i;
|
||||
rj = j;
|
||||
do {
|
||||
c = *ri;
|
||||
*ri++ = *rj;
|
||||
*rj++ = c;
|
||||
} while(--n);
|
||||
}
|
||||
|
||||
q_tex(i, j, k)
|
||||
char *i, *j, *k;
|
||||
{
|
||||
register char *ri, *rj, *rk;
|
||||
int c;
|
||||
int n;
|
||||
|
||||
n = size;
|
||||
ri = i;
|
||||
rj = j;
|
||||
rk = k;
|
||||
do {
|
||||
c = *ri;
|
||||
*ri++ = *rk;
|
||||
*rk++ = *rj;
|
||||
*rj++ = c;
|
||||
} while(--n);
|
||||
}
|
||||
28
c20/lex/lexswi.c
Normal file
28
c20/lex/lexswi.c
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
/*
|
||||
* lexswitch -- switch lex tables
|
||||
*/
|
||||
|
||||
/*
|
||||
* Bob Denny 28-Aug-82 Remove reference to stdio.h
|
||||
*/
|
||||
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
struct lextab *
|
||||
lexswitch(lp)
|
||||
struct lextab *lp;
|
||||
{
|
||||
register struct lextab *olp;
|
||||
|
||||
olp = _tabp;
|
||||
_tabp = lp;
|
||||
return(olp);
|
||||
}
|
||||
62
c20/lex/lextab.c
Normal file
62
c20/lex/lextab.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Created by DECUS LEX from file "tt1:" Tue Aug 31 21:01:15 1982
|
||||
*/
|
||||
|
||||
/*
|
||||
* CREATED FOR USE WITH STANDARD I/O
|
||||
*/
|
||||
|
||||
#
|
||||
#include <stdio.h>
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
extern int _lmovb();
|
||||
|
||||
int _Flextab[] =
|
||||
{
|
||||
-1, -1,
|
||||
};
|
||||
|
||||
#line 1 "tt1:"
|
||||
|
||||
#define LLTYPE1 char
|
||||
|
||||
LLTYPE1 _Nlextab[] =
|
||||
{
|
||||
1,
|
||||
};
|
||||
|
||||
LLTYPE1 _Clextab[] =
|
||||
{
|
||||
-1,
|
||||
};
|
||||
|
||||
LLTYPE1 _Dlextab[] =
|
||||
{
|
||||
1,
|
||||
};
|
||||
|
||||
int _Blextab[] =
|
||||
{
|
||||
0, 0,
|
||||
};
|
||||
|
||||
struct lextab lextab = {
|
||||
1, /* Highest state */
|
||||
_Dlextab, /* --> "Default state" table */
|
||||
_Nlextab, /* --> "Next state" table */
|
||||
_Clextab, /* --> "Check value" table */
|
||||
_Blextab, /* --> "Base" table */
|
||||
0, /* Index of last entry in "next" */
|
||||
_lmovb, /* --> Byte-int move routine */
|
||||
_Flextab, /* --> "Final state" table */
|
||||
_Alextab, /* --> Action routine */
|
||||
NULL, /* Look-ahead vector */
|
||||
0, /* No Ignore class */
|
||||
0, /* No Break class */
|
||||
0, /* No Illegal class */
|
||||
};
|
||||
9
c20/lex/llsave.c
Normal file
9
c20/lex/llsave.c
Normal file
@@ -0,0 +1,9 @@
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is linked from lexlib to resolve a global in yylex which
|
||||
* will be undefined if the user grammar has not defined any rules
|
||||
* with right-context (look-ahead)
|
||||
*/
|
||||
char *llsave[1]; /* Look ahead buffer */
|
||||
35
c20/lex/lmovb.c
Normal file
35
c20/lex/lmovb.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Bob Denny 28-Aug-82 Remove reference to stdio.h
|
||||
*/
|
||||
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
_lmovb(lp, c, st)
|
||||
register c, st;
|
||||
register struct lextab *lp;
|
||||
{
|
||||
int base;
|
||||
|
||||
while ((base = lp->llbase[st]+c) > lp->llnxtmax ||
|
||||
(lp->llcheck[base] & 0377) != st) {
|
||||
|
||||
if (st != lp->llendst) {
|
||||
/*
|
||||
* This miscompiled on Decus C many years ago:
|
||||
* st = lp->lldefault[st] & 0377;
|
||||
*/
|
||||
base = lp->lldefault[st] & 0377;
|
||||
st = base;
|
||||
}
|
||||
else
|
||||
return(-1);
|
||||
}
|
||||
return(lp->llnext[base]&0377);
|
||||
}
|
||||
34
c20/lex/lmovi.c
Normal file
34
c20/lex/lmovi.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Bob Denny 28-Aug-82 Remove reference to stdio.h
|
||||
*/
|
||||
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
_lmovi(lp, c, st)
|
||||
register int c;
|
||||
register int st;
|
||||
register struct lextab *lp;
|
||||
{
|
||||
int base;
|
||||
|
||||
while ((base = lp->llbase[st]+c) > lp->llnxtmax ||
|
||||
(int *)(lp->llcheck)[base]!=st)
|
||||
if (st != lp->llendst) {
|
||||
/*
|
||||
* This miscompiled on Decus C many years ago
|
||||
* st = ((int *)lp->lldefault)[st];
|
||||
*/
|
||||
base = ((int *)lp->lldefault)[st];
|
||||
st = base;
|
||||
}
|
||||
else
|
||||
return(-1);
|
||||
return(((int *)lp->llnext)[base]);
|
||||
}
|
||||
67
c20/lex/mapch.c
Normal file
67
c20/lex/mapch.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* mapch -- handle escapes within strings
|
||||
*/
|
||||
|
||||
/*
|
||||
* mapch.c
|
||||
*
|
||||
* Bob Denny 28-Aug-82
|
||||
* Move stdio dependencies to lexerr(), lexget(), lexech() and mapch()
|
||||
*
|
||||
* This is one of 4 modules in lexlib which depend
|
||||
* upon the standard I/O package.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
extern FILE *lexin;
|
||||
|
||||
mapch(delim, esc)
|
||||
{
|
||||
register c, octv, n;
|
||||
|
||||
if ((c = lexchar())==delim)
|
||||
return(EOF);
|
||||
if (c==EOF || c=='\n') {
|
||||
lexerror("Unterminated string");
|
||||
ungetc(c, lexin);
|
||||
return(EOF);
|
||||
}
|
||||
if (c!=esc)
|
||||
return(c);
|
||||
switch (c=lexchar()) {
|
||||
case 't':
|
||||
return('\t');
|
||||
case 'n':
|
||||
return('\n');
|
||||
case 'f':
|
||||
return('\f');
|
||||
case '\"': case '\'':
|
||||
return(c);
|
||||
case 'e':
|
||||
return('\e');
|
||||
case 'p':
|
||||
return(033);
|
||||
case 'r':
|
||||
return('\r');
|
||||
case '0': case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7':
|
||||
octv = c-'0';
|
||||
for (n = 1; (c = lexchar())>='0' && c<='7' && n<=3; n++)
|
||||
octv = octv*010 + (c-'0');
|
||||
ungetc(c, lexin);
|
||||
return(octv);
|
||||
case '\n':
|
||||
yyline++;
|
||||
return(mapch(delim, esc));
|
||||
}
|
||||
return(c);
|
||||
}
|
||||
180
c20/lex/min.c
Normal file
180
c20/lex/min.c
Normal file
@@ -0,0 +1,180 @@
|
||||
# define MIN 1 /* PLB */
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*
|
||||
* Modified 02-Dec-80 Bob Denny -- Conditionalize debug code for smaller size
|
||||
* Also note other mods. Now minimization is turned on at run time by '-m'.
|
||||
* More 19-Mar-82 Bob Denny -- New C library & compiler
|
||||
* This routine is unimplemented. Define MIN to turn it on. Have fun.
|
||||
*/
|
||||
|
||||
/*
|
||||
* lex -- dfa minimisation routines
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
#ifdef MIN
|
||||
#else
|
||||
/*
|
||||
* Dummy routine
|
||||
*/
|
||||
dfamin()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MIN
|
||||
extern int mflag;
|
||||
|
||||
member(e, v, i)
|
||||
register e, *v, i;
|
||||
{
|
||||
|
||||
while (i--)
|
||||
if (e==*v++)
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
extern struct set **oldpart;
|
||||
extern int **newpart;
|
||||
extern int nold, nnew;
|
||||
|
||||
struct xlist {
|
||||
struct set *x_set;
|
||||
struct trans *x_trans;
|
||||
};
|
||||
|
||||
xcomp(a, b)
|
||||
struct xlist *a, *b;
|
||||
{
|
||||
if (a->x_trans > b->x_trans)
|
||||
return(1);
|
||||
if (a->x_trans==b->x_trans)
|
||||
return(0);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
dfamin()
|
||||
{
|
||||
struct xlist *temp, *tp, *xp, *zp;
|
||||
struct trans *trp;
|
||||
int *tp2, *ip;
|
||||
struct set *gp, **xch;
|
||||
int i, j, k, niter;
|
||||
|
||||
if(mflag == 0) return; /*** NOTE ***/
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(lexlog, "\nDFA minimisation (%d states)\n", ndfa);
|
||||
#endif
|
||||
|
||||
temp = lalloc(ndfa, sizeof(*temp), "minimisation");
|
||||
oldpart = lalloc(ndfa, sizeof(*oldpart), "minimisation");
|
||||
newpart = lalloc(ndfa*2+1, sizeof(*newpart), "minimisation");
|
||||
setlist = 0;
|
||||
/*
|
||||
* partition first into final
|
||||
* states which identify different
|
||||
* translations, and non-final
|
||||
* states.
|
||||
*/
|
||||
tp = temp;
|
||||
for (i = 0; i < ndfa; i++, tp++) {
|
||||
tp->x_set = dfa[i].df_name;
|
||||
if (tp->x_set->s_final)
|
||||
tp->x_trans = nfa[tp->x_set->s_final].n_trans; else
|
||||
tp->x_trans = 0;
|
||||
}
|
||||
qsort(temp, tp-temp, sizeof(*tp), xcomp);
|
||||
for (xp = temp; xp < tp; xp = zp) {
|
||||
ip = newpart;
|
||||
for (zp = xp; zp < tp && zp->x_trans==xp->x_trans; zp++)
|
||||
*ip++ = zp->x_set->s_state-dfa;
|
||||
oldpart[nold++] = newset(newpart, ip-newpart, 0);
|
||||
}
|
||||
free(temp);
|
||||
/*
|
||||
* create a new partition,
|
||||
* by considering each group in
|
||||
* the old partition. For each
|
||||
* such group, create new subgroups
|
||||
* such that two states are in the
|
||||
* same subgroup iff they have
|
||||
* transitions on the same set of
|
||||
* characters into the same
|
||||
* set of groups in the old partition.
|
||||
* repeat this process until
|
||||
* a fixed point is reached.
|
||||
*/
|
||||
niter = 0;
|
||||
do {
|
||||
niter++;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(lexlog, "\n%d groups in partition %d\n", nold, niter);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < nold; i++) {
|
||||
fprintf(lexlog, "group %d: ", i);
|
||||
pset(oldpart[i], 0);
|
||||
fprintf(lexlog, "\n");
|
||||
}
|
||||
nnew = 0;
|
||||
tp2 = newpart;
|
||||
for (i = 0; i < nold; i++) {
|
||||
gp = oldpart[i];
|
||||
for (j = 0; j < gp->s_len; j++) {
|
||||
if (member(gp->s_els[j], newpart, tp2-newpart))
|
||||
continue;
|
||||
*tp2++ = gp->s_els[j];
|
||||
for (k = 0; k < gp->s_len; k++)
|
||||
if (k!=j &&
|
||||
!member(gp->s_els[k], newpart,
|
||||
tp2-newpart) &&
|
||||
eqstate(gp->s_els[j],gp->s_els[k]))
|
||||
*tp2++ = gp->s_els[k];
|
||||
*tp2++ = -1;
|
||||
}
|
||||
}
|
||||
*tp2++ = -1;
|
||||
for (tp2 = newpart; *tp2 != -1; tp2 = ++ip) {
|
||||
for (ip = tp2; *ip != -1; ip++)
|
||||
;
|
||||
oldpart[nnew++] = newset(tp2, ip-tp2, 0);
|
||||
}
|
||||
i = nold; nold = nnew; nnew = i;
|
||||
} while (nnew!=nold);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (ndfa==nnew)
|
||||
fprintf(lexlog, "\nno states saved by minimisation\n"); else
|
||||
fprintf(lexlog, "\n%d states saved by minimisation\n", ndfa-nnew);
|
||||
#endif
|
||||
|
||||
free(newpart);
|
||||
free(oldpart);
|
||||
}
|
||||
|
||||
eqstate(a, b)
|
||||
{
|
||||
register struct move *dp1, *dp2;
|
||||
|
||||
/** dfa vector has no element 'df_moves', transition entries have no elements
|
||||
df_char nor df_set. Obviously unimplemented stuff.
|
||||
|
||||
dp1 = dfa[a].df_moves;
|
||||
dp2 = dfa[b].df_moves;
|
||||
for (; dp1->df_set; dp1++, dp2++)
|
||||
if (dp2->df_set==0)
|
||||
return(0);
|
||||
else if (dp1->df_char != dp2->df_char ||
|
||||
dp1->df_set->s_group != dp2->df_set->s_group)
|
||||
return(0);
|
||||
return(dp2->df_set==0);
|
||||
**/
|
||||
|
||||
}
|
||||
#endif
|
||||
208
c20/lex/obase.c
Normal file
208
c20/lex/obase.c
Normal file
@@ -0,0 +1,208 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*/
|
||||
|
||||
/*
|
||||
* lex -- find and set base values for `move' vector
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
/*
|
||||
* Choose the best default
|
||||
* state for `st'.
|
||||
* Only states previous to the
|
||||
* current state are considered,
|
||||
* as these are guaranteed to
|
||||
* exist.
|
||||
*/
|
||||
struct dfa *
|
||||
defalt(st, xsep)
|
||||
struct dfa *st;
|
||||
struct xset **xsep;
|
||||
{
|
||||
register struct dfa *dp;
|
||||
register unsigned minv, u;
|
||||
struct dfa *def;
|
||||
struct xset *xse;
|
||||
int i;
|
||||
|
||||
xse = *xsep;
|
||||
if ((i = xse-sets)==0)
|
||||
return(NULL);
|
||||
if (lldebug>1)
|
||||
fprintf(stderr, "State %d, default:\n", st-dfa);
|
||||
minv = -1;
|
||||
def = NULL;
|
||||
for (dp = dfa; dp < st; dp++)
|
||||
if ((u = compat(st, dp, xse)) < minv) {
|
||||
if (lldebug>1)
|
||||
fprintf(stderr, "\t%d rates %d\n", dp-dfa, u);
|
||||
def = dp;
|
||||
minv = u;
|
||||
}
|
||||
if (minv == -1 || 10*(i-minv) < i)
|
||||
def = NULL;
|
||||
if (lldebug>1 && def)
|
||||
fprintf(stderr, "\t%d chosen\n", def-dfa);
|
||||
if (def)
|
||||
resolve(st, def, xsep);
|
||||
return(def);
|
||||
}
|
||||
|
||||
/*
|
||||
* State `b' is compatible with,
|
||||
* and hence a suitable default state
|
||||
* for state `a',
|
||||
* if its transitions agree with
|
||||
* those of `a', except those for
|
||||
* which `a' has transitions to the
|
||||
* (alleged) default.
|
||||
* Circularity of the default
|
||||
* relation is also not allowed.
|
||||
* If the state `b' has at least
|
||||
* twice as many transitions as `a',
|
||||
* it is not even worth considering.
|
||||
*/
|
||||
compat(a, b, xse)
|
||||
struct dfa *a, *b;
|
||||
struct xset *xse;
|
||||
{
|
||||
register struct dfa *dp;
|
||||
register i, c;
|
||||
|
||||
if (a==b || b->df_ntrans >= a->df_ntrans*2)
|
||||
return(-1);
|
||||
for (dp = b; dp; dp = dp->df_default)
|
||||
if (dp == a)
|
||||
return(-1);
|
||||
i = resolve(a, b, &xse);
|
||||
return(i);
|
||||
}
|
||||
|
||||
/*
|
||||
* set `sets' to indicate those
|
||||
* characters on which the state `a'
|
||||
* and its default agree and
|
||||
* those characters on which `a'
|
||||
* should go to `error' (as the default
|
||||
* accepts it, but `a' does not).
|
||||
*/
|
||||
resolve(a, def, xsep)
|
||||
struct dfa *a, *def;
|
||||
struct xset **xsep;
|
||||
{
|
||||
register struct move *dp;
|
||||
register c, i;
|
||||
struct xset *xs, *xse;
|
||||
|
||||
xse = *xsep;
|
||||
i = xse-sets;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
xs->x_defsame = 0;
|
||||
for (; def; def = def->df_default)
|
||||
for (dp = def->df_base; dp < def->df_max; dp++)
|
||||
if (dp->m_check == def) {
|
||||
c = dp - def->df_base;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
if (c==(xs->x_char&0377)) {
|
||||
if (xs->x_set==dp->m_next) {
|
||||
xs->x_defsame++;
|
||||
i--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (xs >= xse) {
|
||||
xs->x_defsame = 0;
|
||||
xs->x_char = c;
|
||||
xs->x_set = NULL;
|
||||
i++;
|
||||
xse++;
|
||||
}
|
||||
}
|
||||
*xsep = xse;
|
||||
return(i);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose a base in `move'
|
||||
* for the current state.
|
||||
* The transitions of that
|
||||
* state are in the vector
|
||||
* `sets'.
|
||||
*/
|
||||
struct move *
|
||||
stbase(xse)
|
||||
struct xset *xse;
|
||||
{
|
||||
register a;
|
||||
register struct move *base;
|
||||
register conflicts;
|
||||
struct xset *xs;
|
||||
|
||||
if (xse==sets)
|
||||
return(NULL);
|
||||
base = move;
|
||||
do {
|
||||
if (base-move >= NNEXT) {
|
||||
error("No space in `move' (stbase)");
|
||||
if (lldebug>1)
|
||||
dfaprint();
|
||||
exit(1);
|
||||
}
|
||||
conflicts = 0;
|
||||
for (xs = sets; xs < xse; xs++) {
|
||||
a = xs->x_char&0377;
|
||||
if (xs->x_defsame==0 &&
|
||||
(base+a>=move+NNEXT || base[a].m_check!=NULL)) {
|
||||
conflicts++;
|
||||
base++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (conflicts);
|
||||
return(base);
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a state,
|
||||
* its `base' value in `move',
|
||||
* and the set of transitions in
|
||||
* `sets' (ending near `xse'),
|
||||
* set the `move' values.
|
||||
*/
|
||||
setbase(st, base, xse)
|
||||
struct dfa *st;
|
||||
register struct move *base;
|
||||
struct xset *xse;
|
||||
{
|
||||
register struct move *dp;
|
||||
register struct xset *xs;
|
||||
struct move *maxdp;
|
||||
|
||||
st->df_base = base;
|
||||
st->df_max = base;
|
||||
if (lldebug>1)
|
||||
fprintf(stderr, "Setbase: state %d\n", st-dfa);
|
||||
if (lldebug>1 && base==0)
|
||||
fprintf(stderr, "\tno base\n");
|
||||
if (base==NULL)
|
||||
return;
|
||||
maxdp = base;
|
||||
for (xs = sets; xs < xse; xs++)
|
||||
if (xs->x_defsame==0) {
|
||||
dp = base + (xs->x_char&0377);
|
||||
if (dp > maxdp)
|
||||
maxdp = dp;
|
||||
dp->m_next = xs->x_set;
|
||||
dp->m_check = st;
|
||||
if (dp-move > llnxtmax)
|
||||
llnxtmax = dp-move;
|
||||
if (lldebug>1)
|
||||
fprintf(stderr, "\t%c nets %d\n",
|
||||
xs->x_char&0377, dp-move);
|
||||
}
|
||||
st->df_max = maxdp+1;
|
||||
}
|
||||
215
c20/lex/ocap.c
Normal file
215
c20/lex/ocap.c
Normal file
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Created by DECUS LEX from file "cap.lxi" Sun Aug 29 01:19:05 1982
|
||||
*/
|
||||
|
||||
/*
|
||||
* CREATED FOR USE WITH STANDARD I/O
|
||||
*/
|
||||
|
||||
#
|
||||
#include <stdio.h>
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
extern int _lmovb();
|
||||
|
||||
#line 10 "cap.lxi"
|
||||
|
||||
extern char *token();
|
||||
|
||||
main()
|
||||
{
|
||||
while (yylex())
|
||||
;
|
||||
}
|
||||
|
||||
/* Standard I/O selected */
|
||||
extern FILE *lexin;
|
||||
|
||||
llstin()
|
||||
{
|
||||
if(lexin == NULL)
|
||||
lexin = stdin;
|
||||
}
|
||||
|
||||
_Acap(__na__) /* Action routine */
|
||||
{
|
||||
|
||||
#line 20 "cap.lxi"
|
||||
|
||||
register char *cp;
|
||||
char *et;
|
||||
switch (__na__)
|
||||
{
|
||||
|
||||
case 0:
|
||||
|
||||
#line 25 "cap.lxi"
|
||||
|
||||
cp = token(&et);
|
||||
while (cp < et)
|
||||
putchar(*cp++);
|
||||
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
#line 30 "cap.lxi"
|
||||
putchar(token(0)[1]);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
#line 31 "cap.lxi"
|
||||
putchar(*token(0)+'a'-'A');
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
#line 32 "cap.lxi"
|
||||
putchar(*token(0));
|
||||
break;
|
||||
}
|
||||
return(LEXSKIP);
|
||||
}
|
||||
|
||||
#line 33 "cap.lxi"
|
||||
|
||||
|
||||
int _Fcap[] =
|
||||
{
|
||||
-1, 3, 2, 3, 1, 3, -1, 0,
|
||||
-1, -1, -1, -1, 3, -1, -1, -1,
|
||||
-1,
|
||||
};
|
||||
|
||||
#line 34 "cap.lxi"
|
||||
|
||||
#define LLTYPE1 char
|
||||
|
||||
LLTYPE1 _Ncap[] =
|
||||
{
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 5, 1, 1, 3, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 12, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 5,
|
||||
1, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1,
|
||||
4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 6, 8, 13, 6, 6, 14,
|
||||
8, 8, 15, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16,
|
||||
9, 16, 11, 10, 10, 16, 16, 11,
|
||||
16, 11, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7,
|
||||
};
|
||||
|
||||
LLTYPE1 _Ccap[] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 5, 6, 12, 9, 10, 13,
|
||||
6, 6, 14, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
5, -1, 5, 9, 10, -1, -1, 5,
|
||||
-1, 5, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6,
|
||||
};
|
||||
|
||||
LLTYPE1 _Dcap[] =
|
||||
{
|
||||
16, 16, 16, 16, 16, 16, 16, 16,
|
||||
6, 16, 6, 5, 5, 16, 16, 6,
|
||||
|
||||
};
|
||||
|
||||
int _Bcap[] =
|
||||
{
|
||||
0, 0, 0, 191, 0, 272, 249, 0,
|
||||
0, 275, 276, 0, 204, 207, 280, 0,
|
||||
0,
|
||||
};
|
||||
|
||||
struct lextab cap = {
|
||||
16, /* Highest state */
|
||||
_Dcap, /* --> "Default state" table */
|
||||
_Ncap, /* --> "Next state" table */
|
||||
_Ccap, /* --> "Check value" table */
|
||||
_Bcap, /* --> "Base" table */
|
||||
339, /* Index of last entry in "next" */
|
||||
_lmovb, /* --> Byte-int move routine */
|
||||
_Fcap, /* --> "Final state" table */
|
||||
_Acap, /* --> Action routine */
|
||||
NULL, /* Look-ahead vector */
|
||||
0, /* No Ignore class */
|
||||
0, /* No Break class */
|
||||
0, /* No Illegal class */
|
||||
};
|
||||
33
c20/lex/ocap.lxi
Normal file
33
c20/lex/ocap.lxi
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* capitalise things
|
||||
*/
|
||||
|
||||
letter = [A-Z];
|
||||
open = ["'(];
|
||||
close = ["')];
|
||||
any = [\0-\377];
|
||||
eos = [.?!];
|
||||
%{
|
||||
extern char *token();
|
||||
|
||||
main()
|
||||
{
|
||||
while (yylex())
|
||||
;
|
||||
}
|
||||
%}
|
||||
%%
|
||||
%{
|
||||
register char *cp;
|
||||
char *et;
|
||||
%}
|
||||
|
||||
(".PP\n"|eos close* " "* (" "|"\n"))open*letter {
|
||||
cp = token(&et);
|
||||
while (cp < et)
|
||||
putchar(*cp++);
|
||||
}
|
||||
$letter {putchar(token(0)[1]);}
|
||||
letter {putchar(*token(0)+'a'-'A');}
|
||||
any {putchar(*token(0));}
|
||||
%%
|
||||
400
c20/lex/out.c
Normal file
400
c20/lex/out.c
Normal file
@@ -0,0 +1,400 @@
|
||||
|
||||
#
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*/
|
||||
|
||||
/*
|
||||
* lex -- output human- and machine-readable tables
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
extern int sflag;
|
||||
|
||||
char strdec[] = {"\n\
|
||||
struct\tlextab\t%s = {\n\
|
||||
\t%d,\t/* last state */\n\
|
||||
\t_D%s,\t/* defaults */\n\
|
||||
\t_N%s,\t/* next */\n\
|
||||
\t_C%s,\t/* check */\n\
|
||||
\t_B%s,\t/* base */\n\
|
||||
\t%d,\t/* last in base */\n\
|
||||
\t%s,\t/* byte-int move routines */\n\
|
||||
\t_F%s,\t/* final state descriptions */\n\
|
||||
\t_A%s,\t/* action routine */\n\
|
||||
\t%s%s,\t/* look-ahead vector */\n\
|
||||
"};
|
||||
|
||||
nfaprint(np, base)
|
||||
register struct nfa *np;
|
||||
struct nfa *base;
|
||||
{
|
||||
register i;
|
||||
|
||||
if (np->n_flag&NPRT)
|
||||
return;
|
||||
np->n_flag |= NPRT;
|
||||
fprintf(lexlog, "state %d\n", np-base);
|
||||
switch (np->n_char) {
|
||||
case EPSILON:
|
||||
for (i = 0; i < 2; i++)
|
||||
if (np->n_succ[i])
|
||||
fprintf(lexlog,
|
||||
"\tepsilon %d\n", np->n_succ[i]-base);
|
||||
break;
|
||||
case FIN:
|
||||
fprintf(lexlog, "\tfinal state\n");
|
||||
break;
|
||||
case CCL:
|
||||
fprintf(lexlog, "\t[");
|
||||
cclprint(np->n_ccl);
|
||||
fprintf(lexlog, "] %d\n", np->n_succ[0]-base);
|
||||
break;
|
||||
default:
|
||||
putc('\t', lexlog);
|
||||
chprint(np->n_char);
|
||||
fprintf(lexlog, " %d\n", np->n_succ[0]-base);
|
||||
break;
|
||||
}
|
||||
fprintf(lexlog, "\n");
|
||||
if (np->n_succ[0])
|
||||
nfaprint(np->n_succ[0], base);
|
||||
if (np->n_succ[1])
|
||||
nfaprint(np->n_succ[1], base);
|
||||
}
|
||||
|
||||
cclprint(cp)
|
||||
register char *cp;
|
||||
{
|
||||
register i;
|
||||
|
||||
for (i = 0; i < NCHARS; i++)
|
||||
if (cp[i/NBPC]&(1<<(i%NBPC)))
|
||||
chprint(i);
|
||||
}
|
||||
|
||||
chprint(ch)
|
||||
{
|
||||
register char *s;
|
||||
|
||||
ch &= 0377;
|
||||
switch (ch) {
|
||||
case '\t':
|
||||
s = "\\t";
|
||||
break;
|
||||
case '\n':
|
||||
s = "\\n";
|
||||
break;
|
||||
case '\b':
|
||||
s = "\\b";
|
||||
break;
|
||||
case '\r':
|
||||
s = "\\r";
|
||||
break;
|
||||
default:
|
||||
fprintf(lexlog, (ch<040 || ch>=0177) ? "\\%o": "%c", ch);
|
||||
return;
|
||||
}
|
||||
fprintf(lexlog, s);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* print the minimised DFA,
|
||||
* and at the same time,
|
||||
* construct the vector which
|
||||
* indicates final states by
|
||||
* associating them with
|
||||
* their translation index.
|
||||
*/
|
||||
dfaprint()
|
||||
{
|
||||
register struct move *dp;
|
||||
register struct dfa *st;
|
||||
register i;
|
||||
int fi, k, l;
|
||||
|
||||
vstart("int _", "F", tabname);
|
||||
fprintf(lexlog, "\nMinimised DFA for complete syntax\n");
|
||||
for (i = 0; i < ndfa; i++) {
|
||||
fprintf(lexlog, "\nstate %d", i);
|
||||
st = &dfa[i];
|
||||
k = -1;
|
||||
if (fi = st->df_name->s_final) {
|
||||
k = nfa[fi].n_trans - trans;
|
||||
fprintf(lexlog, " (final %d[%d],)", fi, k);
|
||||
if (nfa[fi].n_flag&FLOOK) {
|
||||
k |= (nfa[fi].n_look+1)<<11;
|
||||
fprintf(lexlog, " restore %d", nfa[fi].n_look);
|
||||
}
|
||||
}
|
||||
if (l = st->df_name->s_look)
|
||||
fprintf(lexlog, " look-ahead %o", l);
|
||||
veld(k);
|
||||
/*
|
||||
k = st->df_name->s_group->s_els[0];
|
||||
if (k!=i) {
|
||||
fprintf(lexlog, " deleted\n");
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
fprintf(lexlog, "\n");
|
||||
for (dp = st->df_base; dp < st->df_max; dp = range(st, dp))
|
||||
;
|
||||
if (st->df_default)
|
||||
fprintf(lexlog, "\t.\tsame as %d\n",
|
||||
st->df_default-dfa);
|
||||
}
|
||||
veld(-1); /* blocking state */
|
||||
vend();
|
||||
}
|
||||
|
||||
range(st, dp)
|
||||
register struct dfa *st;
|
||||
register struct move *dp;
|
||||
{
|
||||
int low, high, last;
|
||||
struct set *s;
|
||||
register a;
|
||||
|
||||
while (dp < st->df_max && dp->m_check!=st)
|
||||
dp++;
|
||||
if (dp >= st->df_max)
|
||||
return(dp);
|
||||
low = dp - st->df_base;
|
||||
/*
|
||||
s = dp->m_next->s_group->s_els[0];
|
||||
*/
|
||||
s = dp->m_next;
|
||||
for (last = low-1; dp < st->df_max &&
|
||||
dp->m_check==st &&
|
||||
(a = dp - st->df_base)==last+1 &&
|
||||
/*
|
||||
dp->m_next->s_state->s_els[0]==s; dp++)
|
||||
*/
|
||||
dp->m_next==s; dp++)
|
||||
last = a;
|
||||
high = last;
|
||||
fprintf(lexlog, "\t");
|
||||
if (high==low)
|
||||
chprint(low);
|
||||
else {
|
||||
fprintf(lexlog, "[");
|
||||
if (high-low > 4) {
|
||||
chprint(low);
|
||||
fprintf(lexlog, "-");
|
||||
chprint(high);
|
||||
} else {
|
||||
while (low<=high)
|
||||
chprint(low++);
|
||||
}
|
||||
fprintf(lexlog, "]");
|
||||
}
|
||||
if (s == NULL || s->s_state == NULL)
|
||||
fprintf(lexlog, "\tNULL\n");
|
||||
else
|
||||
fprintf(lexlog, "\t%d\n", s->s_state-dfa);
|
||||
return(dp);
|
||||
}
|
||||
|
||||
heading()
|
||||
{
|
||||
fprintf(llout, "\
|
||||
\#include <stdio.h>\n\
|
||||
\#ifdef vms\n\
|
||||
\#include \"c:lex.h\"\n\
|
||||
\#else\n\
|
||||
\#include <lex.h>\n\
|
||||
\#endif\n");
|
||||
fprintf(llout, "extern int _lmov%c();\n",
|
||||
(ndfa <= 255) ? 'b' : 'i');
|
||||
}
|
||||
|
||||
llactr()
|
||||
{
|
||||
/*
|
||||
* Prior to generating the action routine, create
|
||||
* the llstin() routine, which initializes yylex(),
|
||||
* per the setting of the "-s" switch. All hardwired
|
||||
* variables have now been removed from yylex(). This
|
||||
* allows analyzers to be independent of the standard
|
||||
* I/O library and the table name.
|
||||
*/
|
||||
fprintf(llout, "extern struct lextab %s;\n", tabname);
|
||||
if(sflag == 0) /* If stdio flavor */
|
||||
{
|
||||
fprintf(llout, "\n/* Standard I/O selected */\n");
|
||||
fprintf(llout, "extern FILE *lexin;\n\n");
|
||||
fprintf(llout, "llstin()\n {\n if(lexin == NULL)\n");
|
||||
fprintf(llout, " lexin = stdin;\n");
|
||||
}
|
||||
else /* Stand-alone flavor */
|
||||
{
|
||||
fprintf(llout, "\n/* Stand-alone selected */\n");
|
||||
fprintf(llout, "\llstin()\n {\n");
|
||||
}
|
||||
fprintf(llout, " if(_tabp == NULL)\n");
|
||||
fprintf(llout, " lexswitch(&%s);\n }\n\n", tabname);
|
||||
fprintf(llout, "_A%s(__na__)\t\t/* Action routine */\n {\n", tabname);
|
||||
}
|
||||
|
||||
/*
|
||||
llactr()
|
||||
{
|
||||
fprintf(llout, "_A%s(__na__) {\n", tabname);
|
||||
}
|
||||
*/
|
||||
|
||||
newcase(i)
|
||||
{
|
||||
static int putsw;
|
||||
|
||||
if (!putsw++)
|
||||
fprintf(llout, "\tswitch (__na__) {\n");
|
||||
fprintf(llout, "\tcase %d:\n", i);
|
||||
setlne();
|
||||
}
|
||||
|
||||
ending()
|
||||
{
|
||||
static int ended;
|
||||
|
||||
if (ended++)
|
||||
return;
|
||||
fprintf(llout, "\t}\n\treturn(LEXSKIP);\n}\n");
|
||||
setlne();
|
||||
}
|
||||
|
||||
dfawrite()
|
||||
{
|
||||
register struct move *dp;
|
||||
register i, a;
|
||||
int k, base, nr, c;
|
||||
struct dfa *st, *def;
|
||||
struct set *xp;
|
||||
|
||||
setlne();
|
||||
fprintf(llout, "\n#define\tLLTYPE1\t%s\n", ndfa<=255? "char": "int");
|
||||
vstart("LLTYPE1 _", "N", tabname);
|
||||
for (i = 0; i <= llnxtmax; i++)
|
||||
if (xp = move[i].m_next)
|
||||
veld(xp->s_state-dfa); else
|
||||
veld(ndfa);
|
||||
vend();
|
||||
vstart("LLTYPE1 _", "C", tabname);
|
||||
for (i = 0; i <= llnxtmax; i++)
|
||||
if (st = move[i].m_check)
|
||||
veld(st-dfa); else
|
||||
veld(-1);
|
||||
vend();
|
||||
vstart("LLTYPE1 _", "D", tabname);
|
||||
for (i = 0; i < ndfa; i++)
|
||||
if (def = dfa[i].df_default)
|
||||
veld(def-dfa); else
|
||||
veld(ndfa); /* refer to blocking state */
|
||||
vend();
|
||||
vstart("int _", "B", tabname);
|
||||
for (i = 0; i < ndfa; i++)
|
||||
if (dp = dfa[i].df_base)
|
||||
veld(dp-move); else
|
||||
veld(0);
|
||||
veld(0); /* for blocking state */
|
||||
vend();
|
||||
if (nlook) {
|
||||
fprintf(llout, "char *llsave[%d];\n", nlook);
|
||||
vstart("int _", "L", tabname);
|
||||
a = nlook<=NBPC? NCHARS-1: -1;
|
||||
for (i = 0; i < ndfa; i++)
|
||||
velo(dfa[i].df_name->s_look&a);
|
||||
velo(0);
|
||||
vend();
|
||||
}
|
||||
dospccl(ignore, "LLIGN", "X");
|
||||
dospccl(breakc, "LLBRK", "Y");
|
||||
dospccl(illeg, "LLILL", "Z");
|
||||
|
||||
fprintf(llout, strdec,
|
||||
tabname, ndfa, tabname, tabname, tabname, tabname,
|
||||
llnxtmax, ndfa<=255? "_lmovb": "_lmovi", tabname, tabname,
|
||||
nlook? "_L": "", nlook? tabname: "NULL");
|
||||
refccl(ignore, "ignore", "X");
|
||||
refccl(breakc, "break", "Y");
|
||||
refccl(illeg, "illegal", "Z");
|
||||
fprintf(llout, "};\n");
|
||||
fclose(llout);
|
||||
}
|
||||
|
||||
dospccl(cp, s, tag)
|
||||
register char *cp;
|
||||
char *s, *tag;
|
||||
{
|
||||
register n;
|
||||
|
||||
if (cp==0)
|
||||
return;
|
||||
fprintf(llout, "#define\t%s\t%s\n", s, s);
|
||||
vstart("char _", tag, tabname);
|
||||
for (n = sizeof(ccls[0]); n--;)
|
||||
velo(*cp++&0377);
|
||||
vend();
|
||||
}
|
||||
|
||||
refccl(cp, nm, tag)
|
||||
char *cp, *nm, *tag;
|
||||
{
|
||||
if (cp==0)
|
||||
fprintf(llout, "\t0,\t/* no %s class */\n", nm); else
|
||||
fprintf(llout, "\t_%s%s,\t/* %s class */\n", tag,
|
||||
tabname, nm);
|
||||
}
|
||||
|
||||
int vnl;
|
||||
|
||||
static
|
||||
vstart(def, tag, name)
|
||||
char *def, *tag, *name;
|
||||
{
|
||||
vnl = 0;
|
||||
fprintf(llout, "\n%s%s%s[] = {\n", def, tag, name);
|
||||
}
|
||||
|
||||
vend()
|
||||
{
|
||||
fprintf(llout, "\n};\n");
|
||||
}
|
||||
|
||||
veld(e)
|
||||
int e;
|
||||
/*
|
||||
* Print decimal value e
|
||||
*/
|
||||
{
|
||||
fprintf(llout, " %d,", e);
|
||||
veol();
|
||||
}
|
||||
|
||||
velo(e)
|
||||
int e;
|
||||
/*
|
||||
* Print octal value e
|
||||
*/
|
||||
{
|
||||
fprintf(llout, " 0%o,", e);
|
||||
veol();
|
||||
}
|
||||
|
||||
veol()
|
||||
/*
|
||||
* End of line
|
||||
*/
|
||||
{
|
||||
if ((++vnl & 017) == 0)
|
||||
fprintf(llout, "\n");
|
||||
}
|
||||
|
||||
setlne()
|
||||
{
|
||||
fprintf(llout, "\n#line %d \"%s\"\n", yyline, infile);
|
||||
}
|
||||
368
c20/lex/out.old
Normal file
368
c20/lex/out.old
Normal file
@@ -0,0 +1,368 @@
|
||||
|
||||
#
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*/
|
||||
|
||||
/*
|
||||
* lex -- output human- and machine-readable tables
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
char strdec[] = {"\n\
|
||||
struct\tlextab\t%s = {\n\
|
||||
\t%d,\t/* last state */\n\
|
||||
\t_D%s,\t/* defaults */\n\
|
||||
\t_N%s,\t/* next */\n\
|
||||
\t_C%s,\t/* check */\n\
|
||||
\t_B%s,\t/* base */\n\
|
||||
\t%d,\t/* last in base */\n\
|
||||
\t%s,\t/* byte-int move routines */\n\
|
||||
\t_F%s,\t/* final state descriptions */\n\
|
||||
\t_A%s,\t/* action routine */\n\
|
||||
\t%s%s,\t/* look-ahead vector */\n\
|
||||
"};
|
||||
|
||||
nfaprint(np, base)
|
||||
register struct nfa *np;
|
||||
struct nfa *base;
|
||||
{
|
||||
register i;
|
||||
|
||||
if (np->n_flag&NPRT)
|
||||
return;
|
||||
np->n_flag |= NPRT;
|
||||
fprintf(lexlog, "state %d\n", np-base);
|
||||
switch (np->n_char) {
|
||||
case EPSILON:
|
||||
for (i = 0; i < 2; i++)
|
||||
if (np->n_succ[i])
|
||||
fprintf(lexlog,
|
||||
"\tepsilon %d\n", np->n_succ[i]-base);
|
||||
break;
|
||||
case FIN:
|
||||
fprintf(lexlog, "\tfinal state\n");
|
||||
break;
|
||||
case CCL:
|
||||
fprintf(lexlog, "\t[");
|
||||
cclprint(np->n_ccl);
|
||||
fprintf(lexlog, "] %d\n", np->n_succ[0]-base);
|
||||
break;
|
||||
default:
|
||||
putc('\t', lexlog);
|
||||
chprint(np->n_char);
|
||||
fprintf(lexlog, " %d\n", np->n_succ[0]-base);
|
||||
break;
|
||||
}
|
||||
fprintf(lexlog, "\n");
|
||||
if (np->n_succ[0])
|
||||
nfaprint(np->n_succ[0], base);
|
||||
if (np->n_succ[1])
|
||||
nfaprint(np->n_succ[1], base);
|
||||
}
|
||||
|
||||
cclprint(cp)
|
||||
register char *cp;
|
||||
{
|
||||
register i;
|
||||
|
||||
for (i = 0; i < NCHARS; i++)
|
||||
if (cp[i/NBPC]&(1<<(i%NBPC)))
|
||||
chprint(i);
|
||||
}
|
||||
|
||||
chprint(ch)
|
||||
{
|
||||
register char *s;
|
||||
|
||||
ch &= 0377;
|
||||
switch (ch) {
|
||||
case '\t':
|
||||
s = "\\t";
|
||||
break;
|
||||
case '\n':
|
||||
s = "\\n";
|
||||
break;
|
||||
case '\b':
|
||||
s = "\\b";
|
||||
break;
|
||||
case '\r':
|
||||
s = "\\r";
|
||||
break;
|
||||
default:
|
||||
fprintf(lexlog, (ch<040 || ch>=0177) ? "\\%o": "%c", ch);
|
||||
return;
|
||||
}
|
||||
fprintf(lexlog, s);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* print the minimised DFA,
|
||||
* and at the same time,
|
||||
* construct the vector which
|
||||
* indicates final states by
|
||||
* associating them with
|
||||
* their translation index.
|
||||
*/
|
||||
dfaprint()
|
||||
{
|
||||
register struct move *dp;
|
||||
register struct dfa *st;
|
||||
register i;
|
||||
int fi, k, l;
|
||||
|
||||
vstart("int _", "F", tabname);
|
||||
fprintf(lexlog, "\nMinimised DFA for complete syntax\n");
|
||||
for (i = 0; i < ndfa; i++) {
|
||||
fprintf(lexlog, "\nstate %d", i);
|
||||
st = &dfa[i];
|
||||
k = -1;
|
||||
if (fi = st->df_name->s_final) {
|
||||
k = nfa[fi].n_trans - trans;
|
||||
fprintf(lexlog, " (final %d[%d],)", fi, k);
|
||||
if (nfa[fi].n_flag&FLOOK) {
|
||||
k |= (nfa[fi].n_look+1)<<11;
|
||||
fprintf(lexlog, " restore %d", nfa[fi].n_look);
|
||||
}
|
||||
}
|
||||
if (l = st->df_name->s_look)
|
||||
fprintf(lexlog, " look-ahead %o", l);
|
||||
veld(k);
|
||||
/*
|
||||
k = st->df_name->s_group->s_els[0];
|
||||
if (k!=i) {
|
||||
fprintf(lexlog, " deleted\n");
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
fprintf(lexlog, "\n");
|
||||
for (dp = st->df_base; dp < st->df_max; dp = range(st, dp))
|
||||
;
|
||||
if (st->df_default)
|
||||
fprintf(lexlog, "\t.\tsame as %d\n",
|
||||
st->df_default-dfa);
|
||||
}
|
||||
veld(-1); /* blocking state */
|
||||
vend();
|
||||
}
|
||||
|
||||
range(st, dp)
|
||||
register struct dfa *st;
|
||||
register struct move *dp;
|
||||
{
|
||||
int low, high, last;
|
||||
struct set *s;
|
||||
register a;
|
||||
|
||||
while (dp < st->df_max && dp->m_check!=st)
|
||||
dp++;
|
||||
if (dp >= st->df_max)
|
||||
return(dp);
|
||||
low = dp - st->df_base;
|
||||
/*
|
||||
s = dp->m_next->s_group->s_els[0];
|
||||
*/
|
||||
s = dp->m_next;
|
||||
for (last = low-1; dp < st->df_max &&
|
||||
dp->m_check==st &&
|
||||
(a = dp - st->df_base)==last+1 &&
|
||||
/*
|
||||
dp->m_next->s_state->s_els[0]==s; dp++)
|
||||
*/
|
||||
dp->m_next==s; dp++)
|
||||
last = a;
|
||||
high = last;
|
||||
fprintf(lexlog, "\t");
|
||||
if (high==low)
|
||||
chprint(low);
|
||||
else {
|
||||
fprintf(lexlog, "[");
|
||||
if (high-low > 4) {
|
||||
chprint(low);
|
||||
fprintf(lexlog, "-");
|
||||
chprint(high);
|
||||
} else {
|
||||
while (low<=high)
|
||||
chprint(low++);
|
||||
}
|
||||
fprintf(lexlog, "]");
|
||||
}
|
||||
if (s == NULL || s->s_state == NULL)
|
||||
fprintf(lexlog, "\tNULL\n");
|
||||
else
|
||||
fprintf(lexlog, "\t%d\n", s->s_state-dfa);
|
||||
return(dp);
|
||||
}
|
||||
|
||||
heading()
|
||||
{
|
||||
fprintf(llout, "\
|
||||
\#include <stdio.h>\n\
|
||||
\#ifdef vms\n\
|
||||
\#include \"c:lex.h\"\n\
|
||||
\#else\n\
|
||||
\#include <lex.h>\n\
|
||||
\#endif\n");
|
||||
fprintf(llout, "extern int _lmov%c();\n",
|
||||
(ndfa <= 255) ? 'b' : 'i');
|
||||
}
|
||||
|
||||
llactr()
|
||||
{
|
||||
fprintf(llout, "_A%s(__na__) {\n", tabname);
|
||||
}
|
||||
|
||||
newcase(i)
|
||||
{
|
||||
static int putsw;
|
||||
|
||||
if (!putsw++)
|
||||
fprintf(llout, "\tswitch (__na__) {\n");
|
||||
fprintf(llout, "\tcase %d:\n", i);
|
||||
setline();
|
||||
}
|
||||
|
||||
ending()
|
||||
{
|
||||
static int ended;
|
||||
|
||||
if (ended++)
|
||||
return;
|
||||
fprintf(llout, "\t}\n\treturn(LEXSKIP);\n}\n");
|
||||
setline();
|
||||
}
|
||||
|
||||
dfawrite()
|
||||
{
|
||||
register struct move *dp;
|
||||
register i, a;
|
||||
int k, base, nr, c;
|
||||
struct dfa *st, *def;
|
||||
struct set *xp;
|
||||
|
||||
setline();
|
||||
fprintf(llout, "\n#define\tLLTYPE1\t%s\n", ndfa<=255? "char": "int");
|
||||
vstart("LLTYPE1 _", "N", tabname);
|
||||
for (i = 0; i <= llnxtmax; i++)
|
||||
if (xp = move[i].m_next)
|
||||
veld(xp->s_state-dfa); else
|
||||
veld(ndfa);
|
||||
vend();
|
||||
vstart("LLTYPE1 _", "C", tabname);
|
||||
for (i = 0; i <= llnxtmax; i++)
|
||||
if (st = move[i].m_check)
|
||||
veld(st-dfa); else
|
||||
veld(-1);
|
||||
vend();
|
||||
vstart("LLTYPE1 _", "D", tabname);
|
||||
for (i = 0; i < ndfa; i++)
|
||||
if (def = dfa[i].df_default)
|
||||
veld(def-dfa); else
|
||||
veld(ndfa); /* refer to blocking state */
|
||||
vend();
|
||||
vstart("int _", "B", tabname);
|
||||
for (i = 0; i < ndfa; i++)
|
||||
if (dp = dfa[i].df_base)
|
||||
veld(dp-move); else
|
||||
veld(0);
|
||||
veld(0); /* for blocking state */
|
||||
vend();
|
||||
if (nlook) {
|
||||
fprintf(llout, "char *llsave[%d];\n", nlook);
|
||||
vstart("int _", "L", tabname);
|
||||
a = nlook<=NBPC? NCHARS-1: -1;
|
||||
for (i = 0; i < ndfa; i++)
|
||||
velo(dfa[i].df_name->s_look&a);
|
||||
velo(0);
|
||||
vend();
|
||||
}
|
||||
dospccl(ignore, "LLIGN", "X");
|
||||
dospccl(breakc, "LLBRK", "Y");
|
||||
dospccl(illeg, "LLILL", "Z");
|
||||
|
||||
fprintf(llout, strdec,
|
||||
tabname, ndfa, tabname, tabname, tabname, tabname,
|
||||
llnxtmax, ndfa<=255? "_lmovb": "_lmovi", tabname, tabname,
|
||||
nlook? "_L": "", nlook? tabname: "NULL");
|
||||
refccl(ignore, "ignore", "X");
|
||||
refccl(breakc, "break", "Y");
|
||||
refccl(illeg, "illegal", "Z");
|
||||
fprintf(llout, "};\n");
|
||||
fclose(llout);
|
||||
}
|
||||
|
||||
dospccl(cp, s, tag)
|
||||
register char *cp;
|
||||
char *s, *tag;
|
||||
{
|
||||
register n;
|
||||
|
||||
if (cp==0)
|
||||
return;
|
||||
fprintf(llout, "#define\t%s\t%s\n", s, s);
|
||||
vstart("char _", tag, tabname);
|
||||
for (n = sizeof(ccls[0]); n--;)
|
||||
velo(*cp++&0377);
|
||||
vend();
|
||||
}
|
||||
|
||||
refccl(cp, nm, tag)
|
||||
char *cp, *nm, *tag;
|
||||
{
|
||||
if (cp==0)
|
||||
fprintf(llout, "\t0,\t/* no %s class */\n", nm); else
|
||||
fprintf(llout, "\t_%s%s,\t/* %s class */\n", tag,
|
||||
tabname, nm);
|
||||
}
|
||||
|
||||
int vnl;
|
||||
|
||||
static
|
||||
vstart(def, tag, name)
|
||||
char *def, *tag, *name;
|
||||
{
|
||||
vnl = 0;
|
||||
fprintf(llout, "\n%s%s%s[] = {\n", def, tag, name);
|
||||
}
|
||||
|
||||
vend()
|
||||
{
|
||||
fprintf(llout, "\n};\n");
|
||||
}
|
||||
|
||||
veld(e)
|
||||
int e;
|
||||
/*
|
||||
* Print decimal value e
|
||||
*/
|
||||
{
|
||||
fprintf(llout, " %d,", e);
|
||||
veol();
|
||||
}
|
||||
|
||||
velo(e)
|
||||
int e;
|
||||
/*
|
||||
* Print octal value e
|
||||
*/
|
||||
{
|
||||
fprintf(llout, " 0%o,", e);
|
||||
veol();
|
||||
}
|
||||
|
||||
veol()
|
||||
/*
|
||||
* End of line
|
||||
*/
|
||||
{
|
||||
if ((++vnl & 017) == 0)
|
||||
fprintf(llout, "\n");
|
||||
}
|
||||
|
||||
setline()
|
||||
{
|
||||
fprintf(llout, "\n#line %d \"%s\"\n", yyline, infile);
|
||||
}
|
||||
306
c20/lex/out1.c
Normal file
306
c20/lex/out1.c
Normal file
@@ -0,0 +1,306 @@
|
||||
/*
|
||||
* Copyright (c) 1978 Charles H. Forsyth
|
||||
*
|
||||
* Modified 02-Dec-80 Bob Denny -- Conditionalize debug code for smaller size
|
||||
* 01 -- Removed ending() function code from here
|
||||
* to lex.c, so ytab.c code could share the
|
||||
* same overlay region as this module.
|
||||
* 02 -- Removed nfaprint(), llactr(), newcase(),
|
||||
* cclprint(), chprint() and setline(),
|
||||
* the rest of this can share an overlay.
|
||||
* They're in 'out2.c'. This is now 'out1.c'.
|
||||
* 29-May-81 Bob Denny -- More extern hacking for RSX overlaying.
|
||||
* 19-Mar-82 Bob Denny -- New compiler and library
|
||||
* 03-May-82 Bob Denny -- Final touches, remove unreferenced autos
|
||||
* 28-Aug-82 Bob Denny -- Put "=" into table initializers to make
|
||||
* new compiler happy. Add "-s" code to
|
||||
* supress "#include <stdio.h>" in output.
|
||||
* Tables output 8 values/line instead of
|
||||
* 16. Overran R.H. edge on 3 digit octals.
|
||||
* Change output format for readability.
|
||||
* 31-Aug-82 Bob Denny -- Add lexswitch( ...) to llstin so table
|
||||
* name selected by -t switch is automatically
|
||||
* switched-to at yylex() startup time. Removed
|
||||
* hard reference to "lextab" from yylex();
|
||||
* This module generates extern declaration
|
||||
* for forward reference.
|
||||
*/
|
||||
|
||||
/*
|
||||
* lex -- output human- and machine-readable tables
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
extern char *ignore;
|
||||
extern char *illeg;
|
||||
extern char *breakc;
|
||||
|
||||
char strdec[] = {"\n\
|
||||
struct lextab %s =\t{\n\
|
||||
\t\t\t%d,\t\t/* Highest state */\n\
|
||||
\t\t\t_D%s\t/* --> \"Default state\" table */\n\
|
||||
\t\t\t_N%s\t/* --> \"Next state\" table */\n\
|
||||
\t\t\t_C%s\t/* --> \"Check value\" table */\n\
|
||||
\t\t\t_B%s\t/* --> \"Base\" table */\n\
|
||||
\t\t\t%d,\t\t/* Index of last entry in \"next\" */\n\
|
||||
\t\t\t%s,\t\t/* --> Byte-int move routine */\n\
|
||||
\t\t\t_F%s\t/* --> \"Final state\" table */\n\
|
||||
\t\t\t_A%s\t/* --> Action routine */\n\
|
||||
\t\t\t%s%s\t/* Look-ahead vector */\n\
|
||||
"};
|
||||
|
||||
char ptabnam[] = { " " };
|
||||
|
||||
/*
|
||||
* Print the minimised DFA,
|
||||
* and at the same time,
|
||||
* construct the vector which
|
||||
* indicates final states by
|
||||
* associating them with
|
||||
* their translation index.
|
||||
* (DFA printout supressed ifndef DEBUG. RBD)
|
||||
*/
|
||||
dfaprint()
|
||||
{
|
||||
register struct move *dp;
|
||||
register struct dfa *st;
|
||||
register i;
|
||||
int fi, k, l;
|
||||
|
||||
vstart("int _F%s", tabname);
|
||||
#ifdef DEBUG
|
||||
fprintf(lexlog, "\nMinimised DFA for complete syntax\n");
|
||||
#endif
|
||||
for (i = 0; i < ndfa; i++) {
|
||||
#ifdef DEBUG
|
||||
fprintf(lexlog, "\nstate %d", i);
|
||||
#endif
|
||||
st = &dfa[i];
|
||||
k = -1;
|
||||
if (fi = st->df_name->s_final) {
|
||||
k = nfa[fi].n_trans - trans;
|
||||
#ifdef DEBUG
|
||||
fprintf(lexlog, " (final %d[%d])", fi, k);
|
||||
#endif
|
||||
if (nfa[fi].n_flag&FLOOK) {
|
||||
k |= (nfa[fi].n_look+1)<<11;
|
||||
#ifdef DEBUG
|
||||
fprintf(lexlog, " restore %d", nfa[fi].n_look);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (l = st->df_name->s_look)
|
||||
#ifdef DEBUG
|
||||
fprintf(lexlog, " look-ahead %o", l);
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
vel(" %d,", k);
|
||||
#ifdef DEBUG
|
||||
k = st->df_name->s_group->s_els[0];
|
||||
if (k!=i) {
|
||||
fprintf(lexlog, " deleted\n");
|
||||
continue;
|
||||
}
|
||||
fprintf(lexlog, "\n");
|
||||
for (dp = st->df_base; dp < st->df_max; dp = range(st, dp))
|
||||
if (st->df_default)
|
||||
fprintf(lexlog, "\t.\tsame as %d\n", st->df_default-dfa);
|
||||
#endif
|
||||
}
|
||||
vel(" -1,"); /* blocking state */
|
||||
vend();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
range(st, dp)
|
||||
register struct dfa *st;
|
||||
register struct move *dp;
|
||||
{
|
||||
int low, high, last;
|
||||
struct set *s;
|
||||
register a;
|
||||
|
||||
while (dp < st->df_max && dp->m_check!=st)
|
||||
dp++;
|
||||
/***************************************************
|
||||
* This always returns given the above statement ! *
|
||||
***************************************************/
|
||||
if (dp >= st->df_max)
|
||||
return(dp);
|
||||
|
||||
low = dp - st->df_base;
|
||||
/*
|
||||
s = dp->m_next->s_group->s_els[0];
|
||||
*/
|
||||
s = dp->m_next;
|
||||
for (last = low-1; dp < st->df_max &&
|
||||
dp->m_check==st &&
|
||||
(a = dp - st->df_base)==last+1 &&
|
||||
/*
|
||||
dp->m_next->s_state->s_els[0]==s; dp++)
|
||||
*/
|
||||
dp->m_next==s; dp++)
|
||||
last = a;
|
||||
high = last;
|
||||
fprintf(lexlog, "\t");
|
||||
if (high==low)
|
||||
chprint(low);
|
||||
else {
|
||||
fprintf(lexlog, "[");
|
||||
if (high-low > 4) {
|
||||
chprint(low);
|
||||
fprintf(lexlog, "-");
|
||||
chprint(high);
|
||||
} else {
|
||||
while (low<=high)
|
||||
chprint(low++);
|
||||
}
|
||||
fprintf(lexlog, "]");
|
||||
}
|
||||
if (s->s_state==NULL)
|
||||
fprintf(lexlog, "\tNULL\n"); else
|
||||
fprintf(lexlog, "\t%d\n", s->s_state-dfa);
|
||||
return(dp);
|
||||
}
|
||||
#endif
|
||||
|
||||
heading()
|
||||
{
|
||||
fprintf(llout,
|
||||
"/*\n * Created by DECUS LEX from file \"%s\" %s\n */\n\n",
|
||||
infile, ctime(0));
|
||||
if(sflag == 0) /* If "standalone" switch off */
|
||||
{
|
||||
fprintf(llout,
|
||||
"/*\n * CREATED FOR USE WITH STANDARD I/O\n */\n\n");
|
||||
fprintf(llout, "#\n#include <stdio.h>\n");
|
||||
}
|
||||
else
|
||||
fprintf(llout, "/*\n * CREATED FOR STAND-ALONE I/O\n */\n\n");
|
||||
|
||||
fprintf(llout, "#ifdef vms\n");
|
||||
fprintf(llout, "#include \"c:lex.h\"\n#else\n");
|
||||
fprintf(llout, "#include <lex.h>\n#endif\n\n");
|
||||
fprintf(llout, "extern int _lmov%c();\n",
|
||||
(ndfa <= 255) ? 'b' : 'i');
|
||||
fprintf(llout, "extern struct lextab %s;\t/* Forward reference */\n\n",
|
||||
tabname);
|
||||
}
|
||||
|
||||
/* 02 */
|
||||
/* 01 */
|
||||
dfawrite()
|
||||
{
|
||||
register struct move *dp;
|
||||
register i, a;
|
||||
struct dfa *st, *def;
|
||||
struct set *xp;
|
||||
char *xcp;
|
||||
|
||||
setline();
|
||||
fprintf(llout, "\n#define\tLLTYPE1\t%s\n", ndfa<=255? "char": "int");
|
||||
vstart("LLTYPE1 _N%s", tabname);
|
||||
for (i = 0; i <= llnxtmax; i++)
|
||||
if (xp = move[i].m_next)
|
||||
vel(" %d,", xp->s_state-dfa); else
|
||||
vel(" %d,", ndfa);
|
||||
vend();
|
||||
vstart("LLTYPE1 _C%s", tabname);
|
||||
for (i = 0; i <= llnxtmax; i++)
|
||||
if (st = move[i].m_check)
|
||||
vel(" %d,", st-dfa); else
|
||||
vel(" -1,");
|
||||
vend();
|
||||
vstart("LLTYPE1 _D%s", tabname);
|
||||
for (i = 0; i < ndfa; i++)
|
||||
if (def = dfa[i].df_default)
|
||||
vel(" %d,", def-dfa); else
|
||||
vel(" %d,", ndfa); /* refer to blocking state */
|
||||
vend();
|
||||
vstart("int _B%s", tabname);
|
||||
for (i = 0; i < ndfa; i++)
|
||||
if (dp = dfa[i].df_base)
|
||||
vel(" %d,", dp-move); else
|
||||
vel(" 0,");
|
||||
vel(" 0,"); /* for blocking state */
|
||||
vend();
|
||||
if (nlook) {
|
||||
fprintf(llout, "char *llsave[%d];\n", nlook);
|
||||
vstart("int _L%s", tabname);
|
||||
a = nlook<=NBPC? NCHARS-1: -1;
|
||||
for (i = 0; i < ndfa; i++)
|
||||
vel(" 0%o,", dfa[i].df_name->s_look&a);
|
||||
vel(" 0,");
|
||||
vend();
|
||||
}
|
||||
dospccl(ignore, "LLIGN", "X");
|
||||
dospccl(breakc, "LLBRK", "Y");
|
||||
dospccl(illeg, "LLILL", "Z");
|
||||
|
||||
i = (7 - strlen(tabname)); /* Yes, 7 */
|
||||
xcp = cpystr(ptabnam, tabname);
|
||||
*xcp++ = ',';
|
||||
while(i--)
|
||||
*xcp++ = ' ';
|
||||
*xcp = '\0';
|
||||
fprintf(llout, strdec,
|
||||
tabname, ndfa, ptabnam, ptabnam, ptabnam, ptabnam,
|
||||
llnxtmax, ndfa<=255? "_lmovb": "_lmovi", ptabnam, ptabnam,
|
||||
nlook? "_L": "", nlook? ptabnam: "NULL, ");
|
||||
refccl(ignore, "Ignore", "X");
|
||||
refccl(breakc, "Break", "Y");
|
||||
refccl(illeg, "Illegal", "Z");
|
||||
fprintf(llout, "\t\t\t};\n");
|
||||
fclose(llout);
|
||||
}
|
||||
|
||||
dospccl(cp, s, tag)
|
||||
register char *cp;
|
||||
char *s, *tag;
|
||||
{
|
||||
register n;
|
||||
|
||||
if (cp==0)
|
||||
return;
|
||||
fprintf(llout, "#define\t%s\t%s\n", s, s);
|
||||
vstart("char _%s%s", tag, tabname);
|
||||
for (n = sizeof(ccls[0]); n--;)
|
||||
vel(" 0%o,", *cp++&0377);
|
||||
vend();
|
||||
}
|
||||
|
||||
refccl(cp, nm, tag)
|
||||
char *cp, *nm, *tag;
|
||||
{
|
||||
if (cp==0)
|
||||
fprintf(llout, "\t\t\t0,\t\t/* No %s class */\n", nm);
|
||||
else
|
||||
fprintf(llout, "\t_%s%s,\t/* %s class */\n", tag, tabname, nm);
|
||||
}
|
||||
|
||||
int vnl;
|
||||
|
||||
vstart(t)
|
||||
{
|
||||
vnl = 0;
|
||||
fprintf(llout, "\n%r", &t);
|
||||
fprintf(llout, "[] =\n {\n ");
|
||||
}
|
||||
|
||||
vend()
|
||||
{
|
||||
fprintf(llout, "\n };\n");
|
||||
}
|
||||
|
||||
vel(s)
|
||||
char *s;
|
||||
{
|
||||
fprintf(llout, "%r", &s);
|
||||
if ((++vnl&07)==0)
|
||||
fprintf(llout, "\n ");
|
||||
}
|
||||
/* 02 */
|
||||
140
c20/lex/out2.c
Normal file
140
c20/lex/out2.c
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* out2.c -- Some of Lex's output routines for overlaying, moved
|
||||
* here from the original out.c as part of size reduction
|
||||
* effort.
|
||||
* Bob Denny
|
||||
* 03-Dec-80
|
||||
* More...
|
||||
* Bob Denny
|
||||
* 29-May-81 RSX overlaying
|
||||
* 19-Mar-82 Bob Denny -- New compiler and library
|
||||
* 28-Aug-82 Bob Denny -- Change output format for readability. I know
|
||||
* you UNIX hackers are not going to like this
|
||||
* one. Add code to generate llstin() per
|
||||
* setting of "-s" switch. Fix cclprint() to
|
||||
* put 16 "characters" on a line. Clean up
|
||||
* nfaprint().
|
||||
* 29-Aug-82 Bob Denny -- Move chprint to root. Add llstin() to
|
||||
* default lexin to stdin for standard I/O
|
||||
* and no-op for stand-alone I/O. Allows
|
||||
* sdtio-specific code to be removed from
|
||||
* yylex().
|
||||
* 31-Aug-82 Bob Denny -- Add lexswitch( ...) to llstin so table
|
||||
* name selected by -t switch is automatically
|
||||
* switched-to at yylex() startup time. Removed
|
||||
* hard reference to "lextab" from yylex();
|
||||
* 30-Oct-82 Bob Denny -- Remove lexswitch() from llstin(). Made it
|
||||
* impossible to do a real lexswitch()! (dumb.)
|
||||
* Default the table by statically initializing
|
||||
* it to NULL and doing the lexswitch only if
|
||||
* _tabp is NULL.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lexlex.h"
|
||||
|
||||
extern int yyline;
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
nfaprint(np, base)
|
||||
register struct nfa *np;
|
||||
struct nfa *base;
|
||||
{
|
||||
register i;
|
||||
|
||||
if (np->n_flag&NPRT)
|
||||
return;
|
||||
np->n_flag |= NPRT;
|
||||
fprintf(lexlog, "state %d\n", np-base);
|
||||
switch (np->n_char) {
|
||||
case EPSILON:
|
||||
for (i = 0; i < 2; i++)
|
||||
if (np->n_succ[i])
|
||||
fprintf(lexlog, "\tepsilon %d\n", np->n_succ[i]-base);
|
||||
break;
|
||||
case FIN:
|
||||
fprintf(lexlog, "\tfinal state\n");
|
||||
break;
|
||||
case CCL:
|
||||
fprintf(lexlog, "\t[");
|
||||
cclprint(np->n_ccl);
|
||||
fprintf(lexlog, "] %d\n", np->n_succ[0]-base);
|
||||
break;
|
||||
default:
|
||||
putc('\t', lexlog);
|
||||
chprint(np->n_char);
|
||||
fprintf(lexlog, " %d\n", np->n_succ[0]-base);
|
||||
break;
|
||||
}
|
||||
putc('\n', lexlog);
|
||||
if (np->n_succ[0])
|
||||
nfaprint(np->n_succ[0], base);
|
||||
if (np->n_succ[1])
|
||||
nfaprint(np->n_succ[1], base);
|
||||
}
|
||||
|
||||
cclprint(cp)
|
||||
register char *cp;
|
||||
{
|
||||
register i;
|
||||
register nc;
|
||||
|
||||
nc = 0;
|
||||
for (i = 0; i < NCHARS; i++)
|
||||
{
|
||||
if (cp[i / NBPC] & (1 << (i % NBPC)))
|
||||
nc += chprint(i);
|
||||
if(nc >= 64)
|
||||
{
|
||||
nc = 0;
|
||||
fprintf(lexlog, "\n\t ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
llactr()
|
||||
{
|
||||
/*
|
||||
* Prior to generating the action routine, create
|
||||
* the llstin() routine, which initializes yylex(),
|
||||
* per the setting of the "-s" switch. All hardwired
|
||||
* variables have now been removed from yylex(). This
|
||||
* allows analyzers to be independent of the standard
|
||||
* I/O library and the table name.
|
||||
*/
|
||||
if(sflag == 0) /* If stdio flavor */
|
||||
{
|
||||
fprintf(llout, "\n/* Standard I/O selected */\n");
|
||||
fprintf(llout, "extern FILE *lexin;\n\n");
|
||||
fprintf(llout, "llstin()\n {\n if(lexin == NULL)\n");
|
||||
fprintf(llout, " lexin = stdin;\n");
|
||||
}
|
||||
else /* Stand-alone flavor */
|
||||
{
|
||||
fprintf(llout, "\n/* Stand-alone selected */\n");
|
||||
fprintf(llout, "\llstin()\n {\n");
|
||||
}
|
||||
fprintf(llout, " if(_tabp == NULL)\n");
|
||||
fprintf(llout, " lexswitch(&%s);\n }\n\n", tabname);
|
||||
fprintf(llout, "_A%s(__na__)\t\t/* Action routine */\n {\n", tabname);
|
||||
}
|
||||
|
||||
newcase(i)
|
||||
{
|
||||
static int putsw;
|
||||
|
||||
if (!putsw++)
|
||||
fprintf(llout, " switch (__na__)\n {\n");
|
||||
fprintf(llout, "\n case %d:\n", i);
|
||||
setline();
|
||||
}
|
||||
|
||||
|
||||
setline()
|
||||
{
|
||||
fprintf(llout, "\n#line %d \"%s\"\n", yyline, infile);
|
||||
}
|
||||
19
c20/lex/readme.604
Normal file
19
c20/lex/readme.604
Normal file
@@ -0,0 +1,19 @@
|
||||
[6,4] [.LEX] Lexical Analyser Generator
|
||||
|
||||
This is an implementation of the Unix program LEX, which generates
|
||||
lexical analysers from regular expression grammars.
|
||||
|
||||
Because the Decus compiler does not seperate I and D space, LEX
|
||||
cannot be used to build very large grammars. There are several
|
||||
possibilities:
|
||||
|
||||
1. Remove the dfa/nfa print routines, which are needed
|
||||
for debugging.
|
||||
|
||||
2. Use I/O redirection to read the grammar source from
|
||||
stdin. This will save 1/4 K-word or so.
|
||||
|
||||
3. Overlay the parser phases.
|
||||
|
||||
Have fun.
|
||||
|
||||
21
c20/lex/token.c
Normal file
21
c20/lex/token.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Bob Denny 28-Aug-82 Remove reference to stdio.h
|
||||
*/
|
||||
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
char *
|
||||
token(cpp)
|
||||
char **cpp;
|
||||
{
|
||||
if (cpp)
|
||||
*cpp = llend;
|
||||
return(llbuf);
|
||||
}
|
||||
194
c20/lex/word.c
Normal file
194
c20/lex/word.c
Normal file
@@ -0,0 +1,194 @@
|
||||
#include <stdio.h>
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
extern int _lmovb();
|
||||
|
||||
#line 8 "word.lxi"
|
||||
|
||||
char line[133];
|
||||
char *linep = &line;
|
||||
int is_eof = 0;
|
||||
int wordct = 0;
|
||||
#define T_EOL 1
|
||||
main()
|
||||
{
|
||||
register int i;
|
||||
while ((i = yylex()) != 0) {
|
||||
/*
|
||||
* If the "end-of-line" token is returned
|
||||
* AND we're really at the end of a line,
|
||||
* read the next line. Note that T_EOL is
|
||||
* returned twice when the program starts
|
||||
* because of the nature of the look-ahead
|
||||
* algorithms.
|
||||
*/
|
||||
if (i == T_EOL && !is_eof && *linep == 0) {
|
||||
if (ftty(stdin)) {
|
||||
printf("* ");
|
||||
fflush(stdout);
|
||||
}
|
||||
getline();
|
||||
}
|
||||
}
|
||||
printf("%d words\n", wordct);
|
||||
}
|
||||
extern struct lextab word;
|
||||
|
||||
/* Standard I/O selected */
|
||||
extern FILE *lexin;
|
||||
|
||||
llstin()
|
||||
{
|
||||
if(lexin == NULL)
|
||||
lexin = stdin;
|
||||
if(_tabp == NULL)
|
||||
lexswitch(&word);
|
||||
}
|
||||
|
||||
_Aword(__na__) /* Action routine */
|
||||
{
|
||||
switch (__na__) {
|
||||
case 0:
|
||||
|
||||
#line 39 "word.lxi"
|
||||
|
||||
/*
|
||||
* Write each word on a seperate line
|
||||
*/
|
||||
lexecho(stdout);
|
||||
printf("\n");
|
||||
wordct++;
|
||||
return(LEXSKIP);
|
||||
|
||||
break;
|
||||
case 1:
|
||||
|
||||
#line 48 "word.lxi"
|
||||
|
||||
return(T_EOL);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
|
||||
#line 51 "word.lxi"
|
||||
|
||||
return(LEXSKIP);
|
||||
|
||||
break;
|
||||
}
|
||||
return(LEXSKIP);
|
||||
}
|
||||
|
||||
#line 54 "word.lxi"
|
||||
|
||||
|
||||
getline()
|
||||
/*
|
||||
* Read a line for lexgetc()
|
||||
*/
|
||||
{
|
||||
is_eof = (fgets(line, sizeof line, stdin) == NULL);
|
||||
linep = &line;
|
||||
}
|
||||
|
||||
lexgetc()
|
||||
/*
|
||||
* Homemade lexgetc -- return zero while at the end of an
|
||||
* input line or EOF at end of file. If more on this line,
|
||||
* return it.
|
||||
*/
|
||||
{
|
||||
return((is_eof) ? EOF : (*linep == 0) ? 0 : *linep++);
|
||||
}
|
||||
|
||||
int _Fword[] = {
|
||||
-1, 2, 2, 1, 0, 0, -1,
|
||||
};
|
||||
|
||||
#line 74 "word.lxi"
|
||||
|
||||
#define LLTYPE1 char
|
||||
|
||||
LLTYPE1 _Nword[] = {
|
||||
3, 6, 6, 6, 6, 6, 6, 6, 6, 1, 1, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2,
|
||||
2, 2, 2, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 2, 6, 2, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5,
|
||||
};
|
||||
|
||||
LLTYPE1 _Cword[] = {
|
||||
0, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
1, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, 1, -1, 2, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5,
|
||||
};
|
||||
|
||||
LLTYPE1 _Dword[] = {
|
||||
6, 6, 6, 6, 6, 6,
|
||||
};
|
||||
|
||||
int _Bword[] = {
|
||||
0, 118, 120, 0, 120, 214, 0,
|
||||
};
|
||||
#define LLILL LLILL
|
||||
|
||||
char _Zword[] = {
|
||||
0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
||||
0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
||||
|
||||
};
|
||||
|
||||
struct lextab word = {
|
||||
6, /* last state */
|
||||
_Dword, /* defaults */
|
||||
_Nword, /* next */
|
||||
_Cword, /* check */
|
||||
_Bword, /* base */
|
||||
340, /* last in base */
|
||||
_lmovb, /* byte-int move routines */
|
||||
_Fword, /* final state descriptions */
|
||||
_Aword, /* action routine */
|
||||
NULL, /* look-ahead vector */
|
||||
0, /* no ignore class */
|
||||
0, /* no break class */
|
||||
_Zword, /* illegal class */
|
||||
};
|
||||
73
c20/lex/word.lxi
Normal file
73
c20/lex/word.lxi
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Count words -- interactively
|
||||
*/
|
||||
white = [\n\t ]; /* End of a word */
|
||||
eol = [\0]; /* End of input line */
|
||||
any = [!-~]; /* All printing char's */
|
||||
illegal = [\0-\377]; /* Skip over junk */
|
||||
%{
|
||||
char line[133];
|
||||
char *linep = &line;
|
||||
int is_eof = 0;
|
||||
int wordct = 0;
|
||||
#define T_EOL 1
|
||||
main()
|
||||
{
|
||||
register int i;
|
||||
while ((i = yylex()) != 0) {
|
||||
/*
|
||||
* If the "end-of-line" token is returned
|
||||
* AND we're really at the end of a line,
|
||||
* read the next line. Note that T_EOL is
|
||||
* returned twice when the program starts
|
||||
* because of the nature of the look-ahead
|
||||
* algorithms.
|
||||
*/
|
||||
if (i == T_EOL && !is_eof && *linep == 0) {
|
||||
if (ftty(stdin)) {
|
||||
printf("* ");
|
||||
fflush(stdout);
|
||||
}
|
||||
getline();
|
||||
}
|
||||
}
|
||||
printf("%d words\n", wordct);
|
||||
}
|
||||
%}
|
||||
%%
|
||||
|
||||
any(any)* {
|
||||
/*
|
||||
* Write each word on a seperate line
|
||||
*/
|
||||
lexecho(stdout);
|
||||
printf("\n");
|
||||
wordct++;
|
||||
return(LEXSKIP);
|
||||
}
|
||||
eol {
|
||||
return(T_EOL);
|
||||
}
|
||||
white(white)* {
|
||||
return(LEXSKIP);
|
||||
}
|
||||
%%
|
||||
|
||||
getline()
|
||||
/*
|
||||
* Read a line for lexgetc()
|
||||
*/
|
||||
{
|
||||
is_eof = (fgets(line, sizeof line, stdin) == NULL);
|
||||
linep = &line;
|
||||
}
|
||||
|
||||
lexgetc()
|
||||
/*
|
||||
* Homemade lexgetc -- return zero while at the end of an
|
||||
* input line or EOF at end of file. If more on this line,
|
||||
* return it.
|
||||
*/
|
||||
{
|
||||
return((is_eof) ? EOF : (*linep == 0) ? 0 : *linep++);
|
||||
}
|
||||
164
c20/lex/word.oc
Normal file
164
c20/lex/word.oc
Normal file
@@ -0,0 +1,164 @@
|
||||
#
|
||||
#include <stdio.h>
|
||||
#include <lex.h>
|
||||
|
||||
extern int _lmovb();
|
||||
|
||||
#line 8 "WORD.LXI"
|
||||
|
||||
char line[133];
|
||||
char *linep = &line;
|
||||
int is_eof = 0;
|
||||
int wordct = 0;
|
||||
#define T_EOL 1
|
||||
main()
|
||||
{
|
||||
register int i;
|
||||
while ((i = yylex()) != 0) {
|
||||
/*
|
||||
* If the "end-of-line" token is returned
|
||||
* AND we're really at the end of a line,
|
||||
* read the next line. Note that T_EOL is
|
||||
* returned twice when the program starts
|
||||
* because of the nature of the look-ahead
|
||||
* algorithms.
|
||||
*/
|
||||
if (i == T_EOL && !is_eof && *linep == 0) {
|
||||
printf("* ");
|
||||
fflush(stdout);
|
||||
getline();
|
||||
}
|
||||
}
|
||||
printf("%d words\n", wordct);
|
||||
}
|
||||
_Alextab(__na__) {
|
||||
switch (__na__) {
|
||||
case 0:
|
||||
|
||||
#line 37 "WORD.LXI"
|
||||
|
||||
/*
|
||||
* Write each word on a seperate line
|
||||
*/
|
||||
lexecho(stdout);
|
||||
printf("\n");
|
||||
wordct++;
|
||||
return(LEXSKIP);
|
||||
|
||||
break;
|
||||
case 1:
|
||||
|
||||
#line 46 "WORD.LXI"
|
||||
|
||||
return(T_EOL);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
|
||||
#line 49 "WORD.LXI"
|
||||
|
||||
return(LEXSKIP);
|
||||
|
||||
break;
|
||||
}
|
||||
return(LEXSKIP);
|
||||
}
|
||||
|
||||
#line 52 "WORD.LXI"
|
||||
|
||||
|
||||
getline()
|
||||
/*
|
||||
* Read a line for lexgetc()
|
||||
*/
|
||||
{
|
||||
is_eof = (fgets(line, sizeof line, stdin) == NULL);
|
||||
linep = &line;
|
||||
}
|
||||
|
||||
lexgetc()
|
||||
/*
|
||||
* Homemade lexgetc -- return zero while at the end of an
|
||||
* input line or EOF at end of file. If more on this line,
|
||||
* return it.
|
||||
*/
|
||||
{
|
||||
return((is_eof) ? EOF : (*linep == 0) ? 0 : *linep++);
|
||||
}
|
||||
|
||||
int _Flextab[] {
|
||||
-1, 2, 2, 1, 0, 0, -1,
|
||||
};
|
||||
|
||||
#line 72 "WORD.LXI"
|
||||
|
||||
#define LLTYPE1 char
|
||||
|
||||
LLTYPE1 _Nlextab[] {
|
||||
3, 6, 6, 6, 6, 6, 6, 6, 6, 1, 1, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2,
|
||||
2, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5,
|
||||
};
|
||||
|
||||
LLTYPE1 _Clextab[] {
|
||||
0, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 4,
|
||||
};
|
||||
|
||||
LLTYPE1 _Dlextab[] {
|
||||
6, 6, 1, 6, 6, 4,
|
||||
};
|
||||
|
||||
int _Blextab[] {
|
||||
0, 118, 0, 0, 118, 0, 0,
|
||||
};
|
||||
#define LLILL LLILL
|
||||
|
||||
char _Zlextab[] {
|
||||
0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
||||
0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
||||
|
||||
};
|
||||
|
||||
struct lextab lextab {
|
||||
6, /* last state */
|
||||
_Dlextab, /* defaults */
|
||||
_Nlextab, /* next */
|
||||
_Clextab, /* check */
|
||||
_Blextab, /* base */
|
||||
244, /* last in base */
|
||||
_lmovb, /* byte-int move routines */
|
||||
_Flextab, /* final state descriptions */
|
||||
_Alextab, /* action routine */
|
||||
NULL, /* look-ahead vector */
|
||||
0, /* no ignore class */
|
||||
0, /* no break class */
|
||||
_Zlextab, /* illegal class */
|
||||
};
|
||||
948
c20/lex/ytab.c
Normal file
948
c20/lex/ytab.c
Normal file
@@ -0,0 +1,948 @@
|
||||
# define vms 1
|
||||
/*
|
||||
* * * * W A R N I N G * * *
|
||||
*
|
||||
* This file has been hand-modified from that which was produced by Yacc
|
||||
* from 'lex.y'. If you plan on rebuilding this with Yacc, be SURE to run
|
||||
* the virgin supplied 'lex.y' thru Yacc first, do a source compare of it's
|
||||
* output 'ytab.c' with this file, and note & understand the manual mods
|
||||
* that were made here.
|
||||
* Bob Denny
|
||||
*
|
||||
* Modified 02-Dec-80 Bob Denny -- Conditionalized debug code for smaller size
|
||||
* YYSMALL no longer used.
|
||||
* Removed hackish accent grave's.
|
||||
* 01 Moved calls do dfa build, min, print and
|
||||
* write, and to stat() to lex.c, so this
|
||||
* module could be put in overlay region.
|
||||
* Moved impure data out into ytdata.c to
|
||||
* go to the root.
|
||||
*
|
||||
* 29-May-81 Bob Denny -- Define yysterm fwd. Remove from LEXLEX.H.
|
||||
* for RSX overlaying.
|
||||
* 19-Mar-82 Bob Denny -- New compiler and library. Typcasts needed.
|
||||
* Conditionally compile remote formats, not
|
||||
* supported in VAX C.
|
||||
* More 03-May-82 Bob Denny -- Final touches, remove unreferenced autos
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ytab.h"
|
||||
#include <ctype.h>
|
||||
|
||||
extern char *yysterm[]; /* Hack forward definition */
|
||||
|
||||
#line 9 "lex.y"
|
||||
#include "lexlex.h"
|
||||
|
||||
#define streq(a,b) (stcmp(a,b) != 0)
|
||||
|
||||
/* char copr[] = "Copyright (c) 1978 Charles H. Forsyth";*/
|
||||
|
||||
struct des {
|
||||
struct nfa *d_start;
|
||||
struct nfa *d_final;
|
||||
};
|
||||
extern struct nlist { /* 01+ */
|
||||
struct nlist *nl_next;
|
||||
struct nfa *nl_base;
|
||||
struct nfa *nl_end;
|
||||
struct nfa *nl_start;
|
||||
struct nfa *nl_final;
|
||||
char *nl_name;
|
||||
} *nlist; /* 01- */
|
||||
extern int str_length;
|
||||
extern struct nfa *elem();
|
||||
extern struct des *newdp();
|
||||
extern struct nlist *lookup();
|
||||
#define yyclearin yychar = -1
|
||||
/* #define yyerrok yyerrflag = 0 */
|
||||
extern int yychar, yyerrflag;
|
||||
|
||||
#ifndef YYSTYPE
|
||||
#define YYSTYPE int
|
||||
#endif
|
||||
#ifndef YYVCOPY
|
||||
#define YYVCOPY(x,y) (x)=(y)
|
||||
#endif
|
||||
|
||||
extern YYSTYPE yyval; /* 01+ */
|
||||
extern YYSTYPE *yypv;
|
||||
extern YYSTYPE yylval;
|
||||
|
||||
|
||||
|
||||
extern int nlook;
|
||||
extern int yyline;
|
||||
extern char *breakc;
|
||||
extern char *ignore;
|
||||
extern char *illeg; /* 01- */
|
||||
|
||||
yyacr(__np__){
|
||||
|
||||
#line 40 "lex.y"
|
||||
struct nfa *np, *nbase;
|
||||
char *cp;
|
||||
struct des *dp;
|
||||
struct trans *tp;
|
||||
struct nlist *nl;
|
||||
int i, c;
|
||||
|
||||
switch(__np__){
|
||||
|
||||
case 7:
|
||||
#line 64 "lex.y"
|
||||
{
|
||||
dp = yypv[3];
|
||||
nl = yypv[1];
|
||||
np = nl->nl_base;
|
||||
nl->nl_start = dp->d_start;
|
||||
nl->nl_final = dp->d_final;
|
||||
nl->nl_end = nfap;
|
||||
#ifdef DEBUG
|
||||
fprintf(lexlog, "NFA (auxiliary definition) for %s\n",
|
||||
nl->nl_name);
|
||||
nfaprint(dp->d_start, nl->nl_base);
|
||||
#endif
|
||||
nbase = lalloc(i = nl->nl_end-nl->nl_base, sizeof(*nbase),
|
||||
"nfa storage");
|
||||
copynfa(nl, nbase, dp);
|
||||
nl->nl_start = dp->d_start;
|
||||
nl->nl_final = dp->d_final;
|
||||
nl->nl_end = nbase+i;
|
||||
nl->nl_base = nbase;
|
||||
nfap = np;
|
||||
spccl(nl->nl_name, "ignore", dp, &ignore);
|
||||
spccl(nl->nl_name, "break", dp, &breakc);
|
||||
spccl(nl->nl_name, "illegal", dp, &illeg);
|
||||
} break;
|
||||
case 8:
|
||||
#line 85 "lex.y"
|
||||
{ copycode(); } break;
|
||||
case 9:
|
||||
#line 89 "lex.y"
|
||||
{
|
||||
yyval = lookup(yypv[1]);
|
||||
((struct nlist *)yyval)->nl_base = nfap;
|
||||
if (((struct nlist *)yyval)->nl_start)
|
||||
#ifdef vms
|
||||
yyemsg("redefined", ((struct nlist *)yyval)->nl_name);
|
||||
#else
|
||||
yyemsg("%s redefined", ((struct nlist *)yyval)->nl_name);
|
||||
#endif
|
||||
} break;
|
||||
case 10:
|
||||
#line 98 "lex.y"
|
||||
{ yyval = lookup(yypv[1]); } break;
|
||||
case 11:
|
||||
#line 102 "lex.y"
|
||||
{
|
||||
np = elem(CCL, yypv[1]);
|
||||
yyval = newdp(np, np->n_succ[0] = elem(FIN));
|
||||
} break;
|
||||
case 12:
|
||||
#line 106 "lex.y"
|
||||
{
|
||||
cp = yypv[1];
|
||||
if (str_length == 0) {
|
||||
np = elem(EPSILON);
|
||||
yyval = newdp(np, np->n_succ[0] = elem(FIN));
|
||||
return;
|
||||
}
|
||||
yyval = np = elem(*cp++);
|
||||
while (--str_length > 0)
|
||||
np = np->n_succ[0] = elem(*cp++);
|
||||
yyval = newdp(yyval, np->n_succ[0] = elem(FIN));
|
||||
} break;
|
||||
case 13:
|
||||
#line 118 "lex.y"
|
||||
{
|
||||
if ((nl = yypv[1])->nl_end == 0) {
|
||||
#ifdef vms
|
||||
yyemsg("not defined", nl->nl_name);
|
||||
#else
|
||||
yyemsg("%s not defined", nl->nl_name);
|
||||
#endif
|
||||
nl->nl_base = nl->nl_end = elem(FIN);
|
||||
nl->nl_start = nl->nl_final = nl->nl_base;
|
||||
}
|
||||
yyval = dp = lalloc(1, sizeof(*dp), "dfa input");
|
||||
nbase = nfap;
|
||||
i = nl->nl_end-nl->nl_base;
|
||||
if ((nfap += i) >= &nfa[MAXNFA]) {
|
||||
yyemsg("Out of NFA nodes", NULL);
|
||||
exit(1);
|
||||
}
|
||||
copynfa(nl, nbase, dp);
|
||||
} break;
|
||||
case 14:
|
||||
#line 133 "lex.y"
|
||||
{
|
||||
yyval = dp = yypv[1];
|
||||
dp->d_start = newnfa(EPSILON, np = dp->d_start, 0);
|
||||
dp->d_final->n_char = EPSILON;
|
||||
dp->d_final->n_succ[0] = np;
|
||||
dp->d_final->n_succ[1] = np = elem(FIN);
|
||||
dp->d_start->n_succ[1] = np;
|
||||
dp->d_final = np;
|
||||
} break;
|
||||
case 15:
|
||||
#line 142 "lex.y"
|
||||
{
|
||||
yyval = dp = yypv[1];
|
||||
dp->d_start = newnfa(EPSILON, dp->d_start,
|
||||
((struct des *)yypv[3])->d_start);
|
||||
dp->d_final->n_char = EPSILON;
|
||||
dp->d_final = dp->d_final->n_succ[0] = np = elem(FIN);
|
||||
dp = yypv[3];
|
||||
dp->d_final->n_char = EPSILON;
|
||||
dp->d_final->n_succ[0] = np;
|
||||
free(yypv[3]);
|
||||
} break;
|
||||
case 16:
|
||||
#line 152 "lex.y"
|
||||
{
|
||||
yyval = yypv[1];
|
||||
dp = yypv[2];
|
||||
np = ((struct des *)yyval)->d_final;
|
||||
((struct des *)yyval)->d_final = dp->d_final;
|
||||
np->n_char = dp->d_start->n_char;
|
||||
np->n_ccl = dp->d_start->n_ccl;
|
||||
np->n_succ[0] = dp->d_start->n_succ[0];
|
||||
np->n_succ[1] = dp->d_start->n_succ[1];
|
||||
free(yypv[2]);
|
||||
} break;
|
||||
case 17:
|
||||
#line 163 "lex.y"
|
||||
{ yyval = yypv[2]; } break;
|
||||
case 18:
|
||||
#line 167 "lex.y"
|
||||
{
|
||||
ending();
|
||||
trans1:
|
||||
#ifdef DEBUG
|
||||
fprintf(lexlog, "\nNFA for complete syntax\n");
|
||||
fprintf(lexlog, "state 0\n");
|
||||
for (tp = trans; tp < trnsp; tp++)
|
||||
fprintf(lexlog, "\tepsilon\t%d\n", tp->t_start-nfa);
|
||||
for (tp = trans; tp < trnsp; tp++)
|
||||
nfaprint(tp->t_start, nfa);
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
/* 01 */
|
||||
} break;
|
||||
case 19:
|
||||
#line 182 "lex.y"
|
||||
{ goto trans1; } break;
|
||||
case 22:
|
||||
#line 191 "lex.y"
|
||||
{
|
||||
llactr();
|
||||
} break;
|
||||
case 23:
|
||||
#line 197 "lex.y"
|
||||
{ dp = yypv[1]; newtrans(dp->d_start, dp->d_final); } break;
|
||||
case 24:
|
||||
#line 198 "lex.y"
|
||||
{ copycode(); } break;
|
||||
case 25:
|
||||
#line 199 "lex.y"
|
||||
{
|
||||
ending();
|
||||
while ((c = get()) != EOF)
|
||||
putc(c, llout);
|
||||
} break;
|
||||
case 26:
|
||||
#line 207 "lex.y"
|
||||
{ action(); } break;
|
||||
case 27:
|
||||
#line 211 "lex.y"
|
||||
{
|
||||
if (nlook >= NBPW)
|
||||
#ifdef vms
|
||||
yyemsg("Too many translations with lookahead", NULL);
|
||||
#else
|
||||
yyemsg("More than %d translations with lookahead",
|
||||
NBPW);
|
||||
#endif
|
||||
yyval = dp = yypv[1];
|
||||
np = dp->d_final;
|
||||
np->n_char = EPSILON;
|
||||
np->n_flag |= LOOK;
|
||||
np->n_succ[0] = ((struct des *)yypv[3])->d_start;
|
||||
dp->d_final = ((struct des *)yypv[3])->d_final;
|
||||
np->n_look = nlook;
|
||||
dp->d_final->n_look = nlook++;
|
||||
dp->d_final->n_flag |= FLOOK;
|
||||
free(yypv[3]);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
int yyeval = 256; /* yyerrval */
|
||||
|
||||
#line 228 "lex.y"
|
||||
|
||||
/*
|
||||
* Lexical analyser
|
||||
* (it isn't done with lex...)
|
||||
*/
|
||||
extern char buffer[150]; /* 01 */
|
||||
extern int str_length; /* 01 */
|
||||
|
||||
yylex()
|
||||
{
|
||||
register c;
|
||||
register char *cp;
|
||||
int lno;
|
||||
|
||||
if (yyline == 0)
|
||||
yyline++;
|
||||
loop:
|
||||
c = get();
|
||||
if (isupper(c)) {
|
||||
name(c);
|
||||
for (cp = yylval; c = *cp; cp++)
|
||||
if (isupper(c))
|
||||
*cp = tolower(c);
|
||||
return(STRING);
|
||||
} else if (islower(c) || c == '_') {
|
||||
name(c);
|
||||
return(NAME);
|
||||
}
|
||||
switch (c) {
|
||||
case EOF:
|
||||
return(0);
|
||||
|
||||
case '[':
|
||||
return(cclass());
|
||||
|
||||
case '(':
|
||||
case ')':
|
||||
case '{':
|
||||
case '}':
|
||||
case '*':
|
||||
case '|':
|
||||
case '=':
|
||||
case ';':
|
||||
case '%':
|
||||
return(c);
|
||||
|
||||
case '/':
|
||||
if ((c = get()) != '*') {
|
||||
un_get(c);
|
||||
return('/');
|
||||
}
|
||||
lno = yyline;
|
||||
for (; c != EOF; c = get())
|
||||
if (c == '*')
|
||||
if ((c = get()) == '/')
|
||||
goto loop; else
|
||||
un_get(c);
|
||||
yyline = lno;
|
||||
yyemsg("End of file in comment", NULL);
|
||||
|
||||
case '\'':
|
||||
case '"':
|
||||
yylval = buffer;
|
||||
string(c);
|
||||
return(STRING);
|
||||
|
||||
case '\n':
|
||||
case ' ':
|
||||
case '\t':
|
||||
goto loop;
|
||||
|
||||
default:
|
||||
yylval = buffer;
|
||||
buffer[0] = c;
|
||||
buffer[1] = 0;
|
||||
str_length = 1;
|
||||
return(STRING);
|
||||
}
|
||||
}
|
||||
|
||||
extern char ccl[(NCHARS+1)/NBPC]; /* 01 */
|
||||
|
||||
cclass()
|
||||
{
|
||||
register c, i, lc;
|
||||
int compl;
|
||||
|
||||
compl = 0;
|
||||
for (i = 0; i < sizeof ccl; i++)
|
||||
ccl[i] = 0;
|
||||
if ((c = get()) == '^')
|
||||
compl++; else
|
||||
un_get(c);
|
||||
lc = -1;
|
||||
while ((c = mapc(']')) != EOF) {
|
||||
if (c == '-' && lc >= 0) {
|
||||
if ((c = mapc(']')) == EOF)
|
||||
break;
|
||||
for (i = lc; i <= c; i++)
|
||||
ccl[i/NBPC] |= 1<<(i%NBPC);
|
||||
lc = -1;
|
||||
continue;
|
||||
}
|
||||
ccl[c/NBPC] |= 1<<(c%NBPC);
|
||||
lc = c;
|
||||
}
|
||||
if (compl) {
|
||||
for (i = 0; i < sizeof ccl; i++)
|
||||
ccl[i] ^= -1;
|
||||
if (aflag == 0)
|
||||
for (i = 0200; i < (1<<NBPC); i++)
|
||||
ccl[i/NBPC] &= ~(1 << (i%NBPC));
|
||||
}
|
||||
yylval = newccl(ccl);
|
||||
return(CCLASS);
|
||||
}
|
||||
|
||||
string(ec)
|
||||
{
|
||||
register char *cp;
|
||||
register c;
|
||||
|
||||
for (cp = buffer; (c = mapc(ec)) != EOF;)
|
||||
*cp++ = c;
|
||||
*cp = 0;
|
||||
str_length = cp-buffer;
|
||||
}
|
||||
|
||||
mapc(ec)
|
||||
{
|
||||
register c, v, i;
|
||||
|
||||
if ((c = get()) == ec)
|
||||
return(EOF);
|
||||
switch(c) {
|
||||
case EOF:
|
||||
yyemsg("End of file in string", NULL);
|
||||
return(c);
|
||||
|
||||
case '\\':
|
||||
if ((c = get()) >= '0' && c <= '7') {
|
||||
i = 0;
|
||||
for (v = 0; c>='0' && c<='7' && i++<3; c = get())
|
||||
v = v*010 + c-'0';
|
||||
un_get(c);
|
||||
return(v&0377);
|
||||
}
|
||||
switch (c) {
|
||||
case 'n':
|
||||
return('\n');
|
||||
|
||||
case 't':
|
||||
return('\t');
|
||||
|
||||
case 'b':
|
||||
return('\b');
|
||||
|
||||
case 'r':
|
||||
return('\r');
|
||||
|
||||
case '\n':
|
||||
yyline++;
|
||||
return(mapc(ec));
|
||||
}
|
||||
|
||||
default:
|
||||
return(c);
|
||||
}
|
||||
}
|
||||
|
||||
name(c)
|
||||
register c;
|
||||
{
|
||||
register char *cp;
|
||||
|
||||
for (yylval=cp=buffer; isalpha(c) || isdigit(c) || c=='_'; c=get())
|
||||
*cp++ = c;
|
||||
*cp = 0;
|
||||
str_length = cp-buffer;
|
||||
un_get(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Miscellaneous functions
|
||||
* used only by lex.y
|
||||
*/
|
||||
struct nfa *
|
||||
elem(k, v)
|
||||
{
|
||||
struct nfa *fp;
|
||||
|
||||
fp = newnfa(k, 0, 0);
|
||||
if (k == CCL)
|
||||
fp->n_ccl = v;
|
||||
return(fp);
|
||||
}
|
||||
|
||||
struct des *
|
||||
newdp(st, fi)
|
||||
struct nfa *st, *fi;
|
||||
{
|
||||
register struct des *dp;
|
||||
|
||||
dp = lalloc(1, sizeof(*dp), "dfa input");
|
||||
dp->d_start = st;
|
||||
dp->d_final = fi;
|
||||
return(dp);
|
||||
}
|
||||
|
||||
action()
|
||||
{
|
||||
register c;
|
||||
int lno, lev;
|
||||
|
||||
newcase(trnsp-trans);
|
||||
lno = yyline;
|
||||
lev = 0;
|
||||
for (; (c = get()) != EOF && (c != '}' || lev); putc(c, llout))
|
||||
if (c == '{')
|
||||
lev++;
|
||||
else if (c == '}')
|
||||
lev--;
|
||||
else if (c == '\'' || c == '"') {
|
||||
putc(c, llout);
|
||||
skipstr(c);
|
||||
}
|
||||
fprintf(llout, "\n break;\n");
|
||||
if (c == EOF) {
|
||||
yyline = lno;
|
||||
yyemsg("End of file in action", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
skipstr(ec)
|
||||
register ec;
|
||||
{
|
||||
register c;
|
||||
|
||||
while ((c = get()) != ec && c != EOF) {
|
||||
putc(c, llout);
|
||||
if (c == '\\' && (c = get()) != EOF)
|
||||
putc(c, llout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
copycode()
|
||||
{
|
||||
int lno;
|
||||
register c;
|
||||
|
||||
setlne();
|
||||
lno = yyline;
|
||||
for (; (c = get()) != EOF; putc(c, llout))
|
||||
if (c == '%') {
|
||||
if ((c = get()) == '}')
|
||||
return;
|
||||
un_get(c);
|
||||
c = '%';
|
||||
}
|
||||
yyline = lno;
|
||||
yyemsg("Incomplete %{ declaration", NULL);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct nlist *
|
||||
lookup(s)
|
||||
register char *s;
|
||||
{
|
||||
register struct nlist *nl;
|
||||
register char *cp;
|
||||
int i;
|
||||
for (nl = nlist; nl; nl = nl->nl_next)
|
||||
if (streq(s, nl->nl_name))
|
||||
return(nl);
|
||||
nl = lalloc(1, sizeof(*nl), "namelist");
|
||||
nl->nl_start = nl->nl_end = nl->nl_base = nl->nl_end = 0;
|
||||
nl->nl_next = nlist;
|
||||
nlist = nl;
|
||||
i = 0;
|
||||
nl->nl_name = cp = lalloc(strlen(s) + 1, sizeof(*cp), "namelist");
|
||||
strcpy(cp, s);
|
||||
return(nl);
|
||||
}
|
||||
|
||||
|
||||
copynfa(nl, nbase, dp)
|
||||
struct nlist *nl;
|
||||
struct des *dp;
|
||||
struct nfa *nbase;
|
||||
{
|
||||
register struct nfa *np, *ob;
|
||||
register j;
|
||||
int i;
|
||||
|
||||
ob = nl->nl_base;
|
||||
i = nl->nl_end-ob;
|
||||
/*
|
||||
* Assumes Decus compiler: copy(out, in, nbytes)
|
||||
*/
|
||||
copy(nbase, ob, sizeof(*np) * i);
|
||||
for (np = nbase; i-- > 0; np++) {
|
||||
np->n_flag &= ~NPRT;
|
||||
for (j = 0; j < 2; j++)
|
||||
if (np->n_succ[j])
|
||||
np->n_succ[j] = (np->n_succ[j]-ob)+nbase;
|
||||
}
|
||||
dp->d_start = (nl->nl_start-ob)+nbase;
|
||||
dp->d_final = (nl->nl_final-ob)+nbase;
|
||||
}
|
||||
|
||||
/* #ifdef vms */
|
||||
copy(out, in, count)
|
||||
register char *out;
|
||||
register char *in;
|
||||
register int count;
|
||||
/*
|
||||
* Block copy for vms -- should be in stdio.lib (in macro)
|
||||
*/
|
||||
{
|
||||
while (--count >= 0)
|
||||
*out++ = *in++;
|
||||
}
|
||||
/* #endif */
|
||||
|
||||
spccl(nm, isit, dp, where)
|
||||
char *nm;
|
||||
char *isit;
|
||||
register struct des *dp;
|
||||
char **where;
|
||||
{
|
||||
|
||||
if (streq(nm, isit)) {
|
||||
if (*where != 0)
|
||||
#ifdef vms
|
||||
yyemsg("Redefinition of class", isit);
|
||||
#else
|
||||
yyemsg("Redefinition of %s class", isit);
|
||||
#endif
|
||||
if (dp->d_start->n_char == CCL &&
|
||||
dp->d_start->n_succ[0] == dp->d_final)
|
||||
*where = dp->d_start->n_ccl;
|
||||
else
|
||||
#ifdef vms
|
||||
yyemsg("Illegal class", isit);
|
||||
#else
|
||||
yyemsg("Illegal %s class", isit);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
get()
|
||||
{
|
||||
register int c;
|
||||
|
||||
if ((c = getc(lexin)) == '\n')
|
||||
yyline++;
|
||||
return(c);
|
||||
}
|
||||
|
||||
un_get(c)
|
||||
register c;
|
||||
{
|
||||
if (c == '\n')
|
||||
yyline--;
|
||||
ungetc(c, lexin);
|
||||
}
|
||||
|
||||
#ifdef vms
|
||||
yyemsg(s, arg)
|
||||
char *s;
|
||||
char *arg;
|
||||
{
|
||||
if (yyline)
|
||||
fprintf(stderr, "%d: ", yyline);
|
||||
fprintf(stderr, "%s", s);
|
||||
if(arg != NULL)
|
||||
fprintf(stderr, ": \"%s\"", arg);
|
||||
#else
|
||||
yyemsg(s)
|
||||
char *s;
|
||||
{
|
||||
if (yyline)
|
||||
fprintf(stderr, "%d: ", yyline);
|
||||
fprintf(stderr, "%r", &s);
|
||||
#endif
|
||||
if (yychar > 256)
|
||||
fprintf(stderr, " near '%s'", yysterm[yychar-256]);
|
||||
else if (yychar < 256 && yychar > 0)
|
||||
fprintf(stderr, " near '%c'", yychar);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int nterms = 15;
|
||||
int nnonter = 13;
|
||||
int nstate = 41;
|
||||
char *yysterm[] = {
|
||||
"error",
|
||||
"NAME",
|
||||
"CCLASS",
|
||||
"STRING",
|
||||
"CONCAT",
|
||||
0 };
|
||||
|
||||
char *yysnter[] = {
|
||||
"$accept",
|
||||
"lexfile",
|
||||
"auxiliary_section",
|
||||
"translation_section",
|
||||
"auxiliaries",
|
||||
"auxiliary",
|
||||
"namedef",
|
||||
"regexp",
|
||||
"name",
|
||||
"translations",
|
||||
"translation",
|
||||
"llactr",
|
||||
"pattern",
|
||||
"action" };
|
||||
#
|
||||
extern int yychar;
|
||||
|
||||
int yylast = 245;
|
||||
yyexcp(s){
|
||||
extern int yydef[];
|
||||
switch(s){
|
||||
case 1:
|
||||
if( yychar == 0 ) return( -1 );
|
||||
return( 0 );
|
||||
case 2:
|
||||
if( yychar == 0 ) return( 19 );
|
||||
return( 22 );
|
||||
}
|
||||
}
|
||||
|
||||
yyact[] = {
|
||||
|
||||
23, 40, 32, 23, 29, 32, 23, 15, 32, 23,
|
||||
31, 32, 23, 35, 32, 18, 26, 13, 23, 32,
|
||||
34, 23, 37, 11, 4, 5, 16, 28, 17, 12,
|
||||
19, 19, 10, 9, 22, 6, 27, 25, 3, 8,
|
||||
2, 1, 0, 0, 36, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 38, 0, 39, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 33, 0, 0, 33, 0, 0,
|
||||
33, 0, 0, 33, 0, 0, 30, 0, 0, 0,
|
||||
0, 0, 14, 14, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 24, 20, 21,
|
||||
24, 20, 21, 24, 20, 21, 24, 20, 21, 24,
|
||||
20, 21, 0, 0, 0, 24, 20, 21, 24, 20,
|
||||
21, 0, 0, 7, 7 };
|
||||
yypact[] = {
|
||||
|
||||
-13,-2000,-2000, -14, -20,-1000, -54,-1000,-1000, -22,
|
||||
-22, -21,-1000,-1000,-1000, -19,-1000,-119, -27, -34,
|
||||
-1000,-1000,-1000, -19,-1000,-1000,-1000, -37,-1000,-1000,
|
||||
-1000,-1000,-1000, -19, -23, -19, -40,-1000, -28, -31,
|
||||
-1000 };
|
||||
yypgo[] = {
|
||||
|
||||
0, 41, 40, 39, 38, 25, 35, 20, 34, 33,
|
||||
26, 32, 28, 27 };
|
||||
yyr1[] = {
|
||||
|
||||
0, 1, 1, 2, 2, 4, 4, 5, 5, 6,
|
||||
8, 7, 7, 7, 7, 7, 7, 7, 3, 3,
|
||||
9, 9, 11, 10, 10, 10, 13, 12, 12, -1 };
|
||||
yyr2[] = {
|
||||
|
||||
0, 2, 0, 3, 2, 2, 1, 4, 2, 1,
|
||||
1, 1, 1, 1, 2, 3, 2, 3, 1, 0,
|
||||
2, 2, 0, 2, 2, 2, 1, 3, 1, -1 };
|
||||
yychk[] = {
|
||||
|
||||
0, -1, -2, -4, 37, -5, -6, 257, -3, -9,
|
||||
-11, 37, -5, 37, 123, 61, -10, -12, 37, -7,
|
||||
258, 259, -8, 40, 257, -10, 37, -7, -13, 123,
|
||||
123, 37, 42, 124, -7, 47, -7, 59, -7, -7,
|
||||
41 };
|
||||
yydef[] = {
|
||||
|
||||
2, -2, -2, 0, 0, 6, 0, 9, 1, 18,
|
||||
0, 0, 5, 4, 8, 0, 20, 0, 0, 28,
|
||||
11, 12, 13, 0, 10, 21, 3, 0, 23, 26,
|
||||
24, 25, 14, 0, 16, 0, 0, 7, 15, 27,
|
||||
17 };
|
||||
|
||||
# define YYFLAG1 -1000
|
||||
# define YYFLAG2 -2000
|
||||
|
||||
/* test me on cases where there are more than one reduction
|
||||
per state, leading to the necessity to look ahead, and other
|
||||
arcane flows of control.
|
||||
*/
|
||||
# define YYMAXDEPTH 150
|
||||
|
||||
/* parser for yacc output */
|
||||
/* extern YYSTYPE yyval; -- defined in the table file
|
||||
* extern YYSTYPE yylval; -- defined in the table file
|
||||
* extern YYSTYPE *yypv; -- defined in the table file
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
#define LOGOUT lexlog
|
||||
#endif
|
||||
|
||||
extern int yydebug; /* 1 for debugging */ /* 01+ */
|
||||
|
||||
extern YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
|
||||
extern int yychar; /* current input token number */
|
||||
extern int yynerrs ; /* number of errors */
|
||||
extern int yyerrflag ; /* error recovery flag */ /* 01- */
|
||||
|
||||
|
||||
yyparse() {
|
||||
|
||||
/* extern int yypgo[], yyr1[], yyr2[], yyact[], yypact[];
|
||||
* extern int yydef[], yychk[];
|
||||
* extern int yylast, yyeval;
|
||||
*/
|
||||
int yys[YYMAXDEPTH];
|
||||
int yyj;
|
||||
register yyn, yystate, *yyps;
|
||||
|
||||
yystate = 0;
|
||||
yychar = -1;
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yyps= &yys[0]-1;
|
||||
yypv= &yyv[0]-1;
|
||||
|
||||
yystack: /* put a state and value onto the stack */
|
||||
|
||||
#ifdef DEBUG
|
||||
if( yydebug )
|
||||
fprintf(LOGOUT, "state %d, value %d, char %d\n",yystate,yyval,yychar);
|
||||
#endif
|
||||
|
||||
*++yyps = yystate;
|
||||
*++yypv = yyval;
|
||||
|
||||
yynewstate:
|
||||
|
||||
yyn = yypact[yystate];
|
||||
|
||||
if( yyn<= YYFLAG1 ){ /* simple state */
|
||||
if( yyn == YYFLAG2 && yychar<0 ) yychar = yylex();
|
||||
goto yydefault;
|
||||
}
|
||||
|
||||
if( yychar<0 ) yychar = yylex();
|
||||
if( (yyn += yychar)<0 || yyn >= yylast ) goto yydefault;
|
||||
|
||||
if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
|
||||
yychar = -1;
|
||||
yyval = yylval;
|
||||
yystate = yyn;
|
||||
if( yyerrflag > 0 ) --yyerrflag;
|
||||
goto yystack;
|
||||
}
|
||||
|
||||
yydefault:
|
||||
/* default state action */
|
||||
|
||||
if( (yyn=yydef[yystate]) == -2 ) yyn = yyexcp( yystate );
|
||||
|
||||
if( yyn == -1 ){ /* accept */
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
if( yyn == 0 ){ /* error */
|
||||
/* error ... attempt to resume parsing */
|
||||
|
||||
switch( yyerrflag ){
|
||||
|
||||
case 0: /* brand new error */
|
||||
|
||||
++yynerrs;
|
||||
yyemsg("syntax error", NULL);
|
||||
|
||||
case 1:
|
||||
case 2: /* incompletely recovered error ... try again */
|
||||
|
||||
yyerrflag = 3;
|
||||
|
||||
/* find a state where "error" is a legal shift action */
|
||||
|
||||
while ( yyps >= yys ) {
|
||||
yyn = yypact[*yyps] + yyeval;
|
||||
if( yyn>= 0 && yyn < yylast && yychk[yyact[yyn]] == yyeval ){
|
||||
yystate = yyact[yyn]; /* simulate a shift of "error" */
|
||||
goto yystack;
|
||||
}
|
||||
yyn = yypact[*yyps];
|
||||
|
||||
/* the current yyps has no shift onn "error", pop stack */
|
||||
|
||||
#ifdef DEBUG
|
||||
if(yydebug)
|
||||
fprintf(LOGOUT, "error recovery pops state %d, uncovers %d\n",
|
||||
*yyps, yyps[-1]);
|
||||
#endif
|
||||
|
||||
--yyps;
|
||||
--yypv;
|
||||
}
|
||||
|
||||
/* there is no state on the stack with an error shift ... abort */
|
||||
|
||||
abort:
|
||||
return(1);
|
||||
|
||||
|
||||
case 3: /* no shift yet; clobber input char */
|
||||
|
||||
#ifdef DEBUG
|
||||
if (yydebug)
|
||||
fprintf(LOGOUT, "error recovery discards char %d\n", yychar );
|
||||
#endif
|
||||
|
||||
if( yychar == 0 ) goto abort; /* don't discard EOF, quit */
|
||||
yychar = -1;
|
||||
goto yynewstate; /* try again in the same state */
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* reduction by production yyn */
|
||||
|
||||
#ifdef DEBUG
|
||||
if(yydebug) fprintf(LOGOUT, "reduce %d\n",yyn);
|
||||
#endif
|
||||
|
||||
yyps -= yyr2[yyn];
|
||||
yypv -= yyr2[yyn];
|
||||
/* YYVCOPY(yyval,yypv[1]);
|
||||
*/ yyval = yypv[1];
|
||||
yyacr(yyn);
|
||||
/* consult goto table to find next state */
|
||||
yyn = yyr1[yyn];
|
||||
yyj = yypgo[yyn] + *yyps + 1;
|
||||
if( yyj>=yylast || yychk[ yystate = yyact[yyj] ] != -yyn )
|
||||
yystate = yyact[yypgo[yyn]];
|
||||
goto yystack; /* stack new state and value */
|
||||
|
||||
}
|
||||
5
c20/lex/ytab.h
Normal file
5
c20/lex/ytab.h
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
# define NAME 257
|
||||
# define CCLASS 258
|
||||
# define STRING 259
|
||||
# define CONCAT 260
|
||||
946
c20/lex/ytab.old
Normal file
946
c20/lex/ytab.old
Normal file
@@ -0,0 +1,946 @@
|
||||
/*
|
||||
* * * * W A R N I N G * * *
|
||||
*
|
||||
* This file has been hand-modified from that which was produced by Yacc
|
||||
* from 'lex.y'. If you plan on rebuilding this with Yacc, be SURE to run
|
||||
* the virgin supplied 'lex.y' thru Yacc first, do a source compare of it's
|
||||
* output 'ytab.c' with this file, and note & understand the manual mods
|
||||
* that were made here.
|
||||
* Bob Denny
|
||||
*
|
||||
* Modified 02-Dec-80 Bob Denny -- Conditionalized debug code for smaller size
|
||||
* YYSMALL no longer used.
|
||||
* Removed hackish accent grave's.
|
||||
* 01 Moved calls do dfa build, min, print and
|
||||
* write, and to stat() to lex.c, so this
|
||||
* module could be put in overlay region.
|
||||
* Moved impure data out into ytdata.c to
|
||||
* go to the root.
|
||||
*
|
||||
* 29-May-81 Bob Denny -- Define yysterm fwd. Remove from LEXLEX.H.
|
||||
* for RSX overlaying.
|
||||
* 19-Mar-82 Bob Denny -- New compiler and library. Typcasts needed.
|
||||
* Conditionally compile remote formats, not
|
||||
* supported in VAX C.
|
||||
* More 03-May-82 Bob Denny -- Final touches, remove unreferenced autos
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ytab.h"
|
||||
#ifdef vms
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
|
||||
extern char *yysterm[]; /* Hack forward definition */
|
||||
|
||||
#line 9 "lex.y"
|
||||
#include "lexlex.h"
|
||||
|
||||
/* char copr[] = "Copyright (c) 1978 Charles H. Forsyth";*/
|
||||
|
||||
struct des {
|
||||
struct nfa *d_start;
|
||||
struct nfa *d_final;
|
||||
};
|
||||
extern struct nlist { /* 01+ */
|
||||
struct nlist *nl_next;
|
||||
struct nfa *nl_base;
|
||||
struct nfa *nl_end;
|
||||
struct nfa *nl_start;
|
||||
struct nfa *nl_final;
|
||||
char *nl_name;
|
||||
} *nlist; /* 01- */
|
||||
extern int str_length;
|
||||
extern struct nfa *elem();
|
||||
extern struct des *newdp();
|
||||
extern struct nlist *lookup();
|
||||
#define yyclearin yychar = -1
|
||||
#define yyerrok yyerrflag = 0
|
||||
extern int yychar, yyerrflag;
|
||||
|
||||
#ifndef YYSTYPE
|
||||
#define YYSTYPE int
|
||||
#endif
|
||||
#ifndef YYVCOPY
|
||||
#define YYVCOPY(x,y) (x)=(y)
|
||||
#endif
|
||||
|
||||
extern YYSTYPE yyval; /* 01+ */
|
||||
extern YYSTYPE *yypv;
|
||||
extern YYSTYPE yylval;
|
||||
|
||||
|
||||
|
||||
extern int nlook;
|
||||
extern int yyline;
|
||||
extern char *breakc;
|
||||
extern char *ignore;
|
||||
extern char *illeg; /* 01- */
|
||||
|
||||
yyactr(__np__){
|
||||
|
||||
#line 40 "lex.y"
|
||||
struct nfa *np, *nbase;
|
||||
char *cp;
|
||||
struct des *dp;
|
||||
struct trans *tp;
|
||||
struct nlist *nl;
|
||||
int i, c;
|
||||
|
||||
switch(__np__){
|
||||
|
||||
case 7:
|
||||
#line 64 "lex.y"
|
||||
{
|
||||
dp = yypv[3];
|
||||
nl = yypv[1];
|
||||
np = nl->nl_base;
|
||||
nl->nl_start = dp->d_start;
|
||||
nl->nl_final = dp->d_final;
|
||||
nl->nl_end = nfap;
|
||||
#ifdef DEBUG
|
||||
fprintf(lexlog, "NFA (auxiliary definition) for %s\n",
|
||||
nl->nl_name);
|
||||
nfaprint(dp->d_start, nl->nl_base);
|
||||
#endif
|
||||
nbase = lalloc(i = nl->nl_end-nl->nl_base, sizeof(*nbase),
|
||||
"nfa storage");
|
||||
copynfa(nl, nbase, dp);
|
||||
nl->nl_start = dp->d_start;
|
||||
nl->nl_final = dp->d_final;
|
||||
nl->nl_end = nbase+i;
|
||||
nl->nl_base = nbase;
|
||||
nfap = np;
|
||||
spccl(nl->nl_name, "ignore", dp, &ignore);
|
||||
spccl(nl->nl_name, "break", dp, &breakc);
|
||||
spccl(nl->nl_name, "illegal", dp, &illeg);
|
||||
} break;
|
||||
case 8:
|
||||
#line 85 "lex.y"
|
||||
{ copycode(); } break;
|
||||
case 9:
|
||||
#line 89 "lex.y"
|
||||
{
|
||||
yyval = lookup(yypv[1]);
|
||||
((struct nlist *)yyval)->nl_base = nfap;
|
||||
if (((struct nlist *)yyval)->nl_start)
|
||||
#ifdef vms
|
||||
yyerror("redefined", ((struct nlist *)yyval)->nl_name);
|
||||
#else
|
||||
yyerror("%s redefined", ((struct nlist *)yyval)->nl_name);
|
||||
#endif
|
||||
} break;
|
||||
case 10:
|
||||
#line 98 "lex.y"
|
||||
{ yyval = lookup(yypv[1]); } break;
|
||||
case 11:
|
||||
#line 102 "lex.y"
|
||||
{
|
||||
np = elem(CCL, yypv[1]);
|
||||
yyval = newdp(np, np->n_succ[0] = elem(FIN));
|
||||
} break;
|
||||
case 12:
|
||||
#line 106 "lex.y"
|
||||
{
|
||||
cp = yypv[1];
|
||||
if (str_length == 0) {
|
||||
np = elem(EPSILON);
|
||||
yyval = newdp(np, np->n_succ[0] = elem(FIN));
|
||||
return;
|
||||
}
|
||||
yyval = np = elem(*cp++);
|
||||
while (--str_length > 0)
|
||||
np = np->n_succ[0] = elem(*cp++);
|
||||
yyval = newdp(yyval, np->n_succ[0] = elem(FIN));
|
||||
} break;
|
||||
case 13:
|
||||
#line 118 "lex.y"
|
||||
{
|
||||
if ((nl = yypv[1])->nl_end == 0) {
|
||||
#ifdef vms
|
||||
yyerror("not defined", nl->nl_name);
|
||||
#else
|
||||
yyerror("%s not defined", nl->nl_name);
|
||||
#endif
|
||||
nl->nl_base = nl->nl_end = elem(FIN);
|
||||
nl->nl_start = nl->nl_final = nl->nl_base;
|
||||
}
|
||||
yyval = dp = lalloc(1, sizeof(*dp), "dfa input");
|
||||
nbase = nfap;
|
||||
i = nl->nl_end-nl->nl_base;
|
||||
if ((nfap += i) >= &nfa[MAXNFA]) {
|
||||
yyerror("Out of NFA nodes", NULL);
|
||||
exit(1);
|
||||
}
|
||||
copynfa(nl, nbase, dp);
|
||||
} break;
|
||||
case 14:
|
||||
#line 133 "lex.y"
|
||||
{
|
||||
yyval = dp = yypv[1];
|
||||
dp->d_start = newnfa(EPSILON, np = dp->d_start, 0);
|
||||
dp->d_final->n_char = EPSILON;
|
||||
dp->d_final->n_succ[0] = np;
|
||||
dp->d_final->n_succ[1] = np = elem(FIN);
|
||||
dp->d_start->n_succ[1] = np;
|
||||
dp->d_final = np;
|
||||
} break;
|
||||
case 15:
|
||||
#line 142 "lex.y"
|
||||
{
|
||||
yyval = dp = yypv[1];
|
||||
dp->d_start = newnfa(EPSILON, dp->d_start,
|
||||
((struct des *)yypv[3])->d_start);
|
||||
dp->d_final->n_char = EPSILON;
|
||||
dp->d_final = dp->d_final->n_succ[0] = np = elem(FIN);
|
||||
dp = yypv[3];
|
||||
dp->d_final->n_char = EPSILON;
|
||||
dp->d_final->n_succ[0] = np;
|
||||
free(yypv[3]);
|
||||
} break;
|
||||
case 16:
|
||||
#line 152 "lex.y"
|
||||
{
|
||||
yyval = yypv[1];
|
||||
dp = yypv[2];
|
||||
np = ((struct des *)yyval)->d_final;
|
||||
((struct des *)yyval)->d_final = dp->d_final;
|
||||
np->n_char = dp->d_start->n_char;
|
||||
np->n_ccl = dp->d_start->n_ccl;
|
||||
np->n_succ[0] = dp->d_start->n_succ[0];
|
||||
np->n_succ[1] = dp->d_start->n_succ[1];
|
||||
free(yypv[2]);
|
||||
} break;
|
||||
case 17:
|
||||
#line 163 "lex.y"
|
||||
{ yyval = yypv[2]; } break;
|
||||
case 18:
|
||||
#line 167 "lex.y"
|
||||
{
|
||||
ending();
|
||||
trans1:
|
||||
#ifdef DEBUG
|
||||
fprintf(lexlog, "\nNFA for complete syntax\n");
|
||||
fprintf(lexlog, "state 0\n");
|
||||
for (tp = trans; tp < transp; tp++)
|
||||
fprintf(lexlog, "\tepsilon\t%d\n", tp->t_start-nfa);
|
||||
for (tp = trans; tp < transp; tp++)
|
||||
nfaprint(tp->t_start, nfa);
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
/* 01 */
|
||||
} break;
|
||||
case 19:
|
||||
#line 182 "lex.y"
|
||||
{ goto trans1; } break;
|
||||
case 22:
|
||||
#line 191 "lex.y"
|
||||
{
|
||||
llactr();
|
||||
} break;
|
||||
case 23:
|
||||
#line 197 "lex.y"
|
||||
{ dp = yypv[1]; newtrans(dp->d_start, dp->d_final); } break;
|
||||
case 24:
|
||||
#line 198 "lex.y"
|
||||
{ copycode(); } break;
|
||||
case 25:
|
||||
#line 199 "lex.y"
|
||||
{
|
||||
ending();
|
||||
while ((c = get()) != EOF)
|
||||
putc(c, llout);
|
||||
} break;
|
||||
case 26:
|
||||
#line 207 "lex.y"
|
||||
{ action(); } break;
|
||||
case 27:
|
||||
#line 211 "lex.y"
|
||||
{
|
||||
if (nlook >= NBPW)
|
||||
#ifdef vms
|
||||
yyerror("Too many translations with lookahead", NULL);
|
||||
#else
|
||||
yyerror("More than %d translations with lookahead",
|
||||
NBPW);
|
||||
#endif
|
||||
yyval = dp = yypv[1];
|
||||
np = dp->d_final;
|
||||
np->n_char = EPSILON;
|
||||
np->n_flag |= LOOK;
|
||||
np->n_succ[0] = ((struct des *)yypv[3])->d_start;
|
||||
dp->d_final = ((struct des *)yypv[3])->d_final;
|
||||
np->n_look = nlook;
|
||||
dp->d_final->n_look = nlook++;
|
||||
dp->d_final->n_flag |= FLOOK;
|
||||
free(yypv[3]);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
int yyerrval = 256;
|
||||
|
||||
#line 228 "lex.y"
|
||||
|
||||
/*
|
||||
* Lexical analyser
|
||||
* (it isn't done with lex...)
|
||||
*/
|
||||
extern char buffer[150]; /* 01 */
|
||||
extern int str_length; /* 01 */
|
||||
|
||||
yylex()
|
||||
{
|
||||
register c;
|
||||
register char *cp;
|
||||
int lno;
|
||||
|
||||
if (yyline == 0)
|
||||
yyline++;
|
||||
loop:
|
||||
c = get();
|
||||
if (isupper(c)) {
|
||||
name(c);
|
||||
for (cp = yylval; c = *cp; cp++)
|
||||
if (isupper(c))
|
||||
*cp = tolower(c);
|
||||
return(STRING);
|
||||
} else if (islower(c) || c == '_') {
|
||||
name(c);
|
||||
return(NAME);
|
||||
}
|
||||
switch (c) {
|
||||
case EOF:
|
||||
return(0);
|
||||
|
||||
case '[':
|
||||
return(cclass());
|
||||
|
||||
case '(':
|
||||
case ')':
|
||||
case '{':
|
||||
case '}':
|
||||
case '*':
|
||||
case '|':
|
||||
case '=':
|
||||
case ';':
|
||||
case '%':
|
||||
return(c);
|
||||
|
||||
case '/':
|
||||
if ((c = get()) != '*') {
|
||||
unget(c);
|
||||
return('/');
|
||||
}
|
||||
lno = yyline;
|
||||
for (; c != EOF; c = get())
|
||||
if (c == '*')
|
||||
if ((c = get()) == '/')
|
||||
goto loop; else
|
||||
unget(c);
|
||||
yyline = lno;
|
||||
yyerror("End of file in comment", NULL);
|
||||
|
||||
case '\'':
|
||||
case '"':
|
||||
yylval = buffer;
|
||||
string(c);
|
||||
return(STRING);
|
||||
|
||||
case '\n':
|
||||
case ' ':
|
||||
case '\t':
|
||||
goto loop;
|
||||
|
||||
default:
|
||||
yylval = buffer;
|
||||
buffer[0] = c;
|
||||
buffer[1] = 0;
|
||||
str_length = 1;
|
||||
return(STRING);
|
||||
}
|
||||
}
|
||||
|
||||
extern char ccl[(NCHARS+1)/NBPC]; /* 01 */
|
||||
|
||||
cclass()
|
||||
{
|
||||
register c, i, lc;
|
||||
int compl;
|
||||
|
||||
compl = 0;
|
||||
for (i = 0; i < sizeof ccl; i++)
|
||||
ccl[i] = 0;
|
||||
if ((c = get()) == '^')
|
||||
compl++; else
|
||||
unget(c);
|
||||
lc = -1;
|
||||
while ((c = mapc(']')) != EOF) {
|
||||
if (c == '-' && lc >= 0) {
|
||||
if ((c = mapc(']')) == EOF)
|
||||
break;
|
||||
for (i = lc; i <= c; i++)
|
||||
ccl[i/NBPC] |= 1<<(i%NBPC);
|
||||
lc = -1;
|
||||
continue;
|
||||
}
|
||||
ccl[c/NBPC] |= 1<<(c%NBPC);
|
||||
lc = c;
|
||||
}
|
||||
if (compl) {
|
||||
for (i = 0; i < sizeof ccl; i++)
|
||||
ccl[i] ^= -1;
|
||||
if (aflag == 0)
|
||||
for (i = 0200; i < (1<<NBPC); i++)
|
||||
ccl[i/NBPC] &= ~(1 << (i%NBPC));
|
||||
}
|
||||
yylval = newccl(ccl);
|
||||
return(CCLASS);
|
||||
}
|
||||
|
||||
string(ec)
|
||||
{
|
||||
register char *cp;
|
||||
register c;
|
||||
|
||||
for (cp = buffer; (c = mapc(ec)) != EOF;)
|
||||
*cp++ = c;
|
||||
*cp = 0;
|
||||
str_length = cp-buffer;
|
||||
}
|
||||
|
||||
mapc(ec)
|
||||
{
|
||||
register c, v, i;
|
||||
|
||||
if ((c = get()) == ec)
|
||||
return(EOF);
|
||||
switch(c) {
|
||||
case EOF:
|
||||
yyerror("End of file in string", NULL);
|
||||
return(c);
|
||||
|
||||
case '\\':
|
||||
if ((c = get()) >= '0' && c <= '7') {
|
||||
i = 0;
|
||||
for (v = 0; c>='0' && c<='7' && i++<3; c = get())
|
||||
v = v*010 + c-'0';
|
||||
unget(c);
|
||||
return(v&0377);
|
||||
}
|
||||
switch (c) {
|
||||
case 'n':
|
||||
return('\n');
|
||||
|
||||
case 't':
|
||||
return('\t');
|
||||
|
||||
case 'b':
|
||||
return('\b');
|
||||
|
||||
case 'r':
|
||||
return('\r');
|
||||
|
||||
case '\n':
|
||||
yyline++;
|
||||
return(mapc(ec));
|
||||
}
|
||||
|
||||
default:
|
||||
return(c);
|
||||
}
|
||||
}
|
||||
|
||||
name(c)
|
||||
register c;
|
||||
{
|
||||
register char *cp;
|
||||
|
||||
for (yylval=cp=buffer; isalpha(c) || isdigit(c) || c=='_'; c=get())
|
||||
*cp++ = c;
|
||||
*cp = 0;
|
||||
str_length = cp-buffer;
|
||||
unget(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Miscellaneous functions
|
||||
* used only by lex.y
|
||||
*/
|
||||
struct nfa *
|
||||
elem(k, v)
|
||||
{
|
||||
struct nfa *fp;
|
||||
|
||||
fp = newnfa(k, 0, 0);
|
||||
if (k == CCL)
|
||||
fp->n_ccl = v;
|
||||
return(fp);
|
||||
}
|
||||
|
||||
struct des *
|
||||
newdp(st, fi)
|
||||
struct nfa *st, *fi;
|
||||
{
|
||||
register struct des *dp;
|
||||
|
||||
dp = lalloc(1, sizeof(*dp), "dfa input");
|
||||
dp->d_start = st;
|
||||
dp->d_final = fi;
|
||||
return(dp);
|
||||
}
|
||||
|
||||
action()
|
||||
{
|
||||
register c;
|
||||
int lno, lev;
|
||||
|
||||
newcase(transp-trans);
|
||||
lno = yyline;
|
||||
lev = 0;
|
||||
for (; (c = get()) != EOF && (c != '}' || lev); putc(c, llout))
|
||||
if (c == '{')
|
||||
lev++;
|
||||
else if (c == '}')
|
||||
lev--;
|
||||
else if (c == '\'' || c == '"') {
|
||||
putc(c, llout);
|
||||
skipstr(c);
|
||||
}
|
||||
fprintf(llout, "\n break;\n");
|
||||
if (c == EOF) {
|
||||
yyline = lno;
|
||||
yyerror("End of file in action", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
skipstr(ec)
|
||||
register ec;
|
||||
{
|
||||
register c;
|
||||
|
||||
while ((c = get()) != ec && c != EOF) {
|
||||
putc(c, llout);
|
||||
if (c == '\\' && (c = get()) != EOF)
|
||||
putc(c, llout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
copycode()
|
||||
{
|
||||
int lno;
|
||||
register c;
|
||||
|
||||
setline();
|
||||
lno = yyline;
|
||||
for (; (c = get()) != EOF; putc(c, llout))
|
||||
if (c == '%') {
|
||||
if ((c = get()) == '}')
|
||||
return;
|
||||
unget(c);
|
||||
c = '%';
|
||||
}
|
||||
yyline = lno;
|
||||
yyerror("Incomplete %{ declaration", NULL);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct nlist *
|
||||
lookup(s)
|
||||
register char *s;
|
||||
{
|
||||
register struct nlist *nl;
|
||||
register char *cp;
|
||||
int i;
|
||||
for (nl = nlist; nl; nl = nl->nl_next)
|
||||
if (streq(s, nl->nl_name))
|
||||
return(nl);
|
||||
nl = lalloc(1, sizeof(*nl), "namelist");
|
||||
nl->nl_start = nl->nl_end = nl->nl_base = nl->nl_end = 0;
|
||||
nl->nl_next = nlist;
|
||||
nlist = nl;
|
||||
i = 0;
|
||||
nl->nl_name = cp = lalloc(strlen(s) + 1, sizeof(*cp), "namelist");
|
||||
strcpy(cp, s);
|
||||
return(nl);
|
||||
}
|
||||
|
||||
|
||||
copynfa(nl, nbase, dp)
|
||||
struct nlist *nl;
|
||||
struct des *dp;
|
||||
struct nfa *nbase;
|
||||
{
|
||||
register struct nfa *np, *ob;
|
||||
register j;
|
||||
int i;
|
||||
|
||||
ob = nl->nl_base;
|
||||
i = nl->nl_end-ob;
|
||||
/*
|
||||
* Assumes Decus compiler: copy(out, in, nbytes)
|
||||
*/
|
||||
copy(nbase, ob, sizeof(*np) * i);
|
||||
for (np = nbase; i-- > 0; np++) {
|
||||
np->n_flag &= ~NPRT;
|
||||
for (j = 0; j < 2; j++)
|
||||
if (np->n_succ[j])
|
||||
np->n_succ[j] = (np->n_succ[j]-ob)+nbase;
|
||||
}
|
||||
dp->d_start = (nl->nl_start-ob)+nbase;
|
||||
dp->d_final = (nl->nl_final-ob)+nbase;
|
||||
}
|
||||
|
||||
#ifdef vms
|
||||
copy(out, in, count)
|
||||
register char *out;
|
||||
register char *in;
|
||||
register int count;
|
||||
/*
|
||||
* Block copy for vms -- should be in stdio.lib (in macro)
|
||||
*/
|
||||
{
|
||||
while (--count >= 0)
|
||||
*out++ = *in++;
|
||||
}
|
||||
#endif
|
||||
|
||||
spccl(nm, isit, dp, where)
|
||||
char *nm;
|
||||
char *isit;
|
||||
register struct des *dp;
|
||||
char **where;
|
||||
{
|
||||
|
||||
if (streq(nm, isit)) {
|
||||
if (*where != 0)
|
||||
#ifdef vms
|
||||
yyerror("Redefinition of class", isit);
|
||||
#else
|
||||
yyerror("Redefinition of %s class", isit);
|
||||
#endif
|
||||
if (dp->d_start->n_char == CCL &&
|
||||
dp->d_start->n_succ[0] == dp->d_final)
|
||||
*where = dp->d_start->n_ccl;
|
||||
else
|
||||
#ifdef vms
|
||||
yyerror("Illegal class", isit);
|
||||
#else
|
||||
yyerror("Illegal %s class", isit);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
get()
|
||||
{
|
||||
register int c;
|
||||
|
||||
if ((c = getc(lexin)) == '\n')
|
||||
yyline++;
|
||||
return(c);
|
||||
}
|
||||
|
||||
unget(c)
|
||||
register c;
|
||||
{
|
||||
if (c == '\n')
|
||||
yyline--;
|
||||
ungetc(c, lexin);
|
||||
}
|
||||
|
||||
#ifdef vms
|
||||
yyerror(s, arg)
|
||||
char *s;
|
||||
char *arg;
|
||||
{
|
||||
if (yyline)
|
||||
fprintf(stderr, "%d: ", yyline);
|
||||
fprintf(stderr, "%s", s);
|
||||
if(arg != NULL)
|
||||
fprintf(stderr, ": \"%s\"", arg);
|
||||
#else
|
||||
yyerror(s)
|
||||
char *s;
|
||||
{
|
||||
if (yyline)
|
||||
fprintf(stderr, "%d: ", yyline);
|
||||
fprintf(stderr, "%r", &s);
|
||||
#endif
|
||||
if (yychar > 256)
|
||||
fprintf(stderr, " near '%s'", yysterm[yychar-256]);
|
||||
else if (yychar < 256 && yychar > 0)
|
||||
fprintf(stderr, " near '%c'", yychar);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int nterms = 15;
|
||||
int nnonter = 13;
|
||||
int nstate = 41;
|
||||
char *yysterm[] = {
|
||||
"error",
|
||||
"NAME",
|
||||
"CCLASS",
|
||||
"STRING",
|
||||
"CONCAT",
|
||||
0 };
|
||||
|
||||
char *yysnter[] = {
|
||||
"$accept",
|
||||
"lexfile",
|
||||
"auxiliary_section",
|
||||
"translation_section",
|
||||
"auxiliaries",
|
||||
"auxiliary",
|
||||
"namedef",
|
||||
"regexp",
|
||||
"name",
|
||||
"translations",
|
||||
"translation",
|
||||
"llactr",
|
||||
"pattern",
|
||||
"action" };
|
||||
#
|
||||
extern int yychar;
|
||||
|
||||
int yylast = 245;
|
||||
yyexcp(s){
|
||||
extern int yydef[];
|
||||
switch(s){
|
||||
case 1:
|
||||
if( yychar == 0 ) return( -1 );
|
||||
return( 0 );
|
||||
case 2:
|
||||
if( yychar == 0 ) return( 19 );
|
||||
return( 22 );
|
||||
}
|
||||
}
|
||||
|
||||
yyact[] = {
|
||||
|
||||
23, 40, 32, 23, 29, 32, 23, 15, 32, 23,
|
||||
31, 32, 23, 35, 32, 18, 26, 13, 23, 32,
|
||||
34, 23, 37, 11, 4, 5, 16, 28, 17, 12,
|
||||
19, 19, 10, 9, 22, 6, 27, 25, 3, 8,
|
||||
2, 1, 0, 0, 36, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 38, 0, 39, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 33, 0, 0, 33, 0, 0,
|
||||
33, 0, 0, 33, 0, 0, 30, 0, 0, 0,
|
||||
0, 0, 14, 14, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 24, 20, 21,
|
||||
24, 20, 21, 24, 20, 21, 24, 20, 21, 24,
|
||||
20, 21, 0, 0, 0, 24, 20, 21, 24, 20,
|
||||
21, 0, 0, 7, 7 };
|
||||
yypact[] = {
|
||||
|
||||
-13,-2000,-2000, -14, -20,-1000, -54,-1000,-1000, -22,
|
||||
-22, -21,-1000,-1000,-1000, -19,-1000,-119, -27, -34,
|
||||
-1000,-1000,-1000, -19,-1000,-1000,-1000, -37,-1000,-1000,
|
||||
-1000,-1000,-1000, -19, -23, -19, -40,-1000, -28, -31,
|
||||
-1000 };
|
||||
yypgo[] = {
|
||||
|
||||
0, 41, 40, 39, 38, 25, 35, 20, 34, 33,
|
||||
26, 32, 28, 27 };
|
||||
yyr1[] = {
|
||||
|
||||
0, 1, 1, 2, 2, 4, 4, 5, 5, 6,
|
||||
8, 7, 7, 7, 7, 7, 7, 7, 3, 3,
|
||||
9, 9, 11, 10, 10, 10, 13, 12, 12, -1 };
|
||||
yyr2[] = {
|
||||
|
||||
0, 2, 0, 3, 2, 2, 1, 4, 2, 1,
|
||||
1, 1, 1, 1, 2, 3, 2, 3, 1, 0,
|
||||
2, 2, 0, 2, 2, 2, 1, 3, 1, -1 };
|
||||
yychk[] = {
|
||||
|
||||
0, -1, -2, -4, 37, -5, -6, 257, -3, -9,
|
||||
-11, 37, -5, 37, 123, 61, -10, -12, 37, -7,
|
||||
258, 259, -8, 40, 257, -10, 37, -7, -13, 123,
|
||||
123, 37, 42, 124, -7, 47, -7, 59, -7, -7,
|
||||
41 };
|
||||
yydef[] = {
|
||||
|
||||
2, -2, -2, 0, 0, 6, 0, 9, 1, 18,
|
||||
0, 0, 5, 4, 8, 0, 20, 0, 0, 28,
|
||||
11, 12, 13, 0, 10, 21, 3, 0, 23, 26,
|
||||
24, 25, 14, 0, 16, 0, 0, 7, 15, 27,
|
||||
17 };
|
||||
|
||||
# define YYFLAG1 -1000
|
||||
# define YYFLAG2 -2000
|
||||
|
||||
/* test me on cases where there are more than one reduction
|
||||
per state, leading to the necessity to look ahead, and other
|
||||
arcane flows of control.
|
||||
*/
|
||||
# define YYMAXDEPTH 150
|
||||
|
||||
/* parser for yacc output */
|
||||
/* extern YYSTYPE yyval; -- defined in the table file
|
||||
* extern YYSTYPE yylval; -- defined in the table file
|
||||
* extern YYSTYPE *yypv; -- defined in the table file
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
#define LOGOUT lexlog
|
||||
#endif
|
||||
|
||||
extern int yydebug; /* 1 for debugging */ /* 01+ */
|
||||
|
||||
extern YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
|
||||
extern int yychar; /* current input token number */
|
||||
extern int yynerrs ; /* number of errors */
|
||||
extern int yyerrflag ; /* error recovery flag */ /* 01- */
|
||||
|
||||
|
||||
yyparse() {
|
||||
|
||||
/* extern int yypgo[], yyr1[], yyr2[], yyact[], yypact[];
|
||||
* extern int yydef[], yychk[];
|
||||
* extern int yylast, yyerrval;
|
||||
*/
|
||||
int yys[YYMAXDEPTH];
|
||||
int yyj;
|
||||
register yyn, yystate, *yyps;
|
||||
|
||||
yystate = 0;
|
||||
yychar = -1;
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yyps= &yys[0]-1;
|
||||
yypv= &yyv[0]-1;
|
||||
|
||||
yystack: /* put a state and value onto the stack */
|
||||
|
||||
#ifdef DEBUG
|
||||
if( yydebug )
|
||||
fprintf(LOGOUT, "state %d, value %d, char %d\n",yystate,yyval,yychar);
|
||||
#endif
|
||||
|
||||
*++yyps = yystate;
|
||||
*++yypv = yyval;
|
||||
|
||||
yynewstate:
|
||||
|
||||
yyn = yypact[yystate];
|
||||
|
||||
if( yyn<= YYFLAG1 ){ /* simple state */
|
||||
if( yyn == YYFLAG2 && yychar<0 ) yychar = yylex();
|
||||
goto yydefault;
|
||||
}
|
||||
|
||||
if( yychar<0 ) yychar = yylex();
|
||||
if( (yyn += yychar)<0 || yyn >= yylast ) goto yydefault;
|
||||
|
||||
if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
|
||||
yychar = -1;
|
||||
yyval = yylval;
|
||||
yystate = yyn;
|
||||
if( yyerrflag > 0 ) --yyerrflag;
|
||||
goto yystack;
|
||||
}
|
||||
|
||||
yydefault:
|
||||
/* default state action */
|
||||
|
||||
if( (yyn=yydef[yystate]) == -2 ) yyn = yyexcp( yystate );
|
||||
|
||||
if( yyn == -1 ){ /* accept */
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
if( yyn == 0 ){ /* error */
|
||||
/* error ... attempt to resume parsing */
|
||||
|
||||
switch( yyerrflag ){
|
||||
|
||||
case 0: /* brand new error */
|
||||
|
||||
++yynerrs;
|
||||
yyerror("syntax error", NULL);
|
||||
|
||||
case 1:
|
||||
case 2: /* incompletely recovered error ... try again */
|
||||
|
||||
yyerrflag = 3;
|
||||
|
||||
/* find a state where "error" is a legal shift action */
|
||||
|
||||
while ( yyps >= yys ) {
|
||||
yyn = yypact[*yyps] + yyerrval;
|
||||
if( yyn>= 0 && yyn < yylast && yychk[yyact[yyn]] == yyerrval ){
|
||||
yystate = yyact[yyn]; /* simulate a shift of "error" */
|
||||
goto yystack;
|
||||
}
|
||||
yyn = yypact[*yyps];
|
||||
|
||||
/* the current yyps has no shift onn "error", pop stack */
|
||||
|
||||
#ifdef DEBUG
|
||||
if(yydebug)
|
||||
fprintf(LOGOUT, "error recovery pops state %d, uncovers %d\n",
|
||||
*yyps, yyps[-1]);
|
||||
#endif
|
||||
|
||||
--yyps;
|
||||
--yypv;
|
||||
}
|
||||
|
||||
/* there is no state on the stack with an error shift ... abort */
|
||||
|
||||
abort:
|
||||
return(1);
|
||||
|
||||
|
||||
case 3: /* no shift yet; clobber input char */
|
||||
|
||||
#ifdef DEBUG
|
||||
if (yydebug)
|
||||
fprintf(LOGOUT, "error recovery discards char %d\n", yychar );
|
||||
#endif
|
||||
|
||||
if( yychar == 0 ) goto abort; /* don't discard EOF, quit */
|
||||
yychar = -1;
|
||||
goto yynewstate; /* try again in the same state */
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* reduction by production yyn */
|
||||
|
||||
#ifdef DEBUG
|
||||
if(yydebug) fprintf(LOGOUT, "reduce %d\n",yyn);
|
||||
#endif
|
||||
|
||||
yyps -= yyr2[yyn];
|
||||
yypv -= yyr2[yyn];
|
||||
/* YYVCOPY(yyval,yypv[1]);
|
||||
*/ yyval = yypv[1];
|
||||
yyactr(yyn);
|
||||
/* consult goto table to find next state */
|
||||
yyn = yyr1[yyn];
|
||||
yyj = yypgo[yyn] + *yyps + 1;
|
||||
if( yyj>=yylast || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
|
||||
goto yystack; /* stack new state and value */
|
||||
|
||||
}
|
||||
174
c20/lex/yylex.c
Normal file
174
c20/lex/yylex.c
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* yylex for lex tables
|
||||
*/
|
||||
|
||||
/*
|
||||
* Bob Denny 28-Aug-82 Remove reference to stdio.h
|
||||
* Remove code to default lexin, change to call to
|
||||
* llstin(), generated by lex depending upon setting
|
||||
* of "-s" switch. Eliminates hardwired dependency
|
||||
* on standard I/O library. Moved declaration of
|
||||
* lexin to lexgetc().
|
||||
*
|
||||
* Bob Denny 31-Aug-82 Add call to lexswitch() in
|
||||
* the generated file, to switch to the table whose
|
||||
* name was given in the "-t" switch (or to "lextab"
|
||||
* if "-t" wasn't given). Removed hardwired setting
|
||||
* of _tabp --> "lextab" here. Now handled automagically.
|
||||
*
|
||||
* Bob Denny 21-Oct-82 Add llinit() function to re-initialize
|
||||
* yylex(), making it serially reusable.
|
||||
*
|
||||
* Initialize _tabp to NULL so lexswitch() to real table happens
|
||||
* only once.
|
||||
*/
|
||||
|
||||
#include <stdio.h> /* PLB */
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
#define ERROR 256 /* yacc's value */
|
||||
|
||||
#define NBPW 16 /* bits per word */
|
||||
|
||||
tst__b(c, tab)
|
||||
register int c;
|
||||
char tab[];
|
||||
{
|
||||
return(tab[(c >> 3) & 037] & (1 << (c & 07)) );
|
||||
}
|
||||
|
||||
struct lextab *_tabp = 0;
|
||||
|
||||
extern char *llsave[]; /* Right-context buffer */
|
||||
char llbuf[100]; /* work buffer */
|
||||
char *llp1 = &llbuf[0]; /* pointer to next avail. in token */
|
||||
char *llp2 = &llbuf[0]; /* pointer to end of lookahead */
|
||||
char *llend = &llbuf[0]; /* pointer to end of token */
|
||||
char *llebuf = &llbuf[sizeof llbuf];
|
||||
int lleof;
|
||||
int yylval = 0;
|
||||
int yyline = 0;
|
||||
|
||||
yylex()
|
||||
{
|
||||
register c, st;
|
||||
int final, l, llk, i;
|
||||
register struct lextab *lp;
|
||||
char *cp;
|
||||
|
||||
/*
|
||||
* Call llstin() to default lexin to stdin
|
||||
* and assign _tabp to "real" table.
|
||||
*/
|
||||
llstin(); /* Initialize yylex() variables */
|
||||
loop:
|
||||
llk = 0;
|
||||
if (llset())
|
||||
return(0); /* Prevent EOF loop */
|
||||
st = 0;
|
||||
final = -1;
|
||||
lp = _tabp;
|
||||
|
||||
do {
|
||||
if (lp->lllook && (l = lp->lllook[st])) {
|
||||
for (c=0; c<NBPW; c++)
|
||||
if (l&(1<<c))
|
||||
llsave[c] = llp1;
|
||||
llk++;
|
||||
}
|
||||
if ((i = lp->llfinal[st]) != -1) {
|
||||
final = i;
|
||||
llend = llp1;
|
||||
}
|
||||
if ((c = llinp()) < 0)
|
||||
break;
|
||||
if ((cp = lp->llbrk) && llk==0 && tst__b(c, cp)) {
|
||||
llp1--;
|
||||
break;
|
||||
}
|
||||
} while ((st = (*lp->llmove)(lp, c, st)) != -1);
|
||||
|
||||
|
||||
if (llp2 < llp1)
|
||||
llp2 = llp1;
|
||||
if (final == -1) {
|
||||
llend = llp1;
|
||||
if (st == 0 && c < 0)
|
||||
return(0);
|
||||
if ((cp = lp->llill) && tst__b(c, cp)) {
|
||||
lexerror("Illegal (out of range) input character");
|
||||
/*
|
||||
lexerror("Illegal character: %c (%03o)", c, c);
|
||||
*/
|
||||
goto loop;
|
||||
}
|
||||
return(ERROR);
|
||||
}
|
||||
if (c = (final >> 11) & 037)
|
||||
llend = llsave[c-1];
|
||||
if ((c = (*lp->llactr)(final&03777)) >= 0)
|
||||
return(c);
|
||||
goto loop;
|
||||
}
|
||||
|
||||
llinp()
|
||||
{
|
||||
register c;
|
||||
register struct lextab *lp;
|
||||
register char *cp;
|
||||
|
||||
lp = _tabp;
|
||||
cp = lp->llign; /* Ignore class */
|
||||
for (;;) {
|
||||
/*
|
||||
* Get the next character from the save buffer (if possible)
|
||||
* If the save buffer's empty, then return EOF or the next
|
||||
* input character. Ignore the character if it's in the
|
||||
* ignore class.
|
||||
*/
|
||||
c = (llp1 < llp2) ? *llp1 & 0377 : (lleof) ? EOF : lexgetc();
|
||||
if (c >= 0) { /* Got a character? */
|
||||
if (cp && tst__b(c, cp))
|
||||
continue; /* Ignore it */
|
||||
if (llp1 >= llebuf) { /* No, is there room? */
|
||||
lexerror("Token buffer overflow");
|
||||
exit(1);
|
||||
}
|
||||
*llp1++ = c; /* Store in token buff */
|
||||
} else
|
||||
lleof = 1; /* Set EOF signal */
|
||||
return(c);
|
||||
}
|
||||
}
|
||||
|
||||
llset()
|
||||
/*
|
||||
* Return TRUE if EOF and nothing was moved in the look-ahead buffer
|
||||
*/
|
||||
{
|
||||
register char *lp1, *lp2;
|
||||
|
||||
for (lp1 = llbuf, lp2 = llend; lp2 < llp2;)
|
||||
*lp1++ = *lp2++;
|
||||
llend = llp1 = llbuf;
|
||||
llp2 = lp1;
|
||||
return(lleof && lp1 == llbuf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Re-initialize yylex() so that it can be re-used on
|
||||
* another file.
|
||||
*/
|
||||
llinit()
|
||||
{
|
||||
llp1 = llp2 = llend = llbuf;
|
||||
llebuf = llbuf + sizeof(llbuf);
|
||||
lleof = yylval = yyline = 0;
|
||||
}
|
||||
176
c20/lex/yylex.c-2
Normal file
176
c20/lex/yylex.c-2
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* yylex for lex tables
|
||||
*/
|
||||
|
||||
/*
|
||||
* Bob Denny 28-Aug-82 Remove reference to stdio.h
|
||||
* Remove code to default lexin, change to call to
|
||||
* llstin(), generated by lex depending upon setting
|
||||
* of "-s" switch. Eliminates hardwired dependency
|
||||
* on standard I/O library. Moved declaration of
|
||||
* lexin to lexgetc().
|
||||
*
|
||||
* Bob Denny 31-Aug-82 Add call to lexswitch() in
|
||||
* the generated file, to switch to the table whose
|
||||
* name was given in the "-t" switch (or to "lextab"
|
||||
* if "-t" wasn't given). Removed hardwired setting
|
||||
* of _tabp --> "lextab" here. Now handled automagically.
|
||||
*
|
||||
* Bob Denny 21-Oct-82 Add llinit() function to re-initialize
|
||||
* yylex(), making it serially reusable.
|
||||
*
|
||||
* Initialize _tabp to NULL so lexswitch() to real table happens
|
||||
* only once.
|
||||
*/
|
||||
|
||||
#include <stdio.h> /* PLB */
|
||||
#ifdef vms
|
||||
#include "c:lex.h"
|
||||
#else
|
||||
#include <lex.h>
|
||||
#endif
|
||||
|
||||
/*)LIBRARY
|
||||
*/
|
||||
|
||||
#define ERROR 256 /* yacc's value */
|
||||
|
||||
#define NBPW 16 /* bits per word */
|
||||
|
||||
tst__b(c, tab)
|
||||
register int c;
|
||||
char tab[];
|
||||
{
|
||||
return(tab[(c >> 3) & 037] & (1 << (c & 07)) );
|
||||
}
|
||||
|
||||
struct lextab *_tabp = 0;
|
||||
|
||||
extern char *llsave[]; /* Right-context buffer */
|
||||
char llbuf[100]; /* work buffer */
|
||||
char *llp1 = &llbuf[0]; /* pointer to next avail. in token */
|
||||
char *llp2 = &llbuf[0]; /* pointer to end of lookahead */
|
||||
char *llend = &llbuf[0]; /* pointer to end of token */
|
||||
char *llebuf = &llbuf[sizeof llbuf];
|
||||
int lleof;
|
||||
int yylval = 0;
|
||||
int yyline = 0;
|
||||
|
||||
yylex()
|
||||
{
|
||||
register c, st;
|
||||
int final, l, llk, i;
|
||||
register struct lextab *lp;
|
||||
char *cp;
|
||||
|
||||
/*
|
||||
* Call llstin() to default lexin to stdin
|
||||
* and assign _tabp to "real" table.
|
||||
*/
|
||||
llstin(); /* Initialize yylex() variables */
|
||||
|
||||
loop:
|
||||
llk = 0;
|
||||
if (llset())
|
||||
return(0); /* Prevent EOF loop */
|
||||
st = 0;
|
||||
final = -1;
|
||||
lp = _tabp;
|
||||
|
||||
do {
|
||||
if (lp->lllook && (l = lp->lllook[st])) {
|
||||
for (c=0; c<NBPW; c++)
|
||||
if (l&(1<<c))
|
||||
llsave[c] = llp1;
|
||||
llk++;
|
||||
}
|
||||
if ((i = lp->llfinal[st]) != -1) {
|
||||
final = i;
|
||||
llend = llp1;
|
||||
}
|
||||
if ((c = llinp()) < 0)
|
||||
break;
|
||||
if ((cp = lp->llbrk) && llk==0 && tst__b(c, cp)) {
|
||||
llp1--;
|
||||
break;
|
||||
}
|
||||
} while ((st = (*lp->llmove)(lp, c, st)) != -1);
|
||||
|
||||
|
||||
if (llp2 < llp1)
|
||||
llp2 = llp1;
|
||||
if (final == -1) {
|
||||
llend = llp1;
|
||||
if (st == 0 && c < 0)
|
||||
return(0);
|
||||
if ((cp = lp->llill) && tst__b(c, cp)) {
|
||||
#ifdef vms
|
||||
lexerror("Illegal (out of range) input character");
|
||||
#else
|
||||
lexerror("Illegal character: %c (%03o)", c, c);
|
||||
#endif
|
||||
goto loop;
|
||||
}
|
||||
return(ERROR);
|
||||
}
|
||||
if (c = (final >> 11) & 037)
|
||||
llend = llsave[c-1];
|
||||
if ((c = (*lp->llactr)(final&03777)) >= 0)
|
||||
return(c);
|
||||
goto loop;
|
||||
}
|
||||
|
||||
llinp()
|
||||
{
|
||||
register c;
|
||||
register struct lextab *lp;
|
||||
register char *cp;
|
||||
|
||||
lp = _tabp;
|
||||
cp = lp->llign; /* Ignore class */
|
||||
for (;;) {
|
||||
/*
|
||||
* Get the next character from the save buffer (if possible)
|
||||
* If the save buffer's empty, then return EOF or the next
|
||||
* input character. Ignore the character if it's in the
|
||||
* ignore class.
|
||||
*/
|
||||
c = (llp1 < llp2) ? *llp1 & 0377 : (lleof) ? EOF : lexgetc();
|
||||
if (c >= 0) { /* Got a character? */
|
||||
if (cp && tst__b(c, cp))
|
||||
continue; /* Ignore it */
|
||||
if (llp1 >= llebuf) { /* No, is there room? */
|
||||
lexerror("Token buffer overflow");
|
||||
exit(1);
|
||||
}
|
||||
*llp1++ = c; /* Store in token buff */
|
||||
} else
|
||||
lleof = 1; /* Set EOF signal */
|
||||
return(c);
|
||||
}
|
||||
}
|
||||
|
||||
llset()
|
||||
/*
|
||||
* Return TRUE if EOF and nothing was moved in the look-ahead buffer
|
||||
*/
|
||||
{
|
||||
register char *lp1, *lp2;
|
||||
|
||||
for (lp1 = llbuf, lp2 = llend; lp2 < llp2;)
|
||||
*lp1++ = *lp2++;
|
||||
llend = llp1 = llbuf;
|
||||
llp2 = lp1;
|
||||
return(lleof && lp1 == llbuf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Re-initialize yylex() so that it can be re-used on
|
||||
* another file.
|
||||
*/
|
||||
llinit()
|
||||
{
|
||||
llp1 = llp2 = llend = llbuf;
|
||||
llebuf = llbuf + sizeof(llbuf);
|
||||
lleof = yylval = yyline = 0;
|
||||
}
|
||||
0
c20/minsrt.mid
Normal file
0
c20/minsrt.mid
Normal file
BIN
c20/mulseg.mid
Normal file
BIN
c20/mulseg.mid
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user