Angel Script BNF Grammar

Started by
2 comments, last by Anth0ny229 8 years, 10 months ago

What i'm trying to do is create a Grammar class for Irony which is a great tool to implement languages but it requires the grammar to be defined in BNF. So far it's been going great but the issue is I'm following the BNF defined in "as_parser.cpp" and I have hit a problem where it's not recognizing the conditional statements within the for, while, do, if sections. I have followed the BNF almost exactly from within the .cpp so I'm not sure if its a problem how I implemented it of if its a small error in the BNF format. Anyways I was wondering if anyone would like to help fix this. It would help fix the BNF format in the Angel Script source if it is the problem. It would also allow people to create very nice syntax highlighters. My goal with this is once I get it down correctly is to make a Visual Studio extension for Angel Script that highlights as well as has Intellisense and all the nice features for writing code. Possible also create support for projects, and if I get that far maybe even add support for the Debugger with a clean add-on class so anyone can use it without almost no code changes.

Attached is the project, all you need to do is compile the C# project which will create a dll. Then you open that DLL with "Irony.GrammarExplorer.exe" that I included in the Debug folder where the dll is outputted. It is very simple to get going so hopefully someone can help out even if its just a little bit. This is a project I plan on releasing so that everyone can use it and hopefully make writing scripts just that much more fun.

You can use the Grammar explorer to open a script file to see how the highlighting works so far with the current grammar. I also included a script that I've been working with. I also removed some of the support for stuff like classes temporarily until I can fix this issue since once this problems solved it will then work with classes just fine. So with some luck someone can help me out and then we can have a nice IDE.

I'm using the Irony Dll from NuGet

https://www.nuget.org/packages/Irony/

And if the exe in the debug folder does not work or you would like to rebuild or at least look at other samples here is the link

https://irony.codeplex.com/

I hope someone is able to help, if you have any questions please ask.

Thank you!

- Anthony Clark

PS: Here is a picture of the Irony Grammar Explorer loaded with the Angel Script grammar dll I'm working on. And you can see how it only works with true or false and not other statements which I think is a problem with the BNF.

e2b8b5e0cdb039f03ed5289f7c394280.png

Advertisement

UPDATE:

As a temporary fix just to make sure it wasn't me that was going crazy I made a temp var to test out a different way.

I replaced:


            //    ::= 'if' '(' ASSIGN ')' STATEMENT ['else' STATEMENT]
            IF.Rule = k_IF + "(" + TEMPIF + ")" + STATEMENT + (k_ELSE + STATEMENT).Q();

with:


            var TEMPIF = new NonTerminal("tempif");
            TEMPIF.Rule = EXPR | MakeStarRule(IDENTIFIER + EXPROP + (IDENTIFIER | LITERAL) + LOGICOP.Q());
            
            //    ::= 'if' '(' ASSIGN ')' STATEMENT ['else' STATEMENT]
            IF.Rule = k_IF + "(" + TEMPIF + ")" + STATEMENT + (k_ELSE + STATEMENT).Q();

It seemed to at least let me setup my if statement properly


  // if statement
  if( a == b || b != a && a == 10 && b != 10 )
  {
    // Do something if condition is true
  }

Here's a picture:

5afac48228e4f5264916f942beed46a5.png

So I'm now pretty sure it is a small issue in the BNF format in "as_parser.cpp". It is missing the setting of literals it seems as well as maybe a few other things. Rather then using this temporary fix for all the other types of statements I rather try and find the error in the .cpp so that way we can correct it there as well as have it work exactly how the Angel Script compiler works. It should not be that hard to fix but I can't seem to wrap my head around it because the recursiveness of it which is important so it's exactly how the Angel Script parser works.

I hope someone that can help out takes the time to, it's very easy to work off what I have provided and it will help everyone. If a donation is a better motivation then just let me know and i'll be more than happy to being it will help the community as a whole. Thanks again.

Also, here is what Lua's BNF looks like which was easy to implement being that it is a lot more simple than Angel Script. But at least it might be a good reference to see how they define some things.

http://www.lua.org/manual/5.1/manual.html#8

- Anthony Clark

I wrote the BNF comments in as_parser.cpp in order to help another team write their syntax highlighter (it was a Chinese team, I believe they are associated to boyaa.com, but I'm not sure). They were the guys behind babelua and they wanted to create something similar for AngelScript. Unfortunately I never heard back from them on whether they completed the project or not.

Anyway, to me the BNF comments are just code comments and may very well contain some errors or missing information. I never intended these comments to be processed automatically, but only to help those that wished to understand the details of the AngelScript syntax. If you see any error in the BNF comments in as_parser.cpp you need just let me know and I'll have it fixed.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Ah to bad you never heard back from them that would have been great since that's pretty much what I'm using as a reference to create my own Visual Studio extension. I can't seem to find where the problem is because I can't seem to wrap my head around that recursive part of the assign part. If I do ever get it fixed ill be sure to share and if I spot anything in the comments ill be sure to let you know. Thank you!

This topic is closed to new replies.

Advertisement