help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Please help!....Strange Error


From: Gregory L Montgomery
Subject: Re: Please help!....Strange Error
Date: Mon, 14 Apr 2003 16:03:28 -0700

Hi Tim Van Holder,
        Your expliantion, and advice WORKED. THANK YOU VERY MUCH! I had 
eliminated a 
privious /* empty */ rule. This is why I was having the problems that I was 
having. I also want to say that Hans Aberg's reply was also very helpful. 
Thank you all again, and

Take Care
Gregory L Montgomery
address@hidden



On Sunday 13 April 2003 11:27 pm, you wrote:
> > %start exp_line
> >
> > %%
> >
> > exp_line : if_exp NEWLINE
> >
> >          | '}' NEWLINE
> >          | PORTS NEWLINE
> >          | NEWLINE
> >          | '!' NEWLINE
> > |
> > | error NEWLINE
> >
> >          ;
>
> Your start rule only matches the one line.
> What you probably want is to add another rule:
>
> %start commands
>
> commands
>
> : /* empty */
> :
> | commands exp_line
>
> ;
>
> (if you expect at least one command, change the /* empty */ to exp_line).
> Note that in cases like this it can help to #define YYERROR_VERBOSE, as
> that will (in most cases) tell you what tokens were expected when there is
> a parse error.
>
> As an aside, you may want to consider the style I used above to keep your
> bison files more readable. Consider:
>
> if_exp
>
> : exp
>
>   {
>     $$ = $1;
>     //printf("if_exp->$1: %d\n", $<y_int>1);
>   }
>
> | var_exp '?' if_exp ':' if_exp
>
>   {
>     //$<y_tree>$ = make_op2_node(P_IF, $<y_tree>1,
>     //                           make_op2_node(P_CON, $<y_tree>3,
> $<y_tree>5));
>     //$$ = new Tree(P_IF, $<y_tree>1, new Tree(P_CON, $<y_tree>3,
> $<y_tree>5));
>     $$ = $1;
>   }
>
> | var_exp '#' if_exp
>
>   {
>     //$<y_tree>$ = make_op2_node(P_ITER, $<y_tree>1, $<y_tree>3);
>     $$ = new Tree(ITER_OpCode, $1, $3);
>   }
>
> | WHILE_DO var_exp ',' var_exp ')'
>
>   {
>     //$<y_tree>$ = make_op2_node(P_WHILE, $<y_tree>2, $<y_tree>4);
>     $$ = new Tree(WHILE_OpCode, $2, $4);
>   }
> ;
>
> instead of
>
> > if_exp : exp
> >        {
> >      $$ = $1;
> >      //printf("if_exp->$1: %d\n",$<y_int>1);
> >        }
> >
> >        | var_exp '?' if_exp ':' if_exp
> >
> >           {
> >         //$<y_tree>$ = make_op2_node(P_IF,$<y_tree>1,
> >             //
> > make_op2_node(P_CON,$<y_tree>3,$<y_tree>5));
> >         //   $$ = new Tree(P_IF,$<y_tree>1, new
> > Tree(P_CON,$<y_tree>3,$<y_tree>5));
> >         $$ = $1;
> >           }
> >
> >        | var_exp '#' if_exp
> >
> >           {
> >             //$<y_tree>$ =
> > make_op2_node(P_ITER,$<y_tree>1,$<y_tree>3);
> >         $$ = new Tree(ITER_OpCode,$1,$3);
> >           }
> >
> >        | WHILE_DO var_exp ',' var_exp ')'
> >
> >           {
> >         //$<y_tree>$ = make_op2_node(P_WHILE,$<y_tree>2,$<y_tree>4);
> >         $$ = new Tree(WHILE_OpCode,$2,$4);
> >           }
> >        ;
>
> Also, you may want to consider typing your rules to avoid having to use
> $<y_tree>n constructs.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]