Mail Archives: djgpp/1997/02/11/12:58:20
I am not very experienced in Bison or Yacc programming
but this works fine for me:
...
| circle expression expression expression opt_radius {circle($2, $3, $4,
$5);}
opt_radius: /* empty is OK */ { return NULL; }
| expression { return $1; }
;
....
I think this is a standard technique.
If anyone has a better approach I would be happy to learn.
Hope this helps!
/Göran
goran AT igl DOT se
Gunnar Beushausen <GBeushausen AT t-online DOT de> wrote in article
<5dgqht$nu3 AT news00 DOT btx DOT dtag DOT de>...
> Hi there!
>
> Does anyone know how to implement optionality into a bison script?
> I'm creating a command that's called "circle" with the arguments
> x_position, y_position, radius and color. But i want color to be an
> optional argumend. My current code looks like this
>
> | circle expression expression expression expression {circle();}
>
> But when i execute the code i can't leave out the last expression,
> otherwise there would be a parse error.
>
> Can somebody help me please?
>
> ---
> Gunnar Beushausen
> GBeushausen AT t-online DOT de
> http://www.hof.de/~gbasic
>
- Raw text -