Move exclusively to bison as parser generator.

This commit is contained in:
Arnold D. Robbins 2020-07-30 17:12:45 +03:00
parent 453ce8642b
commit 07f0438423
11 changed files with 35 additions and 39 deletions

2
.gitignore vendored
View File

@ -1,6 +1,4 @@
a.out
maketab
proctab.c
ytab.c
ytab.h
*.o

View File

@ -1,3 +1,15 @@
2020-07-30 Arnold D. Robbins <arnold@skeeve.com>
By fiat, we use bison for $(YACC). Trying to accommodate
different versions didn't work.
* makefile: Significant cleanup. Replace all ytab* references
with awkgram.tab.* and simplify definition of YACC.
* .gitignore: Remove ytab* references.
* b.c, lex.c, maketab.c, parse.c, run.c: Replace include of ytab.h
with awkgram.tab.h.
* lib.c, main.c, tran.c: Remove include of ytab.h, wasn't needed.
2020-01-20 Arnold D. Robbins <arnold@skeeve.com>
* run.c (openfile): Set the close-on-exec flag for file

2
b.c
View File

@ -32,7 +32,7 @@ THIS SOFTWARE.
#include <string.h>
#include <stdlib.h>
#include "awk.h"
#include "ytab.h"
#include "awkgram.tab.h"
#define MAXLIN 22

2
lex.c
View File

@ -27,7 +27,7 @@ THIS SOFTWARE.
#include <string.h>
#include <ctype.h>
#include "awk.h"
#include "ytab.h"
#include "awkgram.tab.h"
extern YYSTYPE yylval;
extern bool infunc;

1
lib.c
View File

@ -31,7 +31,6 @@ THIS SOFTWARE.
#include <stdarg.h>
#include <limits.h>
#include "awk.h"
#include "ytab.h"
char EMPTY[] = { '\0' };
FILE *infile = NULL;

1
main.c
View File

@ -32,7 +32,6 @@ const char *version = "version 20200702";
#include <string.h>
#include <signal.h>
#include "awk.h"
#include "ytab.h"
extern char **environ;
extern int nfields;

View File

@ -34,54 +34,43 @@ CFLAGS = -O2
HOSTCC = gcc -g -Wall -pedantic -Wcast-qual
CC = $(HOSTCC) # change this is cross-compiling.
# yacc options. pick one; this varies a lot by system.
#YFLAGS = -d -S
# By fiat, to make our lives easier, yacc is now defined to be bison.
# If you want something else, you're on your own.
YACC = bison -d
#YACC = yacc -d
# -S uses sprintf in yacc parser instead of sprint
OFILES = b.o main.o parse.o proctab.o tran.o lib.o run.o lex.o
SOURCE = awk.h ytab.c ytab.h proto.h awkgram.y lex.c b.c main.c \
SOURCE = awk.h awkgram.tab.c awkgram.tab.h proto.h awkgram.y lex.c b.c main.c \
maketab.c parse.c lib.c run.c tran.c proctab.c
LISTING = awk.h proto.h awkgram.y lex.c b.c main.c maketab.c parse.c \
lib.c run.c tran.c
SHIP = README LICENSE FIXES $(SOURCE) ytab[ch].bak makefile \
SHIP = README LICENSE FIXES $(SOURCE) awkgram.tab.[ch].bak makefile \
awk.1
a.out: ytab.o $(OFILES)
$(CC) $(CFLAGS) ytab.o $(OFILES) $(ALLOC) -lm
a.out: awkgram.tab.o $(OFILES)
$(CC) $(CFLAGS) awkgram.tab.o $(OFILES) $(ALLOC) -lm
$(OFILES): awk.h ytab.h proto.h
$(OFILES): awk.h awkgram.tab.h proto.h
# Clear dependency for parallel build: (make -j)
# Depending if we used yacc or bison we can be generating different names
# ({awkgram,y}.tab.{c,h}) so try to move both. We could be using -p to
# specify the output prefix, but older yacc's don't support it.
ytab.c ytab.h: awk.h proto.h awkgram.y
awkgram.tab.c awkgram.tab.h: awk.h proto.h awkgram.y
$(YACC) $(YFLAGS) awkgram.y
-@for i in c h; do for j in awkgram y; do \
if [ -f "$$j.tab.$$i" ]; then mv $$j.tab.$$i ytab.$$i; fi; \
done; done
ytab.h: ytab.c
proctab.c: maketab
./maketab ytab.h >proctab.c
./maketab awkgram.tab.h >proctab.c
maketab: ytab.h maketab.c
maketab: awkgram.tab.h maketab.c
$(HOSTCC) $(CFLAGS) maketab.c -o maketab
bundle:
@cp ytab.h ytabh.bak
@cp ytab.c ytabc.bak
@cp awkgram.tab.h awkgram.tab.h.bak
@cp awkgram.tab.c awkgram.tab.c.bak
@bundle $(SHIP)
tar:
@cp ytab.h ytabh.bak
@cp ytab.c ytabc.bak
@cp awkgram.tab.h awkgram.tab.h.bak
@cp awkgram.tab.c awkgram.tab.c.bak
@bundle $(SHIP) >awk.shar
@tar cf awk.tar $(SHIP)
gzip awk.tar
@ -110,7 +99,7 @@ clean: testclean
rm -f a.out *.o *.obj maketab maketab.exe *.bb *.bbg *.da *.gcov *.gcno *.gcda # proctab.c
cleaner: testclean
rm -f a.out *.o *.obj maketab maketab.exe *.bb *.bbg *.da *.gcov *.gcno *.gcda proctab.c ytab*
rm -f a.out *.o *.obj maketab maketab.exe *.bb *.bbg *.da *.gcov *.gcno *.gcda proctab.c awkgram.tab.*
# This is a bit of a band-aid until we can invest some more time
# in the test suite.
@ -119,4 +108,4 @@ testclean:
glop glop1 glop2 lilly.diff tempbig tempsmall time
# For the habits of GNU maintainers:
distclean: clean
distclean: cleaner

View File

@ -25,14 +25,14 @@ THIS SOFTWARE.
/*
* this program makes the table to link function names
* and type indices that is used by execute() in run.c.
* it finds the indices in ytab.h, produced by yacc.
* it finds the indices in awkgram.tab.h, produced by bison.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "awk.h"
#include "ytab.h"
#include "awkgram.tab.h"
struct xx
{ int token;
@ -122,7 +122,7 @@ int main(int argc, char *argv[])
printf("#include <stdio.h>\n");
printf("#include \"awk.h\"\n");
printf("#include \"ytab.h\"\n\n");
printf("#include \"awkgram.tab.h\"\n\n");
if (argc != 2) {
fprintf(stderr, "usage: maketab YTAB_H\n");

View File

@ -27,7 +27,7 @@ THIS SOFTWARE.
#include <string.h>
#include <stdlib.h>
#include "awk.h"
#include "ytab.h"
#include "awkgram.tab.h"
Node *nodealloc(int n)
{

2
run.c
View File

@ -38,7 +38,7 @@ THIS SOFTWARE.
#include <sys/types.h>
#include <sys/wait.h>
#include "awk.h"
#include "ytab.h"
#include "awkgram.tab.h"
static void stdinit(void);
static void flush_all(void);

1
tran.c
View File

@ -29,7 +29,6 @@ THIS SOFTWARE.
#include <string.h>
#include <stdlib.h>
#include "awk.h"
#include "ytab.h"
#define FULLTAB 2 /* rehash when table gets this x full */
#define GROWTAB 4 /* grow table by this factor */