kaby76 / Trash

Toolkit for grammars
MIT License
71 stars 5 forks source link

Converting really old bison #435

Open marauder2k7 opened 2 months ago

marauder2k7 commented 2 months ago

I am trying to convert a really old bison grammar file, trying to update our engine to test out an antlr4 parser since it is a lot easier to expand the scripting language we use if that was possible the grammar file is here

https://github.com/TorqueGameEngines/Torque3D/blob/development/Engine/source/console/torquescript/CMDgram.y

trying to run trparse CMDgram.y | trconvert | trsponge gives a lot of errors, i understand i can't expect this to be an automatic conversion and it will take some work in order to get it to be successful, any tips/pointers on what needs changed?

This was originally designed to work with bison flex and ast nodes. But it is going on about 15 years ago now and no one on our time fully understands bison enough to be able to expand it. Also since it is a game engine we would like our users to have the option to expand it as well.

kaby76 commented 2 months ago

I ran the grammar through the most recent version of the tools, and it seems to process it without error.

$ trparse GMDgram.y | trconvert | trsponge -o xxx
Using built-in parser.
CSharp 0 GMDgram.y success 0.0613929
Writing to xxx/GMDgram.g4
04/22-05:40:43 ~/issues/trash-435

I'm not sure what the errors may be, but I have been redoing quite a bit of the Trash toolkit. It's likely that the hardwired tool trconvert will be turned into a Bash script that uses trquery, but I'm just starting thinning out the toolkit only now.

I then reformatted the grammar with antlr-format, and produced this:
GMDgram.g4.txt

That said, I would recommend cleaning up the grammar. For example, the last rule in the grammar should be rewritten using the Kleene +-operator.

Also, most actions in the Bison grammar construct a tree. That code will need to be ported over into an Antlr Visitor. Currently, the convert does not do any of that.

marauder2k7 commented 2 months ago

thank you very much for this! is there any guidance you can give me for where i might have been going wrong?

I ran that same command and it seemed to fail for me it only converted a couple of the rules and then failed.

I did begin to re-format this into antlr4 by hand until i was told a few things would not be possible in antlr at the moment but are planned for antlr5 so this is a big help

kaby76 commented 2 months ago

If you can pass me the text of the error messages, I can work on that.

Definitely use the antlr-format tool. The Antlr4Formtter, which is the "official" formatter for Antlr4 code, isn't configurable. Plus, antlr-format is integrated into the Antlr4 extension for VSCode, which is an excellent extension.

Antlr5 won't have tree construction either, but I am planning on adding tree construction into Trash for a superset of the Antlr4 language. The main issue is to roll Selenium into Trash. Unfortunately, I have to port all the open source code, which is in Java, into C#. I will try to parse action code like yours to convert into equivalent actions and/or syntax for tree construction.

marauder2k7 commented 2 months ago

no error message came out is the thing, it just didnt carry on with its conversion, might have been a bug in my download of it or something?

kaby76 commented 2 months ago

What does trparse --version output? What does dotnet --version say?