Bonjour Hans, Le mardi 13 septembre 2005 à 00:45:16, vous écriviez :
HA> On 12 Sep 2005, at 23:31, Baldurien (club internet) wrote: >> I've made a little parser in PHP based on bison output file, and I >> experiment a little problem : >> >> When I have to reduce, saying by rule X : Y '+' X I know I have to pop >> 3 times, but what happens when the rule is simply X : /* empty */ ? I >> can't pop at all, so what should I do? HA> Just don't pop. If s is the state on top of the state stack, the HA> total effect is that the state goto(s, X) is pushed onto it. If you HA> have a stack for non-terminals and terminals, which the Bison HA> generated parser doesn't, then X will be pushed onto that. The rule HA> action is executed. HA> Hans Aberg So, in term of coding I've got these (in php) : $reduce: the rule we use to reduce. $ss : the stack of state $sl : the level of this stack. The top state is $ss[$sl-1]. $ls : the location stack, it's a stack that contains only the start and the end line of a rule. I use it in order to have comprehensive error message (like : syntax error between line x and y for a string, etc). $rule = $__xtf_parser_rule_lhs[$reduce]; /** * We have to pop a certain amount of time */ $pop = $__xtf_parser_rule_count[$reduce]; $sl -= $pop; $goto = &$__xtf_parser_goto[$__xtf_parser_sgoto[$ss[$sl-1]]]; /* call reduce handler, etc : action set by the user */ $ls[$sl-1] = array( $ls[$sl-1][0], $ls[$sl-2+$pop][1] ); $ss[$sl++] = $goto[$rule]; Here I do $sl++, meaning I increment the stack level (but after). When pop is null, should it be only $ss[$sl-1] ? -- Cordialement, Baldurien Courriel : [EMAIL PROTECTED] _______________________________________________ Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison