help-bison
[Top][All Lists]
Advanced

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

Re[2]: Input Data Stream Uprgaded Grammar


From: Владимир Рыков
Subject: Re[2]: Input Data Stream Uprgaded Grammar
Date: Mon, 29 Jan 2001 09:59:51 +0300

Thank you Hans - I supposed the deal to be almost the same

Vladimir


-----Original Message-----
From: Hans Aberg <address@hidden>
To: "Vladimir Rykov" <address@hidden>
Date: Sun, 28 Jan 2001 22:00:14 +0100
Subject: Re: Input Data Stream Uprgaded Grammar

> At 17:12 +0300 1-01-27, Vladimir Rykov wrote:
> >...I met a problem that seems unresolvable for  me. ...   Is it possible
> >to >upgrade the compiled (binary)  Bison-made Grammar from the input data
> >stream?
> 
> No.
> 
> >   Here is an example;   ...   a*b+c     - ordinary  data ...   (I want to
> >>define new operation):   DEFINE ** AS n**2 = n*n    - or by  any other
> >means   >... (Then I use this new operation in my input  stream)   d + f
> >** 2   ...     >So - may I define new operation (let it be "square"  - **)
> >using properly >keywords and other tools and so to upgrade my inner
> >grammar?
> 
> A simple way to provide an extensible grammar, is to identify the different
> possible grammar rules and let your lexer (by a table lookup) return
> suitable token numbers.
> 
> In the languages Haskell and Prolog, one can define operators with a
> precedence and left/right associativity. In Haskell, the precedence levels
> are only ten, so you could write out the different combinations
> expr:
>     expr opl0 expr {...}
>   ...
>   | expr opl9 expr {...}
>   ...
> and then define the precedence levels correctly to Bison. The lexer would
> then use the table lookup precedence level to return the correct opl0, ....
> 
> The Haskell interpreter Hugs http://haskell.org/hugs however skips the
> precedence levels in the .y grammar, and makes that parsing in an
> independent (rather simple) engine. In a Prolog reader you would have to
> use this method, because the number of precedence levels are 1000.
> 
> In your case, you may not need this at all, if you only need macro
> expansions and the like. Then you grammar might look like
>   definition: DEFINE identifier AS expr
> for the definition of new identifiers, and later in the use
>   expr: expr identifier expr { $$ = (*rule($2))($1, $3) }
> -- You then look-up the identifiers defined in the lookup table, and from
> that can you see what to do with them. If the rule of the identifier `**'
> is defined to a^b (in the example action above, a function pointer that the
> function `rule' returns), that rule will be applied. (You must also figure
> out a way to produce an error if an identifier is not defined.)
> 
>   Hans Aberg
>                   * Email: Hans Aberg <mailto:address@hidden>
>                   * Home Page: <http://www.matematik.su.se/~haberg/>
>                   * AMS member listing: <http://www.ams.org/cml/>
> 
> 
> 

--

P bI K O B  B. B.    MOCKBA




reply via email to

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