[antlr-interest] Newbie with a simple problem

Eric researcher0x00 at gmail.com
Mon Feb 27 14:02:52 PST 2012

Hi Tom,

I am not going to try and give you an answer to your specific problem,
instead I would suggest that if the following terms are concepts that you
can not explain to someone else and feel confident, then you need to do
some reading. Parsing is not something most people can pick up without
learning the concepts first. Until you are comfortable with them, you will
just be beating your head against a wall.

The terms are: scanner, tokenization, token stream, paring, AST, ambiguous
grammar, lookahead, context free, BNF, extended BNF, recursive descent
That should get you going, and for more advanced terms see:

I would suggest getting a copy of Ter's book:
If you are really serious, then also get  the dragon book:

When I started learning ANTLR at ver 2.x, the book did not exist. When I
came back to ANTLR after a few years, the first thing I did was buy the
book. Be aware the the book references a version of ANTLR around 3.1, and
the ANTLR 2.x and 4.x are not close enough to it to use the book.

Also a big help early on is to use ANTLRWorks:
http://www.antlr.org/works/index.html  This will require you to use Java,
but since you know C#, the trade off of using Java for learning concepts is
worth the price of admission. Once you get the concepts down, you can then
use C# for the real problems.

Basically take smaller steps to get the concepts down, before jumping into
the deep end.

Hope that helps, Eric

On Mon, Feb 27, 2012 at 1: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
>        ;
>        :       (~('\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'))+ ;
> ~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