bison-patches
[Top][All Lists]
Advanced

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

Re: %code and %typed


From: Hans Aberg
Subject: Re: %code and %typed
Date: Thu, 19 May 2005 12:17:12 -0000

I attach the patches I made to bison-2.0. I implementing the %code command using some context switches. I am happy if somebody can suggest a better implementation. The parse-gram.y syntax is as follows:

declaration:
  grammar_declaration
| PROLOGUE                                 { prologue_augment ($1, @1); }
| "%debug"                                 { debug_flag = true; }
| "%define" string_content string_content  { muscle_insert ($2, $3); }
| "%code" { include_braces = false;  other_id = true; }
OTHER_ID BRACED_CODE { muscle_insert ($3, $4); include_braces = true; other_id = false; }
| "%defines"                               { defines_flag = true; }

Here, a problem is that I do not want the outermost braces included in BRACED_CODE. The reason is that I want to place top level C++ code. Therefore as a quick fix, I made a context switch "include_braces" in the lexer that excludes it. An alternative would have to either zip out the first and last character of $4 above (BRACED_CODE string value), or to do it in a variation of muscle_insert(). But the obstacks seem to not be made for such an operation. An alternative would be to always exclude the outermost braces in BRACED_CODE, and add them in the skeleton file instead.

Another context switch was added for OTHER_ID. Here the problem is that Bison scans for ID, which has the same lexer syntax as OTHER_ID, but is doing semantic work in the lexer, entering it as a grammar symbol. I just want to pick up the string. I choose this syntax, because then one adds code by a construct like
%code header_code {
  ...
}
which feels natural.
--
  Hans Aberg

Attachment: parse-gram.y
Description: Binary data

Attachment: scan-gram.l
Description: Binary data


reply via email to

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