1

I am using one .g file for both lexer and parser. I have the following lines in the grammar file:

@header {
package foo.bar;
}

However I found that package line is only put into the generated parser source file, and missing in the FooLexer.java file. Anyone know how to deal with this?

4

1 回答 1

7
@header {
package foo.bar;
}

is short for:

@parser::header {
package foo.bar;
}

To put a package declaration in the lexer, do:

@lexer::header {
package foo.bar;
}

The same goes for @members { ... }, which is short for @parser::members { ... }. There's also @lexer::members { ... } to put variables/methods etc. in the lexer.

于 2012-06-26T07:23:34.877 回答