bison

Shift/reduce conflict despite precedence rules

五迷三道 提交于 2020-01-07 07:19:21
问题 The language I'm writing a parser for has three constructs that are relevant here: the ord operator, represented by TOK_ORD , which casts character expressions into integer expressions, and [ ] and . , which are used for index and field access, respectively, just like in C. Here's an excerpt from my precedence rules: %right TOK_ORD %left PREC_INDEX PREC_MEMBER My grammar has a nonterminal expr , which represents expressions. Here's some relevant snippets from the grammar ( TOK_IDENT is a

Shift/reduce conflict despite precedence rules

你。 提交于 2020-01-07 07:19:20
问题 The language I'm writing a parser for has three constructs that are relevant here: the ord operator, represented by TOK_ORD , which casts character expressions into integer expressions, and [ ] and . , which are used for index and field access, respectively, just like in C. Here's an excerpt from my precedence rules: %right TOK_ORD %left PREC_INDEX PREC_MEMBER My grammar has a nonterminal expr , which represents expressions. Here's some relevant snippets from the grammar ( TOK_IDENT is a

Unclear how a yacc/bison production spec can cause a stack overflow

吃可爱长大的小学妹 提交于 2020-01-07 02:11:07
问题 This is not homework, but it is from a book. I'm given the following grammar: %{ #include <stdio.h> #include <ctype.h> int yylex(); int yyerror(); %} %% command : exp '\n' { printf("%d\n", $1); exit(0); } | error '\n' { yyerrok; printf("reenter expression: "); } command ; exp : exp '+' term { $$ = $1 + $3; } | exp '-' term { $$ = $1 - $3; } | term { $$ = $1; } ; term : term '*' factor { $$ = $1 * $3; } | factor { $$ = $1; } ; factor : NUMBER { $$ = $1; } | '(' exp ')' { $$ = $2; } ; %% int

Additional syntax error message on GLR parser when syntax is ambiguous

南笙酒味 提交于 2020-01-06 20:53:29
问题 I am using Bison 2.7 to write a GLR parser and also turn on %error-verbose option. When I ran the parser, it gave me "syntax is ambiguous" error. Is there a way that Bison can give me more details on where/how the syntax is ambiguous? 回答1: If you are looking to produce meaningful error messages, you will probably need to craft your own function to report ambiguities. bison does give you a basic tool for this: the custom %merge function. As indicated in the manual (see the paragraphs at the

Using $x to grab string from rule

余生颓废 提交于 2020-01-06 04:53:09
问题 I'm trying to do something like this in Bison... loop_for: FOR var_name COLONEQUALS expression TO {printf("%s<=", $2);} expression STEP {printf("%s+=", $2);} expression {printf(")\n");} Code ENDFOR What I'm trying to do is convert a for statement from the fake language's syntax to C's. However, the $2 I've used to grab var_name doesn't seem to work as the program crashes when it reaches there. Is $x supposed to work only for integers? I even tried adding a union and using char* for a new type

no error while parsing empty file yacc/lex

核能气质少年 提交于 2020-01-06 02:58:06
问题 I have a parser with me generated from yacc/lex. It is working fine for all the rules I have set except one case. If file is empty which this parser is parsing it gives error. I want to add rule so that it does not give error when file is empty. I have not added any checks for that in either of my .l/.y file. How can this be done with YACC/LEX? Thanks in advance !! 回答1: The lexer should recognize the end of input and return a token accordingly (i.e. EOF ). Your grammar's start rule could look

Simple string passing through nodes in Bison/Yacc

会有一股神秘感。 提交于 2020-01-05 09:12:11
问题 I have to concatenate strings in semantic rules of my yacc file: %union { stringstream sstream; } %type<sstream> node1 node2 --- node1 : node2 { $$ << $1 << " goodbye" } node2 : final { $$ << "hello" } However, as stringstream or even string are not allowed in unions, I don't find any easy way to mix char * , int , and make nodes transport a string that I can manipulate everywhere. How should I do it ? 回答1: I don't remember bison / yacc details, but you sure can use pointer and new it. Just

Flex reentrant with start conditions

人盡茶涼 提交于 2020-01-04 09:18:27
问题 I am trying to make a reentrant scanner that relies on start conditions. I was following along something similar to this guys question: Writing re-entrant lexer with Flex And as the one poster mentioned, the scanner will work if you explicitly create the yyscan_t and pass it as an extra argument. However, I still get the yyg undeclared error message when using BEGIN <sc> , etc to manipulate the start condition. Is this a bug? Should I explicity use the yy_push_state and yy_pop_state state

Bison: GLR-parsing of valid expression fails without error message

和自甴很熟 提交于 2020-01-04 06:12:40
问题 I'm working on a GLR-parser in GNU bison and I have the following problem: the language I'm trying to parse allows boolean expressions including relations (<,>,<=,...) and boolean composition (and, or, not). Now the problem is that the language also allows to have multiple arithmetic expressions on the right side of a relation... and they are composed using the same AND token that is used for boolean composition! This is a very dumb language-design, but I can't change it. So you can have a >

YACC rules not getting reduced

拟墨画扇 提交于 2020-01-03 13:30:48
问题 I'm trying to learn YACC and having a bit of trouble figuring out the warning messages it is giving me. Here is part of my file: define_character: WORD IS STRING COLOR { printf("%s's full name is %s and thier color is %s", $1, $3, $4); }; dialog: WORD COLON STRING { printf("%s says %s", $1, $3); }; change_scene: SCENE SETSCENE WORD { printf("%s is the new scene", $3); }; The warnings that it gives me are: 2 rules never reduced 2 useless nonterminals and 2 useless rules warning: useless