help-bison
[Top][All Lists]
Advanced

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

Re: Parsing user-defined types


From: Hans Åberg
Subject: Re: Parsing user-defined types
Date: Wed, 8 May 2019 20:14:49 +0200

> On 8 May 2019, at 19:48, EML <address@hidden> wrote:
> 
> I'm having trouble seeing how to handle user-defined types without lots of 
> feedback from the parser to the lexer. For example, consider a C-like 
> language with a struct declaration:
> 
> foo() {
>  struct a {...};  // type defn
>  struct a b;      // declare object 'b' of user-defined type 'a'
> }
> 
> this is easy to parse, but if you add a typedef, or go to C++, you can have 
> code that looks like this:
> 
> foo() {
>  struct a {...};
>  a b;
> }
> 
> With a simple flex/bison setup this is likely to lead to a lot of conflicts. 
> So how do you handle this? Do you just work through the conflicts, if 
> possible, or is this a job for a hand-coded lexer, which can be told about 
> new types at runtime?

One can store the Bison token value on the lookup table that the lexer uses. So 
the lexer matches the identifier, then, checks if it has been identified, and 
if so, returns its token and semantic values. Otherwise it is just a name, like 
in a definition, whose Bison rule action puts it on the lookup table.




reply via email to

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