Reputation: 61
I am relatively new to ANTLR, I have a current project that needs to be merged from ANTLR3 (version 3.5) to ANTLR4. I have gone thru the book and tried the demo, this all works fine, but my own project gives me the following problem:
After converting a ANTRL3 project to ANTLR4 project (resolving all warnings and errors) I was able to build the lexer.h and lexer.cpp file but the following errors come up: error(33): missing code generation template NonLocalAttrRefHeader error(33): missing code generation template SetNonLocalAttrHeader (about 50 times). I haven't been able to find any references of these templates anywhere. Is there anybody who can shed any light on these error messages? Because they don't say anything about line no's or reference any other code I'm completely in in the dark where to look.
I've set up a test environment, testing the demo g4 files. I have pulled the g4 file out of my (VS2017) project and tried it seperately using batch files.
Because of the lack of references I can't show the actual piece of code that is the cause. I have tried a partial parse, but I haven't been able to get any clues from that.
These errors are shown: error(33): missing code generation template NonLocalAttrRefHeader error(33): missing code generation template SetNonLocalAttrHeader
I've constructed a small example to demonstrate the problem:
/*
* AMF Syntax definition for ANTLR.
*
*/
grammar amf;
options {
language = Cpp;
}
amf_group[amf::AmfGroup& amfGroup] locals [int jsonScope = 2]
: statements=amf_statements (GROUPSEP WS? LINE_COMMENT? EOL? | EOF)
{
amfGroup.SetStatements(std::move($statements.stmts));
}
;
amf_statements returns [amf::AmfStatements stmts]
: ( WS? ( stmt=amf_statement { stmts.emplace_back(std::move($stmt.value)); } WS? EOL) )*
;
amf_statement returns [amf::AmfStatementPtr value]
: (
{$amf_group::jsonScope == 1}? jsonparent_statement
| {$amf_group::jsonScope == 2}? jsonvalue_statement
)
{
value = std::move(context.expression(0).value);
}
;
jsonparent_statement returns [amf::AmfStatementPtr value] locals [int lineno=0]
:
(T_JSONPAR { $lineno = $T_JSONPAR.line;} ) WS (arg=integer_const)
{
value = std::make_shared<amf::JSONParentStatement>($lineno, nullptr);
}
;
jsonvalue_statement returns [amf::AmfStatementPtr value] locals [int lineno=0]
: ( T_JSONVALUE { $lineno = $T_JSONVALUE.line; } ) WS (arg=integer_const) (WS fmt=integer_const)?
{
value = std::make_shared<amf::JSONValueStatement>($lineno, std::move(arg), std::move(fmt));
}
;
integer_const returns [amf::AmfArgPtr value]
: p='%' (
(signed_int)
{
long num = std::stol($signed_int.text);
value = std::make_shared<amf::AmfArg>(ARG_TYPE::ARG_INTEGER, num);
}
| signed_float
{
value = std::make_shared<amf::AmfArg>(ARG_TYPE::ARG_INTEGER, std::stof($signed_float.text));
}
)
;
signed_int
: MINUS? INT;
signed_float
: MINUS? FLOAT;
T_JSONPAR : 'JSONPAR' | 'JSONPARENT';
T_JSONVALUE : 'JSONVAL' | 'JSONVALUE';
/* Special tokens */
GROUPSEP : '%%';
MINUS : '-';
INT : DIGIT+;
FLOAT
: DIGIT+ '.' DIGIT* EXPONENT?
| '.' DIGIT+ EXPONENT?
| DIGIT+ EXPONENT
;
ID : ('A'..'Z'|'_') ('A'..'Z'|'0'..'9'|'_')*
;
COMMENT
: ('/*' .*? '*/') -> channel(HIDDEN)
;
LINE_COMMENT
: ('//' ~('\n'|'\r')* '\r'?) -> channel(HIDDEN)
;
EOL : ('\r'? '\n');
QOUTED_STRING
: '"$' ( ESC_SEQ | ~('\\'|'"') )* '"'
;
SIMPLE_STRING
: '$' ~(' '|'\t'|'\r'|'\n')*
;
WS : (' '|'\t')+;
fragment
DIGIT
: '0'..'9'
;
fragment
EXPONENT
: 'E' ('+'|'-')? ('0'..'9')+
;
fragment
ESC_SEQ
: '\\' (
'R'
|'N'
|'T'
|'"'
|'\''
|'\\'
)
;
The error occurs as soon as I add the predicates for the amf_statement (in this case 4 times "missing code generation template for NonLocalAttrTefHeader)". I have tried changing the output language to Python or CSharp, but this doesn't help.
Upvotes: 3
Views: 427
Reputation: 61
After carefully looking at all the steps I stumbled on a small but critical difference in the batch command that executes the java command: I used a copy of my former antrl3 batch file that uses the java -jar option to execute the antlr-4.7.2-complete.jar instead of cp and executing the org.antlr.v4.Tool. All seems to go well, the command line options are displayed well, the syntax errors are all in place, until the actual lexer and parser code are created: then the error(33) is displayed, but only if dynamic scoping is used, otherwise all seems to go well.
Update: I thought I could proceed with my project, but this is only a partial solution: when I switched back to Cpp output, the errors returned. Standard output anf CSharp output is okay, as soon I attempt to generate Cpp output I receive the same errors, again when using dynamic scoping: lines 25 and 26. If I remove the predicates, the errors disappear.
So I'm still stuck with these errors, but only for C++.
Upvotes: 2