Skip to content

Commit

Permalink
neqn: bison(1): Added Gunnar Ritter's sed script to use internal yyval
Browse files Browse the repository at this point in the history
  • Loading branch information
n-t-roff committed May 9, 2015
1 parent 2104eb6 commit 026a5df
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
6 changes: 4 additions & 2 deletions text/neqn/lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#include "e.h"
#include "y.tab.h"

extern YYSTYPE yyval;

#define SSIZE 400
char token[SSIZE];
int sp, yyval;
int sp;
#define putbak(c) *ip++ = c;
#define PUSHBACK 300 /* maximum pushback characters */
char ibuf[PUSHBACK+SSIZE]; /* pushback buffer for definitions, etc. */
Expand Down Expand Up @@ -212,7 +214,7 @@ include() {
}

delim() {
yyval = eqnreg = 0;
yyval.token = eqnreg = 0;
if (cstr(token, 0, SSIZE))
error(FATAL, "Bizarre delimiters at %.20s", token);
lefteq = token[0];
Expand Down
6 changes: 5 additions & 1 deletion text/neqn/neqn.mk
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ install : all
@chown $(OWNER) $(MAN1DIR)/neqn.1

clean :
rm -f *.o y.tab.c y.tab.h
rm -f *.o y.tab.c y.tab.h e.c

clobber : clean
rm -f neqn
Expand All @@ -61,6 +61,10 @@ neqn : $(OFILES)

$(OFILES) : e.h e.o

e.c: e.y
$(YACC) -d e.y
sed -f yyval.sed <y.tab.c >$@

changes :
@trap "" 1 2 3 15; \
sed \
Expand Down
22 changes: 22 additions & 0 deletions text/neqn/yyval.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Sccsid @(#)yyval.sed 1.2 (gritter) 10/2/07
#
# bison has a yacc-compatible yyval, but it is a local variable inside
# yyparse(). Making the variable global is necessary to make bc work
# with a bison-generated parser.
1,2 {
/Bison/ {
:look
/second part of user declarations/ {
i\
YYSTYPE yyval;
:repl
s/^[ ]*YYSTYPE[ ]*yyval;//
n
t
b repl
}
n
b look
}
}

0 comments on commit 026a5df

Please sign in to comment.