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).

Bison is the GNU parser generator. It generates LALR parsers, but can also generate GLR parsers for grammars that are not LALR. In POSIX mode, Bison is compatible with Yacc (yet another compiler compiler). flex, an automatic lexical analyser, is often used with Bison, to tokenise input data and provide Bison with tokens.

Websites:

See also:

2588 questions
4
votes
1 answer

Bison, difference between @1 and $1

I'm programming a Pascal compiler and already have working grammar. Now I want to start with semantic analysis but actually don't understand how it works in bison. Somehow I wrote a piece of working code by trying every option and I'm wondering what…
4
votes
2 answers

Clean way to end the parsing of a bison parser

I am writing a small expression analyser parser for a project at the company where I work. The parser is supposed to check, for example, a division by zero or an undefined identifier, report the error and stop. What is the best way to do this?…
Sambatyon
  • 3,316
  • 10
  • 48
  • 65
4
votes
1 answer

Bison/Flex parser getting strings as token values

I am currently working on a verilog parser using bison and flex as the tokenizer. My grammar works fine and now my goal is to store the data collected in a database. (If you don't know what verilog is, it doesn't really matter but you can find info…
djfoxmccloud
  • 571
  • 1
  • 9
  • 23
4
votes
1 answer

Implementing String Interpolation in Flex/Bison

I'm currently writing an interpreter for a language I have designed. The lexer/parser (GLR) is written in Flex/Bison and the main interpreter in D - and everything working flawlessly so far. The thing is I want to also add string interpolation, that…
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
4
votes
1 answer

How to move from a C to C++ style flex parser

I have the typical reentrant C style parser, where the parsed data is contained in an union like the following one: %union { int number; const char *string; Item *item_ptr; } I would like to use Shared Pointers instead of normal…
Anon
  • 43
  • 3
4
votes
1 answer

Need help identifying cause of "type clash on default action"

I've been working a school assignment and am having difficulty figuring out which issue is causing the multiple warnings below "type clash on default action." Any help would be greatly appreciated. Warnings received: parser.y:62.9-23: warning:…
KenM
  • 41
  • 3
4
votes
1 answer

What does the -y/-yacc flag do in bison?

I searched the man page and found this. But... what does it mean? without it my bison file doesnt compile and i would like to know why it doesnt (admittedly i have a few shift/reduce and reduce/reduce errors. But that shouldnt stop it?). Does anyone…
user34537
4
votes
3 answers

Can't figure out what is causing a shift/reduce errors in yacc

I'm working on a project in yacc and am getting a shift/reduce error but I can't figure out why I'm getting it. I've been looking through the y.output file but am not quite sure how to read it. My y.output file exceeds the character limit on SO so I…
Ian Burris
  • 6,325
  • 21
  • 59
  • 80
4
votes
1 answer

Assigning multiple data types to a non-terminal in yacc

I'm working on a project for class in which we have to build a parser. We're currently in the stage of building the parser in yacc. The thing currently confusing me is I've read that you need to assign a type to each nonterminal. In some cases…
Ian Burris
  • 6,325
  • 21
  • 59
  • 80
4
votes
4 answers

bison precedence doesn't work

This is my flex code %{ #include "fl.tab.h" %} %% [0-9]+ { yylval = atoi(yytext); return INTEGER; } \n return 0; [ \t] ; . return yytext[0]; %% And my bison code %{ #include %}…
user574183
  • 710
  • 1
  • 10
  • 22
4
votes
1 answer

Linux From Scratch error in Bison-3.0.4 'make check'

So I'm following the Linux From Scratch book and am in chapter 5.17 Bison-3.0.4. The book instructs us to do a make check after make to test the result of the compiled Bison package. Initially, I was getting the following error: make[3]: Entering…
UndercoverCoder
  • 953
  • 3
  • 13
  • 28
4
votes
4 answers

Parsing C/C++ source: How are token boundaries/interactions specified in lex/yacc?

I want to parse some C++ code, and as a guide I've been looking at the C lex/yacc definitions here: http://www.lysator.liu.se/c/ANSI-C-grammar-l.html and http://www.lysator.liu.se/c/ANSI-C-grammar-y.html I understand the specifications of the tokens…
Greencpp
  • 145
  • 6
4
votes
2 answers

Display message after user input in flex

I have the following code snippet that I wrote in flex. I need to display this message: {printf("\n%-20s%-30s%-10s\n", "Lexeme", "Unite lexicale", "Indice");} First thing after the user input, I tried to find a solution but nothing seems to…
user259584
  • 65
  • 1
  • 7
4
votes
1 answer

How can we add comments in flex/bison source code?

Like in other languages, we can add comments using either //, /---/, #, % etc. So similarly if I want to add comments in flex/bison source code for better understanding of code. Can I do the same? If yes then how? Whenever I tried to search about…
Echostar
  • 71
  • 1
  • 4
4
votes
1 answer

How to add additional arguments to yylex (in bison/flex)?

I am trying to create a reentrant parser using flex and bison. I want to add a parameter to save some state, but I failed to add it to yylex(). Here is the example, it is not expected to compile, just shows the generated code. foo.l %option…
OstCollector
  • 51
  • 1
  • 5