Hello Akim and Cristian, I can't reproduce the issue. What version of ldc2 are you using, Cristian?
The error message sends me to 'yy_semantic_null', which is used only here [0]. It makes sense that the code complains only when locations are used, because only then it is outputted by Bison. I initially thought that it complained because yy_semantic_null, an immutable value, *could* theoretically be modified by other functions, like here [1], where it is provided through the ref keyword, but I don't get any compilation error. I added a dummy lexer, and I am getting a syntax error, so the code in question is reached. I even added a push instruction with yy_semantic_null at the beginning of the parse function, and the program compiles and runs. Cristian, can you please give me more details? Adela [0]: https://github.com/akimd/bison/blob/master/data/skeletons/lalr1.d#L758 [1]: https://github.com/akimd/bison/blob/master/data/skeletons/lalr1.d#L1308 În dum., 21 nov. 2021 la 14:29, Akim Demaille <a...@lrde.epita.fr> a scris: > Hi Cristian, > > Adela, could you have a look at this please? > > > Le 17 nov. 2021 à 19:32, cristiansimon <cristiansi...@protonmail.com> a > écrit : > > > > Hello, > > > > When generating a parser for the following file with location support > using GNU Bison 3.8.2: > > > > %language "D" > > %define api.parser.class {Parser} > > %locations > > > > %union { > > AST tast; > > Declaration[] tdecls; > > Declaration tdecl; > > Statement[] tstmts; > > Statement tstmt; > > Type ttype; > > string str; > > char chr; > > long lng; > > double dbl; > > } > > > > %token SEMICOLON ";" > > PERIOD "." > > OPENPAREN "(" > > CLOSEPAREN ")" > > OPENBRACE "{" > > CLOSEBRACE "}" > > OPENBRACKET "[" > > CLOSEBRACKET "]" > > PLUS "+" > > MINUS "-" > > ASTERISK "*" > > SLASH "/" > > > > %token RETURN "return" > > VOID "void" > > INT "int" > > FLOAT "float" > > CHAR "char" > > STRING "string" > > > > %token <str> IDENTIFIER STRINGVALUE > > %token <chr> CHARACTER > > %token <lng> INTEGER > > %token <dbl> FLOATVALUE > > > > %% > > ast : /* Empty*/ > > | declarations > > ; > > > > declarations : declaration > > | declaration declarations > > ; > > > > declaration : type IDENTIFIER "(" ")" "{" statements "}" > > ; > > > > statements : statement > > | statement statements > > ; > > > > statement : "return" ";" > > ; > > > > type : "void" > > ; > > %% > > > > struct AST {} > > class Declaration {} > > class Statement {} > > final class Function : Declaration {} > > final class Return : Statement {} > > enum Type {} > > > > Compiling the generated code yields the following error, which does not > happen when not enabling locations: > > > > cdc.p/parser.d(764): Error: function `parser.Parser.YYStack.push(int > state, YYSemanticType value, ref YYLocation loc)` is not callable using > argument types `(int, immutable(YYSemanticType), YYLocation)` > > cdc.p/parser.d(764): cannot pass argument `yy_semantic_null` of > type `immutable(YYSemanticType)` to parameter `YYSemanticType value` > > cdc.p/parser.d(765): Error: function `parser.Parser.YYStack.push(int > state, YYSemanticType value, ref YYLocation loc)` is not callable using > argument types `(int, immutable(YYSemanticType), YYLocation)` > > cdc.p/parser.d(765): cannot pass argument `yy_semantic_null` of > type `immutable(YYSemanticType)` to parameter `YYSemanticType value` > > > > using ldc2. > > > > Removing the user-defined classes from the union seems to fix it, but > this cannot be done in the original code as they serve a purpose there. > > > > What is there at fault here? What could be a fix for this issue? Thanks > in advance. > > > >