Bison action code
I know the post is out of date, but I ran into the same problem and found a much simpler solution using a small python script.
filename = "in.txt";
b_count = 0;
with open("out.txt", "w") as fout:
with open(filename) as f:
while True:
c = f.read(1)
if not c:
print "End of file"
break
if (b_count == 0):
fout.write(c);
if (c == '{'):
b_count += 1
else :
if (c == '{'):
b_count += 1
if (c == '}'):
b_count -= 1
if (b_count == 0):
fout.write('}')
I hope this is helpful for everyone!
a source to share
As far as I know, no.
As you probably know, writing your own tool is possible, but difficult. For example, the characters {
and }
can be displayed as character constants or strings. (So, of course, symbols :
and ;
.)
If you have specific files that you want to remove actions from, and you can rely on your own environment and constraints (i.e. you don't need a general case solution), there might be a relatively simple way to do it.
If you want a complete general solution, all that remains is to crack the bison code. Not for the faint of heart, I admit. However, most bison are realized or delineated in bison.
For bison sources, see scan-gram.l
and parse-gram.y
for the bison scanner / parser group. The icon to look out for is BRACED_CODE
.
Now, since you basically need to take a file and create an almost exact copy of it, and you don't really need to understand it, you can probably do all your work in lexer. You can use it scan-gram.l
as a basis for your work. A useful modification would be to add a different state (start condition) for the description, if you are in the prologue / declaration section, versus the grammar rules. Everything except grammar rules should be typed verbatim.
Comments, spaces, directives, most punctuation marks, identifiers, numbers: just print them verbatim.
Characters and Strings: They require their own states in the lexer because they need to find where they end. (Character literals can be longer than one keyboard character; consider octal). But given that they have their own states, print them out verbatim.
Code: Like characters and strings, you need to figure out where it ends. This is a little more complicated because it can contain lines and comments and whatnot. But once you find out where it ends, you can exit the code state. You don't need to type anything here (except for parentheses).
Good luck!
a source to share