bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Broken code generated when enabling locations using D


From: cristiansimon
Subject: Broken code generated when enabling locations using D
Date: Wed, 17 Nov 2021 18:32:40 +0000

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]