2,649 questions
1 vote
1 answer
53 views
Right way to fix shift/reduce conflict?
I see 1 shift/reduce conflict for following bison grammar: %token EQUAL "=" NUM "NUM" WORD "WORD" ; %% %start line; VALUES: NUM |...
2 votes
1 answer
102 views
Using %define api.prefix in bison/lex raises error in gcc when linking files
I'm using this answer as my template to add the prefix "eval": https://stackoverflow.com/a/48879103/14956120 The only difference from that answer, is that I'm on windows (using msys2), and ...
1 vote
0 answers
65 views
Bison precedence is behaving unexpectedly with %prec for non operator precedence
I'm trying to remove shift reduce errors in a grammar which just recognizes if-else constructs, using the %nonassoc and %prec. I know there are other ways to solve this, but I'm just trying for my own ...
1 vote
1 answer
59 views
Is it possible to make Bison utilize external token definitions?
I am working on building a compiler using Flex/Bison, and tried to utilize a tokens.h file to define the tokens used by the parser and lexer. #ifndef TOKENS_H #define TOKENS_H enum TokenType { ...
-2 votes
1 answer
110 views
How do I interface Flex and Bison using C++ with variants?
I tried to adapt the (only/most voted) answer of this StackOverflow question to the setting where I don't have std::string semantic values, but rather variants. This means I changed the following: In ...
0 votes
0 answers
80 views
Undefined reference to `yylval' using Flex and Bison
How can I resolve the "undefined reference to 'yylval'" error in the simplest program ever? This is my lexer.l file %{ #include "parser.tab.h" %} %% [0-9]+ { ...
1 vote
1 answer
70 views
Issue with running a calculator YACC compiler [closed]
We are doing a calculator compiler, however, we haven't been able to run it because of file dependencies that we cannot understand. The beginning of the yacc file is as so: %{ #include "symtab.h&...
0 votes
0 answers
31 views
Where does bison store string literals for tokens?
I am curious about how bison's string literal tokens are stored. Consider these definitions in myparser.y: %token FOR %token TO "->" If I understand the way the system works, the first ...
0 votes
0 answers
53 views
shift-reduce conflict in grammar with yacc/bison
I am writing a c-like language, but for grammar shown below: module: module declORFunc | declORFunc ; declORFunc: decl | func decl: CONST_opt btype varDef_list SEMICOLON ; CONST_opt: /* ...
2 votes
1 answer
88 views
Bulding a syntax tree with bison ($ ref issue)
I'm into a project where I need to build a whole compiler for C- language. I was looking for materials on this topic but I don't found anything. I have this code's piece of a grammar rule about ...
1 vote
1 answer
72 views
Why does Bison prioritize Exp → Exp MINUS Exp over Exp → MINUS Exp?
I'm working on a Bison grammar for arithmetic expressions, and I encountered an interesting behavior when parsing expressions with the MINUS operator. Here’s a simplified version of my grammar: %left ...
1 vote
0 answers
55 views
Go yacc: Handling = for both assignment and equality in left-associative expressions
I'm working on a parser using Go and yacc (package golang.org/x/tools/cmd/goyacc). The language I'm parsing uses the = symbol for both assignment and comparison in logical expressions. For example: ...
0 votes
1 answer
67 views
AST creation segfaults when input string input is larger than 9
Test Ouputs: ./parse -r /[123456]/ Accepted! ./parse -r /[1234567]/ zsh: segmentation fault (core dumped) ./parse -r This is my flex rule for the token. \[^?([^\\\]]|\\.)*\] {yylval.value = strdup(...
0 votes
1 answer
83 views
how to resolve a shift/reduce conflict in bison?
I want to make a compilator for a language similar to C. Declarations go first, then functions. Declarations can only be "int" while functions can return "int" or "void". ...
-1 votes
1 answer
90 views
How do I manipulate this dynamic vector for fold operations
I am working with flex/bison to create an interpreter for a class. The problem that I am encountering seems to be related to using/converting a dynamic vector. I am trying to create a function to ...