help-bison
[Top][All Lists]
Advanced

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

Re: Dynamically add tokens


From: Hans Aberg
Subject: Re: Dynamically add tokens
Date: Tue, 28 Jul 2009 13:03:52 +0200

On 28 Jul 2009, at 10:02, Alex Duller wrote:

In the language that I'm parsing it's possible to define custom 'types'; I have the following two rules:

type_defn:
yTYPE yID yIS var_type ';'

use_type:
yID "=>" sig_type

So, I want to somehow store whatever the user enters as yID in the first rule and use it as an alias for the specified var_type when yID is used in the second rule.

Hope that makes sense :)

You need a lookup table which stores the grammar type. When the lexer reads an identifier, it checks if it has been defined, and returns its grammar type. If not it returns just identifier, giving the parser the chance to define it. So the grammar looks like this:
  definition:
    type identifier ...
  ;
Then define tokens like int_variable, double_variable, etc. This works also if you want to make new types: creating a variable that acts as a type.

  Hans







reply via email to

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