[antlr-interest] Need help with simple grammar
jaluber at gmx.de
Wed Apr 11 06:06:08 PDT 2007
Steve Karam wrote:
> I've never worked with any sort of parsing engine before; I think I am
> getting this, but still getting caught up with the huge amount of
> syntax. Could anyone help me with a basic grammar file that can handle
> these basic types of commands?
> get data from file
> put data in file
> change data in file
> get metadata about file
> change metadata about file
> get dependencies of file
> get dependents of file
> get statistics of file
> Basically it boils down to: command what preposition target. There
> will of course be more than this in the end, but I really need this
> basic understanding first before I can even think about what else I'll
> need to tackle.
> What would a grammar file for this look like? I'd prefer using C++, but
> I don't mind Java if that's all you know!
A basic ANTLR3 grammar without semantic checks (i.e. invalid sentences
still allowed) would be:
: verb object preposition target
You still have to change the target rule to allow arbitrary filenames
and include predicates which filter the invalid sentences out (supposing
all your examples were entirely inclusive). I suggest to buy the Beta
Book (http://www.pragmaticprogrammer.com/titles/tpantlr/index.html) for
more in-depth information.
More information about the antlr-interest