Questions tagged [bison]
Bison is the GNU parser generator. It generates LALR parsers, but can also generate GLR parsers for grammars that are not LALR. It has a mode of compatibility with its old predecessor Yacc (yet another compiler compiler).
2,519
questions
-1
votes
1
answer
24
views
flex/bison How can I make it recognize a pattern, whether the final character is a dot or not?
I try to make an analizer/parser of the code of prolog, here is an example of a fact:
"dadof(arturo,armando)."
It ends with a dot (.) and my parser recognize it and then print ("hecho&...
2
votes
1
answer
51
views
CMake FindFLEX produces NOTFOUND on windows
I installed flex and bison with chocolatey
choco install winflexbison3
and created this CMakeLists.txt
find_package(BISON)
find_package(FLEX)
message("FLEX_FOUND: ${FLEX_FOUND}")
message(&...
0
votes
1
answer
51
views
Bison Shift/Reduce conficts
//parserr.y
//tokens
---------
/* precedences */
%left T_LPAREN T_RPAREN
%left T_MULOP T_DIVOP
%left T_ADDOP
%left T_ANDOP
%left T_OROP
%left T_NOTOP
...
-2
votes
1
answer
67
views
In a UNIX pipeline how to get the user-tool interaction of the first stage piped into the next stage?
Page 32 of the book "The UNIX Programming Environment" makes this profound statement about UNIX pipes:
The programs in a pipeline actually run at the same time, not one
after another. This ...
0
votes
0
answers
33
views
Resolving Shift/reduce conflicts in GNU Bison
I have the following grammar rules:
%precedence KW2
%left "or"
%left "and"
%left "==" "!=" ">=" ">" "<=" "<"
...
0
votes
0
answers
14
views
Why does my parser allow input to come from either a file or from stdin? I didn't write my parser to support that functionality [duplicate]
I created a parser to evaluate simple arithmetic expressions. I named the executable "calc". Here is the parser's main() function:
int main(int argc, char *argv[])
{
yyin = fopen(argv[1]...
1
vote
1
answer
90
views
main expects a filename as the first argument ... but I can alternatively provide main the file via a pipe ... how does that work?
I have a C program with this main() function:
int main(int argc, char *argv[])
{
FILE *f = fopen(argv[1], "r");
...
}
Notice that it expects, when executing the program, a filename ...
0
votes
1
answer
35
views
flex/bison gives me a syntax error after printing the result and if another input is written to work
After running the compiler and type the entry on, works fine. Then if I type another entry (and if it also works ok) it gave me Syntax Error.
I must mention I am a new in the world of flex/bison. ...
0
votes
1
answer
45
views
How to restart start state data in flex
I've created a start condition (for strings) in flex and everything works fine. However,
when I parse the same string twice, the elements using the start condition vanish.
How can I solve it?
please ...
0
votes
0
answers
54
views
How to reparse a parsed string in C++ with Bison?
I am developing software that would allow you to replace words with others. The idea is that a character string will be parsed in a loop until there is nothing left to parse, but the problem is that ...
0
votes
0
answers
24
views
Does the Windows "more" command line utility append a newline to the end of the file it displays?
I have an input file containing one arithmetic expression on each line. The file has this form:
expr EOL expr EOL expr
The last arithmetic expression isn't followed by an end-of-line (EOL).
The file ...
-1
votes
0
answers
28
views
Convert a bison token number back into its "name" from the token declarations
I have written a BASIC interpreter in flex/bison/C. The primary purpose is to collect statistics on the structure of BASIC programs. So, for instance, I examine every numeric constant in the program ...
1
vote
1
answer
31
views
How is the output() function different than, better than, a simple printf or fprintf statement?
A book that I am reading [1] says something that I need help understanding.
The book first describes the input(), output(), and unput() functions. Then it says this:
The use of output() allows Lex to ...
0
votes
1
answer
22
views
How to process NUL characters in a Flex lexer, given that 0 denotes end-of-file?
My input file consists of one byte, the NUL character (hex 0).
I have a Flex rule that matches the NUL character and the action returns it:
\0 { return(yytext[0]); }
Below is my ...
0
votes
0
answers
26
views
Invalid directive: '%baseclass-preinclude' with Bison
I would like to compile a parser with bison, that has these line at the top:
%language "c++"
%baseclass-preinclude <iostream>
%lsp-needed
Unfortunately I get this error:
parser.y:2.1-...
0
votes
1
answer
26
views
How to use %code provides {} to create a yyerror function from bison?
I'm trying to build a simple flex/bison scanner/parser. Following the advice of "rici" on this question - How to invoke yyerror() from flex? - I have tried putting my yyerror function in a %...
0
votes
1
answer
37
views
Bison shift/reduce conflit
I get 2 shift/reduce errors when I try to compile the following grammar which is part of a larger one:
%token NAMESPACE IDENTIFIER
%start statement
%%
post_expression
: IDENTIFIER
| ...
0
votes
0
answers
25
views
Why do I need to call yyterminate in the action for end-of-file?
I created a very simple lexer that counts the number of lines in the input. See below. Notice that when end-of-file is encountered, the count is output. Also, notice that yyterminate() is called. I ...
0
votes
1
answer
32
views
Why is 'YY_DO_BEFORE_ACTION' undefined by Bison's %code requires prologue?
I have a compiler project using Bison (3.8.2) and Flex (2.6.4) built using Cygwin on Windows 10. Without using the %code requires prologue, my project will build and run as expected. Once I add the %...
0
votes
0
answers
27
views
Flex swallowing \n and \r at the end of input
I'm trying to make Flex to swallow my \r\n characters at the end of my input. (this is an interpreter like CLI)
So far, I have no luck. I have the following rule:
swallow ([[:space:]]|\n)
and then
<...
0
votes
1
answer
21
views
warning, rule cannot be matched in a line with blank spaces
I have this flex file that gets tokens from a file. For some reason i get this strange warning whenever i compile my file. However the file still compiles and i dont get why do i even get this error ...
0
votes
0
answers
30
views
How to solve yacc error "... has no declared type"
I have problem on Yacc/Bison.
We use Kotlin grammar.
This is my code :
%token BOOL
%token BREAK
%token CHAR
%token CONTINUE
%token DO
%token ENUM
%token EXTERN
%token FALSE
%token FLOAT
%token FOR
%...
0
votes
1
answer
26
views
How to count repetition of characters in a word . Flex
I'm trying to count the repetition of characters in a word by flex and bison.
I don't know how to do that. Any help?
0
votes
0
answers
43
views
JSON Object in Bison Grammar
I'm currently trying to build a parser using flex/bison and i don't know how to create a Json Object in bison Grammar. At the time i've come up with this code but i think it's wrong.
tempJsonObj : ...
0
votes
2
answers
65
views
How to insert any symbol at the beggining , middle or end of BISON expression?
As a beginner in Bison and Flex I want to make a program that only recognizes numbers with '!' symbol at the beginning and '_' in the middle, for example !44_22. I am not sure what's the best way to ...
0
votes
0
answers
37
views
Bison shift/reduce confilcs
I have the following start of a Pascal grammar
The grammar works correctly. What I don't understand is I have a very similar grammar in my 6502 assembler that does not have any reduce/shift conflicts.
...
0
votes
0
answers
22
views
Using emplace on $$ in bison grammar with variant
In a bison grammar that is using variant as the value type, the Bison manual describes how you can use yylval->emplace in the Lexer, and looking at the generated parser.cc code you can deduce how ...
0
votes
0
answers
15
views
Is it possible to generate random possible accepted grammar strings using bison for a particular grammar?
I want to profile my bison based application as well make sure to eliminate the effect of cache while parsing. Is it possible to generate random possible accepted grammar strings using bison for a ...
0
votes
1
answer
43
views
Flex/Bison sometimes misses Re
I build a CLI using flex/bison, and I experience that the flex sometimes doesn't get the tokens.
My .l looks like this:
%{
#include <stdio.h>
#include <string.h>
#include "hmd.tab.h&...
0
votes
1
answer
24
views
Flex/Bison - match random data
I'm implementing a custom CLI with flex/Bison. My sample command looks like this:
zone 3 set field some_value
where I can match keywords like zone and set, and I can match string in the place of field....
0
votes
0
answers
48
views
brew install bison@2.7 Warning: No available formula with the name "bison@2.7"
I need to install the 2.7 version of bison. However, when I run the command brew install bison@2.7, it shows me this error :
brew install bison@2.7
Warning: No available formula with the name "...
0
votes
1
answer
60
views
bad_alloc when attempting to print string that was assigned to member of $$ struct
During our compiler's intermediate code generation phase, and more specifically while testing the arithmetic expressions and assignment rules, I noticed that although the respective quads are ...
1
vote
0
answers
42
views
Custom errors messages with Bison
With Bison, I generate custom error messages with the function: int yyreport_syntax_error (const yypcontext_t *ctx) by specifying %define parse.error custom.
I am looking for a feature to display also ...
0
votes
1
answer
20
views
Platformio compilation error in bison file
I'm using bison with flex combined with Arduino framework in Platformio. Compiling .y and .l files goes without a problem, but when I'm trying to make a Build in Platformio I got those errors:
error: ...
1
vote
0
answers
35
views
How to access FlexLexer's input function without deriving from yyFlexLexer?
I am writing a simple compiler for a simple C like language. To do that I would like to use Flex and Bison but use them both in the context of modern C++
Right now my setup consists of a main.cpp ...
1
vote
1
answer
44
views
Friendly name for special $end token in Bison
With older versions of Bison, verbose error messages sometimes look like this:
syntax error, unexpected [, expecting $end
Is there a way to give $end a more user-friendly name? In newer versions this ...
0
votes
0
answers
52
views
Variant type without memory leak in Bison tokens
What is the best non-memory-leaking variant type to use for texts in Bison (for example %token <std::string>)?
I wanted to replace char * as the variant type for tokens with a more modern type (...
0
votes
1
answer
61
views
Flex and Bison $variables giving unexpected values
In my lexer file I set "yylval.str = yytext" for the token "name". Then in my bison file I try to read that str value to get the name as a string. However, when I read $2 I end up ...
0
votes
0
answers
49
views
is their any grammar file of flex/bison input file in flex/bison format?
i would like to write a flex and bison which will generate pure-cpp header file so that can platform independ.
actually i have written some code of them.
i parse the flex and bison input file using ...
0
votes
0
answers
33
views
Receiving a core dumped while using flex-bison and cpp
I am using flex-bison to make a basic compiler of an invented language for an appointment. The problem is that I always receive a core dumped error when I test the 'continue' sentence. I know this ...
0
votes
0
answers
34
views
Why does my $1 operation not work with Java Bison?
When I have an abstract syntax tree in the Java Bison (.y) file with this:
string_op:
SYMBOL_PLUS { $$ = $1; System.out.println("this should print + here: " + $$);}
| SYMBOL_DOUBLEEQ
| ...
0
votes
1
answer
44
views
Unordered result because of an ambiguous grammar using Flex and Bison
I'm trying to create a section for variable declaration (a bit similar to HTML) using Flex and Bison, my grammar is correct (no lexical or syntax errors), but the displayed result isn't ordered.
...
0
votes
0
answers
48
views
Bison is always giving me a yyerror and yyparse() is always returning 1
I am constantly getting yyerror : syntax error no matter the input file and yyparse() is always returning 1. I am having trouble finding what the issue is. I believe my BNF and input should be correct ...
-1
votes
1
answer
56
views
Flex and Bison compiler doesn't show lexical errors when he meets one syntax error
I'm coding a compiler using Flex and Bison, I coded yyerror(char*) and some printf() messages to show lexical and syntax errors. I tested my code by adding some errors in my file "programm.txt&...
-1
votes
1
answer
23
views
Bison calling yyerror and printing success
For some reason when trying to use bison and test input on it I constantly get both a success and a failure every time no matter what. I am not sure what I am doing wrong. Here is my .y file:
%{
#...
0
votes
1
answer
74
views
How to write custom input function for Flex in C++ mode?
I have a game engine and a shader parser. The engine has an API for reading from a virtual file system. I would like to be able to load shaders through this API. I was thinking about implementing my ...
0
votes
1
answer
62
views
Confused regarding parsing with Bison
I'm reading "Flex & Bison" by Levine and I'm a bit confused as to how exactly the parsing takes place. For this example I'll be using these rules for a simple calculator:
exp: factor | ...
0
votes
1
answer
97
views
Understanding how to resolve reduce/reduce & shift/reduce conflicts
I have the following tokens, operator precedence and grammar rules in my parser.y file:
%token <intval> INTCONST
%token <realval> REALCONST
%token <strval> STRCONST
%token <strval&...
1
vote
1
answer
52
views
How does Bison deal with some optional part in BNF grammars?
I'm a freshman in Bison and Compiler principles, now I'm trying to write an easy Verilog parser in Flex&Bison according to the IEEE Standard. Here is the question: when a grammar's body has ...
0
votes
1
answer
52
views
How to run code on start of yylex and when token is matched in RE-flex
I was using RE-flex to generate a c++ Scanner for a project. I wanted to run code when a token is matched and I followed the Flex way of doing, but that ended up putting the code outside the function. ...