Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically-Scoped Attributes generate error(33): missing code generation template SetNonLocalAttrHeader ONLY in C++ target. #4372

Open
Kameneth opened this issue Aug 2, 2023 · 0 comments

Comments

@Kameneth
Copy link

Kameneth commented Aug 2, 2023

Target: c++
Generating parser code with ANTLR 4.13.0
Expected behavior: does not trigger any error .
Actual behavior: triggers an error(33): missing code generation template SetNonLocalAttrHeader

The DynScope grammar from the doc triggers the error. (from "Actions and Attributes" chapter, exactly as it is in it.)

antlr4 -Dlanguage=Java DynScope.g4 works

antlr4 -Dlanguage=PHP DynScope.g4 works

antlr4 -Dlanguage=JavaScript DynScope.g4 works

antlr4 -Dlanguage=Cpp DynScope.g4 does not work and generate the error(33).

Here is a simplified version of the grammar that triggers the same error:

grammar DynScope;
 
prog: block ;
 
block locals [int myInt = 0;]
	: '{' decl* '}' 
;

decl: 
  'int' INT {$block::myInt += 1;} ';'
;

INT : [0-9]+ ;
WS : [ \t\r\n]+ -> skip ;

if i just comment the {$block::myInt+=1;} ';', no errors is triggered.
like that:

grammar DynScope;
 
prog: block ;
 
block locals [int myInt = 0;]
	: '{' decl* '}' 
;

decl: 
  'int' INT // {$block::myInt += 1;} ';' 
;

INT : [0-9]+ ;
WS : [ \t\r\n]+ -> skip ;

replacing {$block::myInt += 1;} by {((BlockContext*)$ctx->parent)->myInt +=1 ;} seems to work properly.

@Kameneth Kameneth changed the title Dynamically-Scoped Attributes generate error(33): missing code generation template SetNonLocalAttrHeader in C++ target. Dynamically-Scoped Attributes generate error(33): missing code generation template SetNonLocalAttrHeader ONLY in C++ target. Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant