[antlr-interest] Redefinition of header action - in composite grammars for 3.4

Dave Thomas opensource at peoplemerge.com
Tue Nov 22 18:07:30 PST 2011


Hi all,

I'm using ANTLR for my masters thesis, which includes letting user extend
the lex and parser grammars I supply with their own jargon in the form of a
combined grammar.  I wouldn't have dreamed it possible before ANTLR, and
I'm a big fan!

The problem I'm having is:
error(144): JavaDecl.g:3:2: redefinition of header action

The reason this is making me scratch my head is that I see this issue has
been reported, and AFAICT addressed:
http://www.antlr.org/jira/browse/ANTLR-301
http://www.antlr.org/jira/browse/ANTLR-370
http://www.antlr.org/jira/browse/ANTLR-375
http://www.antlr.org/pipermail/antlr-interest/2011-January/040487.html
http://www.antlr.org/wiki/display/ANTLR3/Composite+Grammars (basis for the
examples; sorry for the cross-post)

Am I specifying the antlr release wrong in the maven plugin?

Should I be concerned that my dependency hierarchy includes antlr 2.7.7?
 Per http://www.antlr.org/wiki/display/ANTLR3/ANTLR+3.4+Release+Notes the
dependency on v2 should be removed, but I still see it when I do `mvn clean
antlr3:antlr compile -X`:

[DEBUG]    org.antlr:antlr:jar:3.4:compile
[DEBUG]       org.antlr:antlr-runtime:jar:3.4:compile
[DEBUG]          org.antlr:stringtemplate:jar:3.2.1:compile
[DEBUG]          antlr:antlr:jar:2.7.7:compile


src/main/antlr3/test/JLex.g

lexer grammar JLex;
@lexer::header { package test; }

INT : 'int';
SEMICOLON : ';';
EQUALS : '=';
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;


src/main/antlr3/test/JavaDecl.g

parser grammar JavaDecl;
@header { package test; }
type : INT ;
decl : type ID SEMICOLON
     | type ID init SEMICOLON
     ;
init : EQUALS INT ;


src/main/antlr3/test/Java.g:

grammar Java;
import JavaDecl, JLex;
@header { package test; }
prog : decl ;
type : 'int' | 'float' ;

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
 <artifactId>test</artifactId>
<packaging>jar</packaging>
 <version>1.0-SNAPSHOT</version>
<name>test</name>
 <build>
<plugins>
<plugin>
 <groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
 <version>3.4</version>
<executions>
<execution>
 <configuration>
<goals>
<goal>antlr</goal>
 </goals>
</configuration>
</execution>
 </executions>
</plugin>
</plugins>
 </build>
</project>


More information about the antlr-interest mailing list