bison

Why am I getting this error: “data definition has no type or storage class”?

五迷三道 提交于 2019-12-18 13:24:46
问题 #include <stdio.h> #include <stdlib.h> struct NODE { char* name; int val; struct NODE* next; }; typedef struct NODE Node; Node *head, *tail; head = (Node*) malloc( sizeof( Node ) ); //line 21 And I compiling like this: cc -g -c -o file.tab.o file.tab.c I'm getting this error message: file.y:21:1 warning: data definition has no type or storage class [enabled by default] 回答1: It looks like the line head = (Node*) malloc( sizeof( Node ) ); //line 21 is outside the main() function. You can't do

Simple Flex/Bison C++

三世轮回 提交于 2019-12-18 11:50:49
问题 I already looked for my answer but I didn't get any quick response for a simple example. I want to compile a flex/bison scanner+parser using g++ just because I want to use C++ classes to create AST and similar things. Searching over internet I've found some exploits, all saying that the only needed thing is to declare some function prototypes using extern "C" in lex file. So my shady.y file is %{ #include <stdio.h> #include "opcodes.h" #include "utils.h" void yyerror(const char *s) { fprintf

Shift Reduce Conflict

99封情书 提交于 2019-12-18 09:38:48
问题 I'm having trouble fixing a shift reduce conflict in my grammar. I tried to add -v to read the output of the issue and it guides me towards State 0 and mentions that my INT and FLOAT is reduced to variable_definitions by rule 9. I cannot see the conflict and I'm having trouble finding a solution. %{ #include <stdio.h> #include <stdlib.h> %} %token INT FLOAT %token ADDOP MULOP INCOP %token WHILE IF ELSE RETURN %token NUM ID %token INCLUDE %token STREAMIN ENDL STREAMOUT %token CIN COUT %token

Shift/reduce conflict with C-like grammar under Bison

北城以北 提交于 2019-12-18 08:53:09
问题 I've been working on a C-like grammar for my personal amusement. However, I've been running into shift/reduce conflicts, and I'm quite sure they could be resolved. Right now my expressions look like this, in a simplified form, stripped of actions: %left '+' '-' %% expr : NUMBER | IDENTIFIER | expr '+' expr | expr '-' expr /* other operators like '*', '/', etc. */ | expr '(' expr ')' /* function call */ %% However, this results in shift/reduce conflicts: the parser is unsure about how to treat

Shift/reduce conflict with C-like grammar under Bison

混江龙づ霸主 提交于 2019-12-18 08:52:40
问题 I've been working on a C-like grammar for my personal amusement. However, I've been running into shift/reduce conflicts, and I'm quite sure they could be resolved. Right now my expressions look like this, in a simplified form, stripped of actions: %left '+' '-' %% expr : NUMBER | IDENTIFIER | expr '+' expr | expr '-' expr /* other operators like '*', '/', etc. */ | expr '(' expr ')' /* function call */ %% However, this results in shift/reduce conflicts: the parser is unsure about how to treat

Creating a separate “boolean expression” rule for a dynamic language

╄→гoц情女王★ 提交于 2019-12-17 20:56:03
问题 I'm creating a grammar in Bison for a simple dynamically-typed language. I have a "general" expression rule, which is somewhat akin to the concept of an rvalue in C; expressions appear on the right-hand side of an assignment, they can also be sent to functions as arguments etc. A greatly simplified version of the rule follows: constantExpression : TOK_INTEGER_CONSTANT | TOK_FLOAT_CONSTANT | stringLiteral ; expression : constantExpression | identifier | booleanExpression | booleanExpression

Bison shift-reduce conflict - Unable to resolve

一笑奈何 提交于 2019-12-17 20:16:07
问题 The grammar is as follows: 1. program -> declaration-list 2. declaration-list -> declaration-list declaration | declaration 3. declaration -> var-declaration | fun-declaration 4. var-declaration -> type-specifier ID ; | type-specifier ID [ NUM ] ; 5. type-specifier -> int | void 6. fun-declaration -> type-specifier ID ( params ) compound-stmt 7. params -> param-list | void 8. param-list -> param-list , param | param 9. param -> type-specifier ID | type-specifier ID [ ] 10. compound-stmt -> {

Advantages of Antlr (versus say, lex/yacc/bison) [closed]

泄露秘密 提交于 2019-12-17 17:23:44
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . I've used lex and yacc (more usually bison) in the past for various projects, usually translators (such as a subset of EDIF streamed into an EDA app). Additionally, I've had to support code based on lex/yacc grammars dating back decades. So I know my way around the tools,

Bison - operator precedence

我怕爱的太早我们不能终老 提交于 2019-12-17 16:40:06
问题 I have a question about operator precedence and associativity in Bison. In every example I see the productions are like expr 'op' expr , for example :http://dinosaur.compilertools.net/bison/bison_8.html But if I would use bison %left and others associativity tools, and I would use grammar like: expr| expr binop expr | expr relop expr | expr logical_op expr and binop: '+' | '-' | '*' | '/' ; relop: EE | NE | LE | '<' | GE | '>' ; logical_op: AND | OR ; would associativity and precedence rules

#error “Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h”

╄→гoц情女王★ 提交于 2019-12-17 16:34:12
问题 I have been trying to follow the tutorial at http://gnuu.org/2009/09/18/writing-your-own-toy-compiler/5/ (using flex, bison and llvm) but when typing the line g++ -o parser parser.cpp tokens.cpp main.cpp I get the following errors: In file included from /usr/local/include/llvm/Support/PointerLikeTypeTraits.h:18:0, from /usr/local/include/llvm/ADT/PointerIntPair.h:17, from /usr/local/include/llvm/IR/Use.h:28, from /usr/local/include/llvm/IR/Value.h:17, from node.h:3, from parser.y:2: /usr