[antlr-interest] Composite tree grammar

Bill Andersen andersen at ontologyworks.com
Tue Oct 7 10:02:06 PDT 2008


Folks,

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.

	.bill

grammar Foo;
options {
	output=AST;
}
tokens {
	FOO = 'foo';
	BAR = 'bar';
	ZAP;
}
start
	: FOO BAR
		-> ^(ZAP FOO BAR)
	;
	
-----------------------------------

tree grammar FooAST;
options {
	tokenVocab=Foo;
	output=AST;
}
start
	: ^(ZAP FOO BAR)
		-> ^(ZAP BAR FOO)
	;

-----------------------------------

tree grammar FooASTImport;
import FooAST;

options {
	tokenVocab=Foo;
	output=AST;
}

start
	: ^(ZAP FOO BAR)
		-> ^(ZAP FOO BAR)
	;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedGraphic.png
Type: image/png
Size: 20289 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20081007/b0be80d7/attachment.png 
-------------- next part --------------



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