[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bison, C++, types, and all that
From: |
Hans Aberg |
Subject: |
Re: Bison, C++, types, and all that |
Date: |
Mon, 24 Dec 2001 10:33:04 +0100 |
At 01:30 +0100 2001/12/21, Hans Aberg wrote:
>I found a very simple patch, which
>also generalizes the %union option.
...
>- I introduce four macros YYVAL, YYVAL_CAST, YYVSP, YYVSP_CAST which are
>used to write out the $ variable variables in the actions of the generated
>file:
> When: Macro written:
> $$ untyped YYVAL(yyval)
> $$ typed to cast_name YYVAL_CAST(yyval, cast_name)
> $n untyped YYVSP(yyvsp, n, stack_offset)
> $n typed to cast_name YYVSP_CAST(yyvsp, n, stack_offset, cast_name)
By using this patch, I was able to implement a C++ polymorphic variable for
use with Bison. Some specs: YYSTYPE is a class object with a polymorphic
pointer to a class object_root, which has a reference count. Parsing value
types are classes derived from object_root, which can be tracked by the use
of the Bison typing system, and a C++ template class I wrote (so C macros
are not sufficient). For example, $$ = $1 means that $$ becomes a reference
of what $1 is referencing, and I choose *$n mean the static type value of
$n, so that *$$ = *$n means recopying.
Also, I started to write my own skeleton file, C++.bison, which replaces
the C constructs with C++ ones, for example, the stacks have been replaced
by std::vector.
Hans Aberg