1 %%{section
} %%{output
-prefix
} %%{output
-infix
} %%".hh"
4 /* A Bison parser, made from %%filename,
5 by GNU bison %%version. */
7 /* Skeleton output parser for bison,
8 Copyright 1984, 1989, 1990, 2000, 2001 Free Software Foundation, Inc.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* As a special exception, when this file is copied by Bison into a
26 Bison output file, you may use that output file without restriction.
27 This special exception was added by the Free Software Foundation
28 in version 1.24 of Bison. */
31 /* #include "parser.hh" */
32 #include "location.hh"
38 template < typename P
>
44 struct Traits
< %%{name
} >
46 typedef int StateType
;
47 typedef %%{stype
} SemanticType
;
48 typedef Location LocationType
;
60 typedef Traits
< %%{name
} >::StateType StateType
;
61 typedef Traits
< %%{name
} >::SemanticType SemanticType
;
62 typedef Traits
< %%{name
} >::LocationType LocationType
;
64 typedef Stack
< StateType
> StateStack
;
65 typedef Stack
< SemanticType
> SemanticStack
;
66 typedef Stack
< LocationType
> LocationStack
;
68 %%{name
} () : debug (1)
77 /* Call to lexical analyser. */
82 looka
= yylex (&value
);
86 StateStack state_stack
;
87 SemanticStack semantic_stack
;
88 LocationStack location_stack
;
91 static const short pact_
[];
92 static const short defact_
[];
93 static const short pgoto_
[];
94 static const short defgoto_
[];
95 static const short table_
[];
96 static const short check_
[];
97 static const short line_
[];
98 static const short r1_
[];
99 static const short r2_
[];
100 static const char* const name_
[];
102 /* More tables, for debugging. */
103 /* FIXME: These tables should not be printed when not in debug
105 static const short rhs_
[];
106 static const short prhs_
[];
107 static const short rline_
[];
109 /* Even more tables. */
110 static inline char translate (int token
);
113 static const int eof
;
114 static const int empty
;
128 LocationType location
;
132 %%{section
} %%{output
-prefix
} %%{output
-infix
} %%".cc"
133 #include "%%{output-prefix}%%{output-infix}.hh"
135 /* Enable debugging if requested. */
139 # define YYFPRINTF std::fprintf
141 # define YYDPRINTF(Args) \
146 /* Nonzero means print parse trace. [The following comment makes no
147 sense to me. Could someone clarify it? --akim] Since this is
148 uninitialized, it does not stop multiple parsers from coexisting.
152 # define YYDPRINTF(Args)
153 #endif /* !YYDEBUG */
159 yy::%%{name
}::parse ()
161 /* Initialize stack. */
162 state_stack
= StateStack (0);
163 semantic_stack
= SemanticStack (1);
164 location_stack
= LocationStack (1);
166 /* Reserve initial space. The C parser needed that, but is it really
168 state_stack
.reserve (%%{initdepth
});
169 semantic_stack
.reserve (%%{initdepth
});
170 location_stack
.reserve (%%{initdepth
});
174 YYDPRINTF ((stderr
, "Starting parse\n"));
178 state_stack
.push (state
);
179 YYDPRINTF ((stderr
, "Entering state %d\n", state
));
184 /* Try to take a decision without lookahead. */
189 /* Read a lookahead token. */
192 YYDPRINTF ((stderr
, "Reading a token: "));
196 /* Convert token to internal form. */
201 YYDPRINTF ((stderr
, "Now at end of input.\n"));
205 ilooka
= translate (looka
);
207 YYFPRINTF (stderr
, "Next token is %d (%s", looka
, name_
[ilooka
]);
208 YYFPRINTF (stderr
, ")\n");
213 if (n
< 0 || n
> %%{last
} || check_
[n
] != ilooka
)
216 /* Reduce or error. */
235 /* Shift the lookahead token. */
236 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka
, name_
[ilooka
]));
238 /* Discard the token being shifted unless it is eof. */
242 semantic_stack
.push (value
);
243 location_stack
.push (location
);
247 /* Default action. */
256 value
= semantic_stack
[1 - len
];
257 location
= location_stack
[1 - len
];
262 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n
- 1, rline_
[n
]);
263 for (unsigned i
= prhs_
[n
];
265 YYFPRINTF (stderr
, "%s ", name_
[rhs_
[i
]]);
266 YYFPRINTF (stderr
, "-> %s\n", name_
[r1_
[n
]]);
271 SemanticType
& yyval (value
);
272 SemanticStack
& yyvsp (semantic_stack
);
280 state_stack
.pop (len
);
281 semantic_stack
.pop (len
);
282 location_stack
.pop (len
);
287 YYFPRINTF (stderr
, "state stack now");
288 for (StateStack::ConstIterator i
= state_stack
.begin ();
289 i
!= state_stack
.end (); ++i
)
290 YYFPRINTF (stderr
, " %d", *i
);
291 YYFPRINTF (stderr
, "\n");
295 semantic_stack
.push (value
);
296 location_stack
.push (location
);
298 /* Shift the result of the reduction. */
300 state
= pgoto_
[n
- %%{ntokens
}] + state_stack
[0];
301 if (state
>= 0 && state
<= %%{last
} && check_
[state
] == state_stack
[0])
302 state
= table_
[state
];
304 state
= defgoto_
[n
- %%{ntokens
}];
307 /* Report and recover from errors. This is very incomplete. */
309 std::cerr
<< "Parse error." << std::endl
; // FIXME: Need something like yyerror?
317 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
320 yy::%%{name
}::pact_
[] =
325 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
326 doesn't specify something else to do. Zero means the default is an
329 yy::%%{name
}::defact_
[] =
334 /* YYPGOTO[NTERM-NUM]. */
336 yy::%%{name
}::pgoto_
[] =
341 /* YYDEFGOTO[NTERM-NUM]. */
343 yy::%%{name
}::defgoto_
[] =
348 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
349 positive, shift that token. If negative, reduce the rule which
350 number is the opposite. If zero, do what YYDEFACT says. */
352 yy::%%{name
}::table_
[] =
359 yy::%%{name
}::check_
[] =
364 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
366 yy::%%{name
}::line_
[] =
371 /*YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
373 yy::%%{name
}::r1_
[] =
378 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
380 yy::%%{name
}::r2_
[] =
385 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
386 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
388 const yy::%%{name
}::name_
[] =
393 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
395 yy::%%{name
}::rhs_
[] =
400 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
403 yy::%%{name
}::prhs_
[] =
408 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
410 yy::%%{name
}::rline_
[] =
415 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
417 yy::%%{name
}::translate (int token
)
425 return ((unsigned)(token
) <= %%{maxtok
} ? translate_
[token
] : %%{nsym
});
428 const int yy::%%{name
}::eof
= 0;
429 const int yy::%%{name
}::empty
= -2;
433 %%{section
} %%"stack.hh"
434 #ifndef BISON_STACK_HH
435 # define BISON_STACK_HH
441 template < class T
, class S
= std::vector
< T
> >
446 typedef typename
S::iterator Iterator
;
447 typedef typename
S::const_iterator ConstIterator
;
453 Stack (unsigned n
) : seq_ (n
)
459 operator [] (int index
)
461 return seq_
[seq_
.size () - 1 + index
];
466 operator [] (int index
) const
468 return seq_
[seq_
.size () - 1 + index
];
493 inline ConstIterator
begin () const { return seq_
.begin (); }
494 inline ConstIterator
end () const { return seq_
.end (); }
502 #endif // not BISON_STACK_HH
504 %%{section
} %%"location.hh"
505 #ifndef BISON_LOCATION_HH
506 # define BISON_LOCATION_HH
523 #endif // not BISON_LOCATION_HH