help-bison
[Top][All Lists]
Advanced

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

Re: Problems with untyped


From: Hans Aberg
Subject: Re: Problems with untyped
Date: Thu, 4 Jul 2002 19:25:16 +0200

Reply-to: address@hidden

At 13:34 +0100 2002/07/04, John S O'Sullivan wrote:
>I would appreciate some trouble with a simple grammar I am trying to
>develop.

This is unusual -- usually people wants to rid their grammars of trouble. :-)

> I have read the Bison
>manual , but find the brief references to typing unclear.

The Bison manual, section 3.5.4, says:

If you have used @code{%union} to specify a variety of data types, then you
must declare a choice among these types for each terminal or nonterminal
symbol that can have a semantic value.  Then each time you use @code{$$} or
@address@hidden, its data type is determined by which symbol it refers to
in the rule.

>I have attached some sample code.
...
> Bison complains
>that the line
>     |       IF expression '<' expression THEN statement { if ($2 < $4) $6;
>}
>has $6 untyped. I can't figure out what type $6 should be.
...
>%union {
>       float dval;
>       int vblno;
>}

Taking the Bison manual literally, so must add either of
  %type <dval> statement
  %type <vblno> statement

However, you do not use any value for statement, so I merely added
  %type <> statement
Strictly speaking, tis is not a supported feature, it seems.

[Akim: Would it not be great to add this
  %type <> grammar-variable
as a feature as an indication of a variable that has no value? -- Also,
perhaps for polymorphic programing one might need "any value" indicated by
say
  %type grammar-variable
]

Then I get the error:
     type clash (`' `') on default action

If you write your rule _without_ any action, like:
  statement_list:
      statement '\n'
    | statement_list statement '\n'
then Bison will assume that the rule $$ = $1 should be applied, which is
causing the problem. So I added empty rules:
  statement_list:
      statement '\n' {}
    | statement_list statement '\n' {}

Then Bison compiles it without an error.

  Hans Aberg





reply via email to

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