MOAIParser Bug

Discussion about using Moai SDK - post questions, bugs and issues here.

Moderators: seebs, franciscotufro

MOAIParser Bug

Postby rhoster » Sun Jun 17, 2012 10:54 am

I was trying to write the compiler for our game design files last night and found that there is a bug with MOAIParser. I have a grammar for a game design language that we use internally to define our game props; this was built using Gold Parser Builder and tests out fine in the test window with some example text.

When I load the CGT file and try to parse the same text using MOAIParser, I get nothing. The sample grammar that is included still works fine, but my custom one doesn't. I've tweeted Devin Cook about it (the guy who built Gold and added support for MOAI I believe) to let him know, but if anyone is planning on using this, I wouldn't count on it right now. That being said, I'm just going to write a compiler in Java that exports files in Lua Table format for me to import into our game (Gold has a skeleton Java program that it can export).

Does anyone else use MOAIParser? Have you gotten it to work with a custom grammar table?
User avatar
rhoster
 
Posts: 193
Joined: Sat May 26, 2012 3:59 pm
Location: Santa Barbara, CA

Re: MOAIParser Bug

Postby rhoster » Tue Jun 19, 2012 1:39 pm

The more I look into this, the more I think that there isn't a problem with MOAIParser, but instead with the cgt file I was providing. When I took a look at it, it showed up as mojibake which leads me to believe that there is an issue with the compilation process and the encoding on my machine. I'm going to try compiling to CGT another way using an XML dump of the grammar tables and see if it works.
User avatar
rhoster
 
Posts: 193
Joined: Sat May 26, 2012 3:59 pm
Location: Santa Barbara, CA

Re: MOAIParser Bug

Postby dana » Tue Jun 19, 2012 1:42 pm

Keep me updated! If you find that there is an issue with MOAIParser, then I will look into it.
User avatar
dana
Site Admin
 
Posts: 200
Joined: Fri Mar 02, 2012 6:10 pm
Location: Zipline Games

Re: MOAIParser Bug

Postby rhoster » Tue Jun 19, 2012 3:16 pm

I think I have it figured out. The MOAIParser is working fine - it's just that the CGT file you use must not have any warnings in it. Gold Parser Builder lets you parse past some conflicts but it seems that the MOAI implementation doesn't have support to auto-correct the warnings. I'm going through and rewriting our grammar so that I don't have any production conflicts (actually helping me become a better grammar writer).
User avatar
rhoster
 
Posts: 193
Joined: Sat May 26, 2012 3:59 pm
Location: Santa Barbara, CA

Re: MOAIParser Bug

Postby rhoster » Tue Jun 19, 2012 5:57 pm

Final confirmation - this was a mistake in the CGT file. I'm not exactly sure where the problem was, but I can now get it to parse my grammar and I have an expression (which is both left/right recursive), but it still parses it - even though Gold Parser Builder throws up a warning.

My takeaway - write better grammars and test them as you add productions. Also - java compilers are a pain in the ass to write from scratch, you're better off tweaking your grammar and grabbing the AST in lua.
User avatar
rhoster
 
Posts: 193
Joined: Sat May 26, 2012 3:59 pm
Location: Santa Barbara, CA

Re: MOAIParser Bug

Postby ibisum » Wed Jun 20, 2012 12:29 am

I'm really curious how you're using CGT in the context of MOAI - maybe you want to enlighten us how you will use your custom parser?
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info
User avatar
ibisum
 
Posts: 1005
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

Re: MOAIParser Bug

Postby rhoster » Wed Jun 20, 2012 4:16 pm

Sure - the intent behind using a Parser/Compiler combo for our game logic comes from three desires:

1. Reusability :: by creating a bunch of abstract logic, we are able to reuse it amongst multiple games or in multiple objects for the same game.

2. Reliability :: by crunching your game logic through a parser, you eliminate all the typographical and lexical mistakes that can occur. By adding the compiler, you eliminate game logic errors (e.g. by checking ahead of time that your references exist).

3. Efficiency :: by compiling your game logic into raw data that can be processed by the game engine, you get maximum efficiency. Our game engine is designed to know absolutely nothing about what it is doing. It's just a number cruncher. That way, it focuses on the things that it can do very well and is easier to debug.

The workflow advantages to having your designers work in a formal language are hugely beneficial as well. If you're interested in trying this approach yourself, download Gold Language Parser (http://goldparser.org/) and start by writing a simple grammar that describes some data in your game. The beauty of Gold is that you don't have to actually write an IDE for your designers - you simply give them a copy of the .grm or .cgt files and they can use the test window to parse their code and check for errors. THIS IS HUGE! Now you can be sure that all the design files that you get from artists, level designers, etc. work without having to doublecheck them.

The way it ties back into MOAI is that you load your .cgt in MOAI and create your own traversal functions (the example for MOAIParser is flawless and is a great template for a compiler) to add flavor to the parse tree - meaning you keep track of all the stuff that is important (like whether or not a reference to some variables exists when it is called, etc.) depending on the tokens. But it isn't just reliability that you achieve, you also are able to create a very efficient, abstract representation of your parse tree that you can use in your game engine.

I hope this explains a little about the reasoning for creating a custom grammar for your game logic or data files. I'm happy to answer any other questions!
Last edited by rhoster on Fri Jun 22, 2012 2:10 pm, edited 2 times in total.
User avatar
rhoster
 
Posts: 193
Joined: Sat May 26, 2012 3:59 pm
Location: Santa Barbara, CA

Re: MOAIParser Bug

Postby ibisum » Fri Jun 22, 2012 12:25 am

Sounds great - I'd love to see an example, or maybe some code snippets, that shows how you would use this practically ..
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info
User avatar
ibisum
 
Posts: 1005
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

Re: MOAIParser Bug

Postby rhoster » Fri Jun 22, 2012 1:59 pm

No problem! I decided to move this to its own topic (since the name MOAIParser Bug was bothering me since there isn't actually a bug).

writing-a-custom-grammar-and-moaiparser-t913/
Last edited by rhoster on Fri Jun 22, 2012 3:19 pm, edited 22 times in total.
User avatar
rhoster
 
Posts: 193
Joined: Sat May 26, 2012 3:59 pm
Location: Santa Barbara, CA

Re: MOAIParser Bug

Postby rhoster » Fri Jun 22, 2012 2:06 pm

So, I didn't really answer your practical part :) Here is an example of a the spatial definition that we use to define objects in 3d. You start by giving the height map for all points on a 2d plane. Then you add and subtract boxes from that to generate your spatial representation. I won't do an explanation on this one, but hopefully you can see how it's useful for defining spatial definitions (one component of our prop definition).

Code: Select all
  1. <spatial_definition> ::= <prop_size> <height_map_table> <terrain_table>



Code: Select all
  1. <prop_size> ::= 'size:' <point>



Code: Select all
  1. <height_map_table> ::= 'height_map:' <height_map_list>

  2. <height_map_list> ::= <height_map_list> ',' <height_map> | <height_map>

  3. <height_map> ::= non_negative_integer



Code: Select all
  1. <terrain_table> ::= <diff_table> <add_table>

  2. <diff_table> ::= 'diff_table:' <box_table>

  3. <add_table> ::= 'add_table:' <box_table>

  4. <box_table> ::= <box_list> | <nil>

  5. <box_list> ::= <box_list> <box> | <box>

  6. <box> ::= <point> <point> ';'



Code: Select all
  1. <point> ::= point



** the text below is also code, but can't use the bbcode because of square brackets **

point = '[' '-'? {Number}+ ',' '-'? {Number}+ ',' '-'? {Number}+ ']'
User avatar
rhoster
 
Posts: 193
Joined: Sat May 26, 2012 3:59 pm
Location: Santa Barbara, CA


Return to Moai SDK

Who is online

Users browsing this forum: No registered users and 1 guest

x