bison

Problem calling std::max

十年热恋 提交于 2019-11-28 16:57:33
I compiled my bison-generated files in Visual Studio and got these errors: ...\position.hh(83): error C2589: '(' : illegal token on right side of '::' ...\position.hh(83): error C2059: syntax error : '::' ...\position.hh(83): error C2589: '(' : illegal token on right side of '::' ...\position.hh(83): error C2059: syntax error : '::' The corresponding code is: inline void columns (int count = 1) { column = std::max (1u, column + count); } I think the problem is with std::max; if I change std::max to equivalent code then there is no problem anymore, but is there a better solution instead of

goto label in the same loop in Bison

隐身守侯 提交于 2019-11-28 14:22:36
I am making a parser with Bison and Flex and I want to create a "goto label" statement, but I want to check if the label exists in the same block of code (between brackets { }, loop, etc). Is there a function that checks such things? Your question implies that you are missing some background context in building language translators/compilers, so perhaps a small tutorial will assist you in solving your problem. I hope you don't mind. The processing of computer languages is conventionally divided up into a sequence of steps (sometimes called phases or passes). Each step handles a component of

bison only reads one line [closed]

我的梦境 提交于 2019-11-28 13:03:25
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . I'm doing a simple calculator with flex and bison but it only reads the first line of the input file. this is my bison code: %{ #include <stdio.h> #include <stdlib.h> #include <math.h> #include "symtab.h" extern int yylex(void); extern char *yytext; extern int num_linea; extern FILE *yyin; void

Bison shift-reduce conflict - Unable to resolve

本秂侑毒 提交于 2019-11-28 11:39:11
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 -> { local-declarations statement-list } 11. local-declarations -> local-declarations var-declarations |

Bison Shift/reduce error for C-like language

≡放荡痞女 提交于 2019-11-28 10:02:08
问题 I'm having an issue with my bison grammar, it is giving me shift/reduce errors, and I have already defined precedence for the operators. I know that it is cause by the 'expr binop expr' bit of the expr rule. Here is my bison file, and the output I get. Any help would be very much appreciated. %token ID KEYWORD INTCON FLOATCON TYPE STRING %token IF WHILE FOR VOID RETURN %token AND_OP OR_OP EQ_OP NEQ_OP LEQ_OP GEQ_OP %left OR_OP %left AND_OP %nonassoc '<' LEQ_OP '>' GEQ_OP EQ_OP NEQ_OP %left '+

parse bibtex with flex+bison: revisited

久未见 提交于 2019-11-28 06:51:39
问题 For last few weeks, I am trying to write a parser for bibtex (http://www.bibtex.org/Format/) file using flex and bison. $ cat raw.l %{ #include "raw.tab.h" %} value [\"\{][a-zA-Z0-9 .\t\{\} \"\\]*[\"\}] %% [a-zA-Z]* return(KEY); \" return(QUOTE); \{ return(OBRACE); \} return(EBRACE); ; return(SEMICOLON); [ \t]+ /* ignore whitespace */; {value} { yylval.sval = malloc(strlen(yytext)); strncpy(yylval.sval, yytext, strlen(yytext)); return(VALUE); } $ cat raw.y %{ #include <stdio.h> %} //Symbols.

Make bison start parsing with a rule other than the start rule

社会主义新天地 提交于 2019-11-28 05:50:52
问题 Currently I'm working on a source-to-source compiler and I have already written a bison parser that creates the AST for the input correctly. I need to do several transformations on the syntax tree now and therefore I need to insert many nodes to the tree. I could create all the structs/unions that I want to add to the syntax tree manually, but this seems to be very much work. It would be much easier for me to create a string and I want this string to be parsed by the parser I already have.

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

你说的曾经没有我的故事 提交于 2019-11-28 02:35:11
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, though I'm no expert. I've seen positive comments about Antlr in various fora in the past, and I'm curious as to what I may be missing. So if you've used both, please tell me what's better or more advanced in Antlr. My current constraints are that I work in a C++ shop, and any product we ship will not include Java, so the

freeing the string allocated in strdup() from flex/bison

时间秒杀一切 提交于 2019-11-28 00:49:51
问题 I have flex code that copies a string lexeme using strdup() . %{ #include "json.tab.h" #define YY_DECL extern "C" int yylex() %} %option noyywrap %% [ \t\n]+ ; \"[a-zA-Z]+\" {yylval.sval = strdup(yytext); return STRING; } [0-9]+ {yylval.ival = atoi(yytext); return NUMBER; } . {return yytext[0];} ; %% strdup() allocates memory and copies the input string into it and return (strdup() - what does it do in C?), so I guess I need to free it up when I don't need it anymore. From this post:When is

Include struct in the %union def with Bison/Yacc

笑着哭i 提交于 2019-11-27 20:37:19
I am trying to include a struct as part of the union with Bison, but I get an error on the 'struct node args' in %union: parser.y:17: error: field ‘args’ has incomplete type The Code: struct node { char * val; struct node * next; }; %} %union { char * string; struct node args; } %token <string> CD WORD PWD EXIT %type <args> arg_list Anyone know what I am doing wrong? Even better, use the %code directive with the "requires" option, i.e.: %code requires { struct node { char * val; struct node * next; }; } %union { char * string; struct node args; } This will include the code in the "requires"