[antlr-interest] Composite tree grammar
Bill Andersen
andersen at ontologyworks.com
Thu Oct 9 17:02:26 PDT 2008
Gavin,
Yeah, I goofed the line numbers up. Here are the files again. My
question is whether the syntax is correct. I can't see anything
wrong. Thanks for any help.
grammar Foo;
options {
output=AST;
}
tokens {
FOO = 'foo';
BAR = 'bar';
ZAP;
}
start
: FOO BAR EOF
-> ^(ZAP FOO BAR)
;
----------------------
tree grammar FooAST;
options {
ASTLabelType=CommonTree;
tokenVocab=Foo;
output=AST;
}
start
: ^(ZAP FOO BAR)
-> ^(ZAP BAR FOO)
;
----------------------
tree grammar Import;
import FooAST;
options {
ASTLabelType=CommonTree;
tokenVocab=Foo;
output=AST;
}
start
: ^(ZAP FOO BAR)
-> ^(ZAP FOO BAR)
;
On Oct 9, 2008, at 02:41 , Gavin Lambert wrote:
> At 06:02 8/10/2008, Bill Andersen wrote:
> >I want to use grammar import on tree grammars and did the test
> >below using ANTLRWorks 1.2. I wrote a simple grammar (Foo) to
> >output an AST, a tree grammar (FooAST) to parse the latter,
> >and another (FooASTImport) that imports FooAST and attempts to
> >override the one rule in FooAST. Code here. I get a syntax
> >error (in attached snapshot) but can't see where I'm going
> >wrong. Any help appreciated.
> [...]
> >tree grammar FooAST;
> >options {
> > tokenVocab=Foo;
> > output=AST;
> >}
> >start
> > : ^(ZAP FOO BAR)
> > -> ^(ZAP BAR FOO)
> > ;
>
> Given that the attached screenshot reports an error on line 10 of
> FooAST.g, and there doesn't appear to be that many lines in the
> file, I suspect some kind of EOL problem.
>
> Especially since you're on MacOS. Maybe the file is being saved
> with Mac CR-only line endings (or some other strange construction),
> while ANTLR requires either LF-only or CRLF.
>
Bill Andersen
Ontology Works, Inc. (www.ontologyworks.com)
3600 O'Donnell Street, Suite 600
Baltimore, MD 21224
Office: +1.410.675.1201
Cell: +1.443.858.6444
Fax: +1.410.675.1204
More information about the antlr-interest
mailing list