help-bison
[Top][All Lists]
Advanced

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

Re: Parsing user-defined types


From: EML
Subject: Re: Parsing user-defined types
Date: Wed, 8 May 2019 18:57:53 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

I've just found the problem described on Wikipedia (https://en.wikipedia.org/wiki/The_lexer_hack), but not much practical information on actually handling it.

On 08/05/2019 18:48, EML 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?

_______________________________________________
address@hidden https://lists.gnu.org/mailman/listinfo/help-bison




reply via email to

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