Skip to content

Commit dd244cf

Browse files
committed
using an updated version to generate code via bison
1 parent 772e42e commit dd244cf

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

makefiles/lexyaccxx.mf

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,24 @@
22
# disable _this_ implicit rule
33
%.c: %.y
44

5-
%.cc: %.y
6-
mkdir -p bisontmp ; \
7-
rm -f bisontmp/* ; \
8-
cd bisontmp ; \
9-
x=`$(YACC) $(YFLAGS) -o $(notdir $@) ../$< 2>&1` ; \
10-
if [[ "$<" == "src/parser.y" ]]; then \
11-
# patch parser.y file, if older version of bison is used. Since 3.3.2, synatx changed. \
12-
if [[ "$$x" =~ "error: %define variable 'api.parser.class' is not used" ]]; then \
13-
# push and pop is necessary, as GNU patch does not accept ../ as file paths \
14-
pushd . && cd ../ && patch $< < src/parser.y_apiparserclass.patch && popd; \
15-
x=`$(YACC) $(YFLAGS) -o $(notdir $@) ../$< 2>&1` ; \
16-
fi; \
17-
fi; \
18-
r=$$? ; \
19-
printf "$$x\n" ; \
20-
if [ "$$r" != 0 ]; then \
21-
echo Bison exit status: $$r ; \
22-
cd ..; \
23-
rm -rf bisontmp; \
24-
exit 1;\
25-
fi ; \
26-
y=`echo $$x | grep -v conflict` ; \
27-
r=$$? ; \
28-
if [ "$$r" != 0 ]; then \
29-
cd ..; rm -rf bisontmp; exit 2; fi ; \
30-
for i in *; do cmp $$i ../$(dir $@)/$$i; if [ "$$?" != 0 ]; then echo copying $$i; cp $$i ../$(dir $@)$$i; fi; done ; \
31-
touch ../$@; \
32-
cd ..; \
33-
rm -rf bisontmp;
34-
355
%.c: %.l
366

377
%.cc: %.l
388
$(LEX) -o $@ $(LFAGS) $<
9+
10+
%.cc: %.y
11+
$(call bold,>>> Creating parser via bison ...)
12+
# create a new temporary directory
13+
$(eval tmpdir := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gapc_XXXXXXXX'))
14+
# copy input file into temporary directory
15+
cp $< $(tmpdir)/
16+
# use bison to generate parser source files
17+
# we have a breaking change since Bison 3.3.2, which only effects src/parser.y
18+
# if first bison attempt fails, we will try to apply a patch to the input in the tmpdir and rerun the code generation
19+
$(YACC) $(YFLAGS) -o $(tmpdir)/$(notdir $@) $(tmpdir)/$(notdir $<) 2>&1 \
20+
|| (echo "failed to generate parser, trying to patch input .y file..." && (patch $(tmpdir)/$(notdir $<) < $<_apiparserclass.patch && $(YACC) $(YFLAGS) -o $(tmpdir)/$(notdir $@) $(tmpdir)/$(notdir $<) 2>&1)) \
21+
|| (echo "failed to generate parser, trying another patch on input .y file..." && (patch $(tmpdir)/$(notdir $<) < $<_osx.patch && $(YACC) $(YFLAGS) -o $(tmpdir)/$(notdir $@) $(tmpdir)/$(notdir $<) 2>&1))
22+
# remove source file from temporary directiry
23+
rm $(tmpdir)/$(notdir $<)
24+
# copy all generated files into working directory
25+
cp $(tmpdir)/* $(dir $@)

src/parser.y_osx.patch

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--- parser.y 2020-07-07 15:39:39.403691645 +0200
2+
+++ /media/vbox/Users/sjanssen/Git/jlab/gapc/src/parser.y 2020-07-07 15:01:57.000000000 +0200
3+
@@ -68,15 +68,15 @@
4+
5+
%skeleton "lalr1.cc"
6+
%defines /* yacc -d */
7+
-%define api.parser.class {Parser}
8+
-%define api.location.type { Loc }
9+
+%define "parser_class_name" "Parser"
10+
+%define "location_type" "Loc"
11+
%parse-param { Driver& driver }
12+
%parse-param { yy::Parser::token_type start_symbol }
13+
%lex-param { yy::Parser::token_type start_symbol }
14+
%locations
15+
%debug /* yacc -t */ /* FIXME */
16+
%verbose /* yacc -v */
17+
-%define parse.error verbose
18+
+%error-verbose
19+
20+
%initial-action
21+
{

0 commit comments

Comments
 (0)