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

heap handling in a bison push pure parser

Is there any way to specify my own allocator/deallocator functions for heap management instead of malloc()/free() for a pure push parser in bison?
Flavius
  • 13,566
  • 13
  • 80
  • 126
7
votes
1 answer

How can I manage mutual recursion, retaining associativity rules?

The overall question is: How does my grammar have to look like to allow for arbitrarily nested expr := '(' expr ')' => expr | expr_without_short_closure and expr_without_short_closure := [expr_without_short_closure => expr] | yield…
bwoebi
  • 23,637
  • 5
  • 58
  • 79
7
votes
2 answers

Get rid of warning: implicit declaration of function ‘fileno’ in flex

I'm trying to get rid of a warning that gcc is throwing when I try to compile my bison and flex files: : In function ‘yy_init_buffer’: :1675: warning: implicit declaration of function ‘fileno’ The reason why I want to do this is because I'm trying…
bnoite
  • 185
  • 2
  • 12
7
votes
1 answer

use yylval in bison to recover a string

hi im confusing about how to get a char* when i read a specific token... I look in various sites and they provide suggestions but not complete, i mean, for example yylval and yytext declaration is missing or how to transform the types, etc What is…
mjsr
  • 7,410
  • 18
  • 57
  • 83
7
votes
4 answers

c++ what is the advantage of lex and bison to a selfmade tokenizer / parser

I would like to do some parsing and tokenizing in c++ for learning purposes. Now I often times came across bison/yacc and lex when reading about this subject online. Would there be any mayor benefit of using those over for instance a…
moka
  • 4,353
  • 2
  • 37
  • 63
7
votes
1 answer

How to increase stack size in bison (and solve "memory exhausted")

My bison-based parser started choking on some moderately sized files I've generated recently. It throws an exception about "memory exhausted." The bison man page says that this is likely due to use of right-hand recursion. Without trying to rewrite…
user2180977
  • 401
  • 3
  • 14
7
votes
1 answer

bison precedence is useless? it doesn't work

I have declared such precedence for bison : %left '+' '-' %left '*' '/' Recursive rules for arithmetic: exp: exp binary_op exp { .. } | literal_exp { .. } | ID { .. } binary_op: '+' …
inaumov17
  • 1,329
  • 11
  • 18
7
votes
2 answers

bison YYSTYPE: Trying to use char*

I need to use flex and bison to parse some code. The default type of YYSTYPE is int, even though I never declared it that way. Is that a default from bison? It would help me a lot to pass strings back. I read this: How to solve Bison warning "...…
naokoken
  • 71
  • 1
  • 2
7
votes
7 answers

Creating a small programming language for beginners

I would like to create my own programming language. Maybe not exactly a programming language from scratch but maybe base it on another language. I've heard of Yacc. So, I installed Flex and Bison. But I do not understand how to make a compiler with…
7
votes
5 answers

Multiple flex/bison parsers

What is the best way to handle multiple Flex/Bison parsers inside a project? I wrote a parser and now I need a second one in the same project. So far in the third section of parser1.y I inserted the main(..) method and called yyparse from…
Jack
  • 131,802
  • 30
  • 241
  • 343
7
votes
3 answers

Flex++ Bisonc++ parser

I'm trying to use flex and bison in my project to generate a parser code for a file structure. Main programming language is C++ and project is on an OO design mainly running in parallel. I heard that flex and bison generated parsers are C codes and…
sorush-r
  • 10,490
  • 17
  • 89
  • 173
7
votes
4 answers

What is $$ in bison?

In the bison manual in section 2.1.2 Grammar Rules for rpcalc, it is written that: In each action, the pseudo-variable $$ stands for the semantic value for the grouping that the rule is going to construct. Assigning a value to $$ is the main…
Amumu
  • 17,924
  • 31
  • 84
  • 131
6
votes
2 answers

How do I implement forward references in a compiler?

I'm creating a compiler with Lex and YACC (actually Flex and Bison). The language allows unlimited forward references to any symbol (like C#). The problem is that it's impossible to parse the language without knowing what an identifier is. The only…
Zifre
  • 26,504
  • 11
  • 85
  • 105
6
votes
1 answer

How to get string value of token in flex and bison?

I have this token in my .lex file: [a-zA-Z0-9]+ { yylval = yytext; return ALPHANUM; } and this code in my .y file: Sentence: "Sphere(" ALPHANUM ")." { FILE* file = fopen("C:/test.txt", "a+"); char st1[] = "polySphere -name "; strcat(st1,…
user1007632
  • 167
  • 2
  • 2
  • 8
6
votes
3 answers

C++ GLR parsers with Bison

I'm using Bison to generate a parser. I've got one shift/reduce conflict where I really need Bison to use GLR rather than LALR to deal with it. But I've passed the %glr-parser directive and the source file still states that it's a LALR parser. I…
Puppy
  • 144,682
  • 38
  • 256
  • 465