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
6
votes
1 answer

Bison nonterminal useless in grammar

When I compile the below grammar with bison test.y, it warns that the nonterminals "header_stms" and "forward" are useless. Why? They are used in the "program" rule. The nonterminal "stm" is not reported useless. %% program: /* empty */ | stm …
Mike
  • 654
  • 2
  • 7
  • 22
6
votes
2 answers

Bison build warning: "-s option given but default rule can be matched"

I get the warning warning, -s option given but default rule can be matched if you google "option given but default rule can be matched", you'll find the Flex manual's chapter on Diagnostics and this entry in an old Flex manpage in the Diagnostics…
user34537
6
votes
2 answers

How to integrate flex and bison with Qt project?

I am making a GUI program using Qt4, under git source control (Github page). Small part of project requires scanning and parsing. So I want to use flex and bison with the project. I can think of 3 ways- To keep flex and bison files out of project…
Vinayak Garg
  • 6,518
  • 10
  • 53
  • 80
6
votes
1 answer

Grammar spec resolving Shift/Reduce conflicts

I'm using Jison (Bison) to create a simple markup language. I'm clearly new to this, but slight variations are working very well. I just don't understand the source of the S/R conflict. It doesn't seem matter that 'Text' is returned by two lexer…
Jason Kleban
  • 20,024
  • 18
  • 75
  • 125
6
votes
1 answer

Is the order of reduction defined in Yacc?

This is more of an "in principle" question than a practical one. Is the order in which Yacc reduces productions, and reads new tokens from the lexer defined. That is, if I had the following set of…
Alex Gaynor
  • 14,353
  • 9
  • 63
  • 113
6
votes
3 answers

Start states in Lex / Flex

I'm using Flex and Bison for a parser generator, but having problems with the start states in my scanner. I'm using exclusive rules to deal with commenting, but this grammar doesn't seem to match quoted tokens: %x COMMENT // {…
Dan
  • 33,953
  • 24
  • 61
  • 87
6
votes
2 answers

Generating random but still valid expressions based on yacc/bison/ANTLR grammar

Is it possible? Any tool available for this?
user313885
6
votes
1 answer

can Flex return a string match to bison

I'm writing a Bison/Flex program to convert LaTeX into MathML. At the moment, dealing with functions (i.e. \sqrt, \frac, etc) works like this, with a token for every function \\frac {return FUNC_FRAC;} and passes the token FUNC_FRAC back…
Alex
  • 1,581
  • 2
  • 18
  • 31
5
votes
1 answer

Building an AST using Bison

I am working with Bison to build an AST for a compiler I am writing. What is the best way to build up the nodes in the AST? My question might be more clear with an example. Given the following snippet: field : modifier type TOK_IDENT…
mcorley
  • 767
  • 12
  • 21
5
votes
4 answers

Why does this simple grammar have a shift/reduce conflict?

%token PLUS MINUS INT %left PLUS MINUS THIS WORKS: exp : exp PLUS exp; exp : exp MINUS exp; exp : INT; THIS HAS 2 SHIFT/REDUCE CONFLICTS: exp : exp binaryop exp; exp : INT; binaryop: PLUS | MINUS ; WHY?
MustafaM
  • 493
  • 1
  • 4
  • 14
5
votes
2 answers

Bison, C++ GLR parsing: how to force shift\reduce conflict?

How can I force the shift\reduce conflict to be resolved by the GLR method? Suppose I want the parser to resolve the conflict between the right shift operator and two closing angle brackets of template arguments for itself. I make the lexer pass the…
slavasav
  • 71
  • 1
  • 7
5
votes
2 answers

How to show abstract syntax tree of a grammar in bison?

I am writing a grammar for a simple Pascal compiler in bison and I would like to visualize the parse tree for my grammar which I specified in pascal.y. Is it possible to graphically show the syntax tree based on my pascal.y file?
martas
  • 51
  • 2
5
votes
4 answers

Weird C code in Bison (yyerror)

I'm using Bison to create a simple parser and have some trouble understanding the C code below. To me it doesn't look like a valid statement, but gcc comepiles it neatly and the code in the block executes on parsing error. I'd really like to know…
rickythefox
  • 6,601
  • 6
  • 40
  • 62
5
votes
2 answers

Bison/YACC - avoid reduce/reduce conflict with two negation rules

The following grammar (where INTEGER is a sequence of digits) gives rise to a reduce/reduce conflict, because e.g. -4 can be reduced by expr -> -expr or expr -> num -> -INTEGER. In my grammar, num and expr return different types so that I have to…
Searles
  • 1,447
  • 1
  • 11
  • 26
5
votes
1 answer

Values in $1, $2 .. variables always NULL

I am trying to create a parser with Bison (GNU bison 2.4.1) and flex (2.5.35) on my Ubuntu OS. I have something like this: sql.h: typedef struct word { char *val; int length; } WORD; struct yword { struct word v; int …
Jay
  • 51
  • 2