|
By slunk731 Wc3c
开源的..C#...
最近感觉智力严重下降..
我已经懒得看他到底写了些啥了..
全部copy过来完事...
So, I decided to play around with the idea of Grimoire extensions. I'm not much of a delphi guy, though, so first I needed to put together an interpreter for Jass. I decided to use ANTLR to these ends, and the results are very good.
Attached are:
-A .g file which can be opened in ANTLR. The grammar was developed in ANTLRWorks 1.2b5. Any post-3.1 version of ANTLR should be able to run it, but if you're a programming languages noob like me, I'd recommend using ANTLRWorks.
Using ANTLR, you can use this .g file to export source files for a Jass interpreter to about half a dozen different languages. I used C#, but you can use C, Java, Objective C, ActionScript, etc. I know that C# works for a fact, though, and I cannot vouch for the usefulness of the exporters for the other languages.
-A C# project showing off the Jass interpreter exported with ANTLR. It's a console project that takes a Jass file in as a single argument. It will attempt to parse the Jass file, displaying parse errors. There is a known bug, located in the C# ANTLR runtimes that causes it to get confused by UNIX/Mac newlines, so the line of a syntax error will be displayed incorrectly in some cases. This doesn't stop it from parsing correctly, though, because my grammar is done right.
Included in the project are Program.cs, written by me, and JassLexer.cs/JassParser.cs, exported by ANTLR. Also the necessary dll's of the ANTLR runtimes are included. The only changes made to JassLexer.cs/JassParser.cs after exporting is that I changed the text of the token name strings at the top of JassParser.cs, to make syntax error messages more informative.
-The binaries exported by compiling the C# project, so you can test it without pulling out visual studio.
Let me know if you enjoy this stuff- I'll be using it to write my obfuscator!
Update: I decided to go ahead and clean up/comment the .G file, so it's a little more legible now, hopefully. |
|