0
votes

I have two parser grammars (lets call them A.g and B.g). Now I want to import the Grammar B into the Grammar A. Here is what they two grammars look like: GRAMMAR A:

parser grammar A;

options {
   tokenVocab = testLexer;
}

import B;

@header {
  package com.splendit.pli2uct;
}
rule
  :  ImpLexRule1 | subRule ;

GRAMMAR B:

parser grammar B;


@header {
  package com.splendit.pli2uct;
}
subRule: ImpLexRule2 ;

But when I build the java Classes from the grammar files (no matter if i do this with antlr ide or with the antlr-maven-plugin) I'm getting the following error: error(144): B.g:11:2: redefinition of header action

But when I leave the header Definition in the B.g Grammar then the generated Java Class has an error because there is noch package Definition at the beginning of the file. Can anybody help me with this problem? I have really no idea what I'm doing wrong.

Thnaks in advance Bernhard

1

1 Answers

1
votes

A solution for your problem might be:

  • Throw out your @header definitions.

  • Build .java files with ANTLR Tool by command:

    java org.antlr.v4.Tool -package com.splendit.pli2uct

Reason for the error when you leave your @header in, is that the ANTLR Tool combines the two grammars, so it is nearly the same as if you put it in one file.

Have fun with ANTLR, its a very nice Tool