bison

Simple ambiguous grammar with reduce-reduce conflict

独自空忆成欢 提交于 2019-12-11 03:24:43
问题 The following simple grammar to parse a logical expression results in a reduce/reduce conflict: %token AND OR %token NUMBER VARIABLE %% logical_expr : logical_expr AND logical_term | logical_expr OR logical_term | logical_term ; logical_term : VARIABLE | comparison | '(' logical_expr ')' ; comparison : expr '<' expr | expr '>' expr ; expr : expr '+' term | expr '-' term | term ; term : NUMBER | VARIABLE | '(' expr ')' ; %% The status report from bison has: state 2 4 logical_term: VARIABLE .

How does backpatching work with markers?

回眸只為那壹抹淺笑 提交于 2019-12-11 02:44:51
问题 I've searched all over the Internet and could not find a proper explanation of how backpatching works? Can you please explain me how does backpatching works? How does it work with the markers ? I know it has 2 main types of markers: with next-quad in it with next-list in it I found this code, in which they are taking an input file and creating a file with RISKI language. In their first roll they have: PROGRAM : N FUNCTION M MAIN_FUNCTION and you can see that N and M are markers (they are

Why doesn't %prec have an effect in this bison grammar?

会有一股神秘感。 提交于 2019-12-11 02:21:00
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 5 years ago . Consider the following Bison grammar (this is stripped down from a much larger grammar I'm working on): %token ident %left '+' %left CALLPREC %% start: add ';' ; expr: ident | call | add ; call: expr '(' ')' %prec CALLPREC ; add: expr '+' expr ; Obviously without precedence there's a s/r conflict when parsing an expression like foo + bar() . I'm trying to

Yacc and Lex inclusion confusion

送分小仙女□ 提交于 2019-12-11 01:48:01
问题 I am wondering how to correctly compile a program with a Makefile that has calls to yyparse in it? This is what I do: I have a Makefile that compiles all my regular files and they have no connections to y.tab.c or lex.yy.c (Am I supposed to have them?) I do this on top of my code: #include "y.tab.c" #include "lex.yy.c" #include "y.tab.h" This is what happens when I try to make the program: When I just type in "make", it gives me many warnings. Some of the examples are shown below. In function

Bison token is rest of the string

可紊 提交于 2019-12-11 01:31:27
问题 I have written a flex and bison, I am facing a problem which is illustrated via the below program. The program is intended to parse the key-value pairs separated by an equals (=) sign I am hoping that my bison script tokenizes the key and values and prints them. Below is the snippet of my flex program %{ /* file : kvp.l */ #include <stdio.h> #define YYSTYPE char* #include "kvp.tab.h" %} %% [a-zA-Z0-9][_a-zA-Z0-9]* { yylval=yytext; return IDENTIFIER; } "=" { yylval=yytext; return EQUALS_OP; }

bison/lex YYSTYPE declaration as struct

孤者浪人 提交于 2019-12-11 01:14:57
问题 I've been trying for a while, to implement a parser for a grammar by using bison and lex. I have a problem with the type redeclaration of yylval, I explain myself. I have 4 files: lexico.l, parser.y, funcionesTabla.c, funcionesTabla.h The first, contains the specification for lex The second, specification for bison/yacc The last two, are a bunch of methods for dealing with a symbol table. I have in funcionesTabla.h: typedef enum { entero, real, caracter, arrayEntero, arrayReal, arrayCaracter,

Undefined reference to `yylex'

情到浓时终转凉″ 提交于 2019-12-11 00:58:10
问题 I am trying to parse one input file using flex and bison but I am facing one difficulty while compiling my program. I am attaching my flex and bison code and error which I am getting. Please help me out to solve these errors lex.l %{ #include <iostream> #include <stdio.h> #include "yacc.tab.h" #define YY_DECL extern "C" int yylex() using namespace std; %} DOT "." COLON ":" SEMICOLON ";" COMMA "," ANGLE_LEFT "<" ANGLE_RIGHT ">" AT "@" EQUAL "=" SQUARE_OPEN "[" SQUARE_CLOSE [^\\]"]" OPENBRACE "

segmentation fault with bison and flex

ⅰ亾dé卋堺 提交于 2019-12-11 00:54:49
问题 I was trying learn lex and yacc using the oreilly book. I tried following example from book, but it gives segmentation fault. %{ /** * A lexer for the basic grammar to use for recognizing English sentences. */ #include <stdio.h> extern FILE *yyin; %} %token NOUN PRONOUN VERB ADVERB ADJECTIVE PREPOSITION CONJUNCTION %% sentence: subject VERB object{ printf("Sentence is valid.\n");} ; subject: NOUN | PRONOUN ; object: NOUN ; %% main() { while(!feof(yyin)) { yyparse(); } } yyerror(char *s) {

Can't compile flex & bison (Symbols not found x86_64)

流过昼夜 提交于 2019-12-11 00:12:30
问题 I am trying to compile a simple program on Flex & Bison on my Mac running Yosemite but get the following error: Undefined symbols for architecture x86_64: "_yyerror", referenced from: _yyparse in pr1-19c182.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) My two files look like this, they compile on my teacher's Ubuntu installation but I can't get them to work on my Mac: pr1.y %{ #include <stdio.h> %} %% expr :

compiling flex and bison into cpp

杀马特。学长 韩版系。学妹 提交于 2019-12-10 21:24:42
问题 Usually, when we compile .l and .y files, we get .tab.h,.tab.c and .yy.c files. However, I need to use these in a C++ environment with types that are only available in C++. How do you modify your code so as to do this? 回答1: You can compile the generated files using your trustworthy C++ compiler, so you don't have to rewrite the whole thing. If you want to go "full c++", keep reading. For Flex , you need to specifiy %option c++ in the file. You can also change the generated C++ lexer name