[antlr-interest] Newbie with a simple problem
Martijn Reuvers
martijn.reuvers at gmail.com
Mon Feb 27 10:47:50 PST 2012
Hello Tom,
First: don't use literals (the strings) in parser rules, this always
gives problems sooner or later and makes error reporting bad - use
real tokens instead.
To skip whitespace between tokens (you can also write it to a hidden
channel if you need it later):
WS
: (' ' | '\t' | '\n' | '\r')+
{ skip(); }
;
Regards,
Martijn
On Mon, Feb 27, 2012 at 7:37 PM, Tom Hicks <headhunter3 at gmail.com> wrote:
> 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
> though
> grammar PBScript;
> options {
> output = AST;
> }
>
> line : '_SC stop'
> | '_SC play ' ASSETNAME
> ;
> ASSETNAME
> : (~('\n'|'\r'))+ ;
>
> If instead I use this grammar it works but captures the space as part
> of ASSETNAME
> grammar PBScript;
> options {
> output = AST;
> }
>
> line : '_SC stop'
> | '_SC play' ASSETNAME
> ;
> ASSETNAME
> : ' '(~('\n'|'\r'))+ ;
>
> ~Tom
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list