[antlr-interest] Newbie with a simple problem

Tom Hicks headhunter3 at gmail.com
Mon Feb 27 10:37:45 PST 2012

I need to implement a fairly simple scripting language for a project
I'm working on and I'm trying to use antlr to help.

I'm not sure if antlr is the right tool for this so I'm going to start
by explaining how I'm trying to use the script.
Each line is either whitespace, a directive, or an action.
Whitespace is only for readability and when I load the script should be ignored.
Actions are things like show a message box, play a bgm, or change the
current character and background images.  There are more but they are
all implemented the same way.
Directives are used to set options on groups of actions.  Each action
has a play condition so if I put a message box action after an "#if
HasHadConversation dlg_darren_photos" directive and before the
corresponding "#endif" directive, then the action should have it's
playcondition set to "HasHadConversation dlg_darren_photos" Which is
another data model object.
I can explain that in more detail if necessarry, but I don't want to
make this too long.

When I load the script file I want to generate a list of the
appropriate actions.  I have this working except for the directives
just using regular expressions, unfortunately the logical expressions
in the directives can't be matched to regular expressions.
So I started looking at parser generators but everything else I've
found expects that I'm familiar with bison/lex and I'm not.  Antlr
looks far more friendly and supports C# which is what I need.

I tried writing a grammar for the script other than an extremely
trivial example I'm completely stumped.

When I use the following grammar with the input "_SC play test 01"
(without the quotes). I get a NoViableAltException.  "_SC stop" works
grammar PBScript;
options {
output = AST;

line	:	'_SC stop'
	|	'_SC play ' ASSETNAME
	:	(~('\n'|'\r'))+ ;

If instead I use this grammar it works but captures the space as part
grammar PBScript;
options {
output = AST;

line	:	'_SC stop'
	|	'_SC play' ASSETNAME
	:	' '(~('\n'|'\r'))+ ;


More information about the antlr-interest mailing list