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

Incorrect D code generated when enabling locations. #81

Closed
streaksu opened this issue Nov 17, 2021 · 1 comment
Closed

Incorrect D code generated when enabling locations. #81

streaksu opened this issue Nov 17, 2021 · 1 comment

Comments

@streaksu
Copy link

Hello,

When generating a parser for the following file with location support:

%language "D"
%define api.parser.class {Parser}
%locations

/* Types the parser handles for return and input */
%union {
    AST           tast;
    Declaration[] tdecls;
    Declaration   tdecl;
    Statement[]   tstmts;
    Statement     tstmt;
    Type          ttype;
    string        str;
    char          chr;
    long          lng;
    double        dbl;
}

/* Single-char token declarations */
%token SEMICOLON    ";"
       PERIOD       "."
       OPENPAREN    "("
       CLOSEPAREN   ")"
       OPENBRACE    "{"
       CLOSEBRACE   "}"
       OPENBRACKET  "["
       CLOSEBRACKET "]"
       PLUS         "+"
       MINUS        "-"
       ASTERISK     "*"
       SLASH        "/"

/* Keywords */
%token RETURN "return"
       VOID   "void"
       INT    "int"
       FLOAT  "float"
       CHAR   "char"
       STRING "string"

/* Values */
%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.

@streaksu
Copy link
Author

Moving it to bug-bison@gnu.org, sorry for not noticing the other channel for bug reporting.

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