Skip to content

Commit d63a201

Browse files
committed
Two small fix-up lines to get it working with bison-2.4.1
1 parent 2ce60e3 commit d63a201

9 files changed

Lines changed: 560 additions & 307 deletions

File tree

src/Makefile.plain

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# $Id$
2+
# plain simple Makefile to build exprtest
3+
4+
CXX = g++
5+
LEX = flex
6+
YACC = bison
7+
8+
CXXFLAGS = -W -Wall -Wextra -ansi -g
9+
LDFLAGS =
10+
11+
HEADERS = driver.h parser.h scanner.h expression.h \
12+
y.tab.h FlexLexer.h location.hh position.hh stack.hh
13+
14+
all: exprtest
15+
16+
# Generate scanner and parser
17+
18+
parser.cc: parser.yy
19+
$(YACC) -o parser.cc --defines=parser.h parser.yy
20+
21+
scanner.cc: scanner.ll
22+
$(LEX) -o scanner.cc scanner.ll
23+
24+
# Implicit rule to compile c++ files
25+
26+
%.o: %.cc
27+
$(CXX) $(CXXFLAGS) -c -o $@ $<
28+
29+
# Link executable
30+
31+
exprtest: exprtest.o parser.o scanner.o driver.o
32+
$(CXX) $(LDFLAGS) -o $@ exprtest.o parser.o scanner.o driver.o
33+
34+
clean:
35+
rm -f exprtest *.o
36+
37+
extraclean: clean
38+
rm -f parser.cc parser.h scanner.cc

src/expression.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <map>
88
#include <vector>
9+
#include <ostream>
910
#include <stdexcept>
1011
#include <cmath>
1112

src/location.hh

Lines changed: 80 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
/* A Bison parser, made by GNU Bison 2.3. */
21

3-
/* Locations for Bison parsers in C++
4-
5-
Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
2+
/* A Bison parser, made by GNU Bison 2.4.1. */
63

7-
This program is free software; you can redistribute it and/or modify
4+
/* Locations for Bison parsers in C++
5+
6+
Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
7+
8+
This program is free software: you can redistribute it and/or modify
89
it under the terms of the GNU General Public License as published by
9-
the Free Software Foundation; either version 2, or (at your option)
10-
any later version.
11-
10+
the Free Software Foundation, either version 3 of the License, or
11+
(at your option) any later version.
12+
1213
This program is distributed in the hope that it will be useful,
1314
but WITHOUT ANY WARRANTY; without even the implied warranty of
1415
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1516
GNU General Public License for more details.
16-
17+
1718
You should have received a copy of the GNU General Public License
18-
along with this program; if not, write to the Free Software
19-
Foundation, Inc., 51 Franklin Street, Fifth Floor,
20-
Boston, MA 02110-1301, USA. */
19+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
2120

2221
/* As a special exception, you may create a larger work that contains
2322
part or all of the Bison parser skeleton and distribute that work
@@ -28,7 +27,7 @@
2827
special exception, which will cause the skeleton and the resulting
2928
Bison output files to be licensed under the GNU General Public
3029
License without this special exception.
31-
30+
3231
This special exception was added by the Free Software Foundation in
3332
version 2.2 of Bison. */
3433

@@ -44,100 +43,129 @@
4443
# include <string>
4544
# include "position.hh"
4645

46+
47+
/* Line 162 of location.cc */
48+
#line 1 "[Bison:b4_percent_define_default]"
49+
4750
namespace example {
4851

49-
/// Abstract a location.
50-
class location
51-
{
52-
public:
52+
/* Line 162 of location.cc */
53+
#line 54 "location.hh"
54+
55+
/// Abstract a location.
56+
class location
57+
{
58+
public:
5359

5460
/// Construct a location.
5561
location ()
56-
: begin (), end ()
62+
: begin (), end ()
5763
{
5864
}
5965

66+
6067
/// Initialization.
6168
inline void initialize (std::string* fn)
6269
{
63-
begin.initialize (fn);
64-
end = begin;
70+
begin.initialize (fn);
71+
end = begin;
6572
}
6673

6774
/** \name Line and Column related manipulators
6875
** \{ */
69-
public:
76+
public:
7077
/// Reset initial location to final location.
7178
inline void step ()
7279
{
73-
begin = end;
80+
begin = end;
7481
}
7582

7683
/// Extend the current location to the COUNT next columns.
7784
inline void columns (unsigned int count = 1)
7885
{
79-
end += count;
86+
end += count;
8087
}
8188

8289
/// Extend the current location to the COUNT next lines.
8390
inline void lines (unsigned int count = 1)
8491
{
85-
end.lines (count);
92+
end.lines (count);
8693
}
8794
/** \} */
8895

8996

90-
public:
97+
public:
9198
/// Beginning of the located region.
9299
position begin;
93100
/// End of the located region.
94101
position end;
95-
};
102+
};
96103

97-
/// Join two location objects to create a location.
98-
inline const location operator+ (const location& begin, const location& end)
99-
{
104+
/// Join two location objects to create a location.
105+
inline const location operator+ (const location& begin, const location& end)
106+
{
100107
location res = begin;
101108
res.end = end.end;
102109
return res;
103-
}
110+
}
104111

105-
/// Add two location objects.
106-
inline const location operator+ (const location& begin, unsigned int width)
107-
{
112+
/// Add two location objects.
113+
inline const location operator+ (const location& begin, unsigned int width)
114+
{
108115
location res = begin;
109116
res.columns (width);
110117
return res;
111-
}
118+
}
112119

113-
/// Add and assign a location.
114-
inline location& operator+= (location& res, unsigned int width)
115-
{
120+
/// Add and assign a location.
121+
inline location& operator+= (location& res, unsigned int width)
122+
{
116123
res.columns (width);
117124
return res;
118-
}
119-
120-
/** \brief Intercept output stream redirection.
121-
** \param ostr the destination output stream
122-
** \param loc a reference to the location to redirect
123-
**
124-
** Avoid duplicate information.
125-
*/
126-
inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
127-
{
125+
}
126+
127+
/// Compare two location objects.
128+
inline bool
129+
operator== (const location& loc1, const location& loc2)
130+
{
131+
return loc1.begin == loc2.begin && loc1.end == loc2.end;
132+
}
133+
134+
/// Compare two location objects.
135+
inline bool
136+
operator!= (const location& loc1, const location& loc2)
137+
{
138+
return !(loc1 == loc2);
139+
}
140+
141+
/** \brief Intercept output stream redirection.
142+
** \param ostr the destination output stream
143+
** \param loc a reference to the location to redirect
144+
**
145+
** Avoid duplicate information.
146+
*/
147+
inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
148+
{
128149
position last = loc.end - 1;
129150
ostr << loc.begin;
130151
if (last.filename
131152
&& (!loc.begin.filename
132153
|| *loc.begin.filename != *last.filename))
133-
ostr << '-' << last;
154+
ostr << '-' << last;
134155
else if (loc.begin.line != last.line)
135-
ostr << '-' << last.line << '.' << last.column;
156+
ostr << '-' << last.line << '.' << last.column;
136157
else if (loc.begin.column != last.column)
137-
ostr << '-' << last.column;
158+
ostr << '-' << last.column;
138159
return ostr;
139-
}
160+
}
161+
162+
163+
/* Line 271 of location.cc */
164+
#line 1 "[Bison:b4_percent_define_default]"
165+
166+
} // example
140167

141-
}
168+
/* Line 271 of location.cc */
169+
#line 170 "location.hh"
142170

143171
#endif // not BISON_LOCATION_HH

0 commit comments

Comments
 (0)