bison

How to increase stack size in bison (and solve “memory exhausted”)

馋奶兔 提交于 2019-12-01 17:17:06
My bison-based parser started choking on some moderately sized files I've generated recently. It throws an exception about "memory exhausted." The bison man page says that this is likely due to use of right-hand recursion. Without trying to rewrite the grammar (I am on a tight deadline), I would like to simply increase the stack to get the parser to parse this file. I tried to follow the bison man page and #define YYMAXDEPTH to some number larger than the default 10000, but that didn't work. When I look at the output from bison, it seems like YYMAXDEPTH is only conditionally used when YYSTACK

How to increase stack size in bison (and solve “memory exhausted”)

家住魔仙堡 提交于 2019-12-01 16:10:54
问题 My bison-based parser started choking on some moderately sized files I've generated recently. It throws an exception about "memory exhausted." The bison man page says that this is likely due to use of right-hand recursion. Without trying to rewrite the grammar (I am on a tight deadline), I would like to simply increase the stack to get the parser to parse this file. I tried to follow the bison man page and #define YYMAXDEPTH to some number larger than the default 10000, but that didn't work.

Thread-safe / reentrant bison + flex

瘦欲@ 提交于 2019-12-01 14:57:00
I would really prefer a working example to any explanation. Whatever I read so far on Bison's documentation site contradicts whatever Flex says. One says to declare yylex as int yylex (yyscan_t yyscanner); another one wants it to be: int yylex(YYSTYPE *lvalp, YYLTYPE *llocp); What I really need is the location information. I'm not sure as of yet if I need YYSTYPE (I don't have a use for this information right now, but maybe in the future I will). Unrelated to the above, and as a bonus, I'd be interesting to know why this infrastructure is so bad. It seems like such a straight-forward thing to

Flex newline scanning for bison

一笑奈何 提交于 2019-12-01 13:42:32
I'd like to use the same flex/bison scanner/parser for an interpreter and for loading a file to be interpreted. I can not get the newline parsing to work correctly in both cases. Interpreter: There is a prompt and I can enter commands terminated by pressing ENTER. File: Here is an example input file: -----cut--------- begin( print("well done"), 1) ----cut------- So, there is a newline in the first line and after the '(' that should be eaten. In my scanner.l I have %% [ \t] { errorLineCol += strlen(yytext); } \n { errorLineNumber++; errorLineCol = 0; } ("-"?[0-9])[0-9]* { errorLineCol += strlen

Flex newline scanning for bison

三世轮回 提交于 2019-12-01 12:45:23
问题 I'd like to use the same flex/bison scanner/parser for an interpreter and for loading a file to be interpreted. I can not get the newline parsing to work correctly in both cases. Interpreter: There is a prompt and I can enter commands terminated by pressing ENTER. File: Here is an example input file: -----cut--------- begin( print("well done"), 1) ----cut------- So, there is a newline in the first line and after the '(' that should be eaten. In my scanner.l I have %% [ \t] { errorLineCol +=

Thread-safe / reentrant bison + flex

喜欢而已 提交于 2019-12-01 12:32:48
问题 I would really prefer a working example to any explanation. Whatever I read so far on Bison's documentation site contradicts whatever Flex says. One says to declare yylex as int yylex (yyscan_t yyscanner); another one wants it to be: int yylex(YYSTYPE *lvalp, YYLTYPE *llocp); What I really need is the location information. I'm not sure as of yet if I need YYSTYPE (I don't have a use for this information right now, but maybe in the future I will). Unrelated to the above, and as a bonus, I'd be

Where are the shift/reduce conflicts in this Bison code coming from?

依然范特西╮ 提交于 2019-12-01 08:15:15
I'm trying to parse this syntax: 34 + 1 − 8, 32 * 87 + 6 / 4, 34 / 8 I'm expecting to ground it like this: (, (- (+ 34 1) 8) (/ (+ (* 32 87) 6) 4) (/ 34 8)) This is the code for BISON: %token NUMBER %token COMMA %token OPERATOR %left OPERATOR %left COMMA %% term: NUMBER | term op term ; op: OPERATOR | COMMA; %% There is a problem: test.y: conflicts: 2 shift/reduce How can I solve it? The problem is with your definition of term : term: NUMBER | term op term ; When parsing this, at each number, the question is: should I read another token to know if I have the first, or the second form. A

Where are the shift/reduce conflicts in this Bison code coming from?

本小妞迷上赌 提交于 2019-12-01 07:07:44
问题 I'm trying to parse this syntax: 34 + 1 − 8, 32 * 87 + 6 / 4, 34 / 8 I'm expecting to ground it like this: (, (- (+ 34 1) 8) (/ (+ (* 32 87) 6) 4) (/ 34 8)) This is the code for BISON: %token NUMBER %token COMMA %token OPERATOR %left OPERATOR %left COMMA %% term: NUMBER | term op term ; op: OPERATOR | COMMA; %% There is a problem: test.y: conflicts: 2 shift/reduce How can I solve it? 回答1: The problem is with your definition of term : term: NUMBER | term op term ; When parsing this, at each

In function ‘yylex’: 'Variable’ undeclared

只愿长相守 提交于 2019-12-01 06:19:21
问题 I am working with Lexical Analysis . For this I am using Flex and I fetch following Problems. work.l int cnt = 0,num_lines=0,num_chars=0; // Problem here. %% [" "]+[a-zA-Z0-9]+ {++cnt;} \n {++num_lines; ++num_chars;} . {++num_chars;} %% int yywrap() { return 1; } int main() { yyin = freopen("in.txt", "r", stdin); yylex(); printf("%d %d %d\n", cnt, num_lines,num_chars); return 0; } then, I use following command and it work properly and create lex.yy.c . Rezwans-iMac:laqb-2 rezwan$ flex work.l

When is %destructor invoked in BISON?

旧巷老猫 提交于 2019-12-01 05:54:00
When is %destructor invoked in BISON ? I have the following bison code: %union{ char * sval; Variable * vval; } %token VARIABLE %token Literal %type <vval> Expression VARIABLE %type <sval> Literal %destructor { delete $$; } <vval> %destructor { delete $$; } Literal where Variable is a class. I thought that after processing a line, all the Variable objects will be freed, but I can see no destructor invoked. And that will lead straightly to memory leak... Edit: To be clear; I allocate a new Variable object for a new token, and this token is pushed to the BISON stack. I want to delete the