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
11
votes
2 answers

Getting: warning, rule cannot be matched

I am working on building a lexical and syntax analyzer. I am getting the following warning when I try to use flex with my .l file. littleDuck.l:26: warning, rule cannot be matched Rule 26 is the one that starts with {cteI}, my rules section is the…
gabrielbaca
  • 123
  • 1
  • 2
  • 10
11
votes
4 answers

How to use indentation as block delimiters with bison and flex

I wounder how to implement indentation as block delimiters in bison + flex. Just like in python. I'm writing my own programming language ( mostly for fun, but I intend to use it together with a game engine ), I'll try to come up with something…
Frank
  • 2,640
  • 2
  • 21
  • 21
10
votes
2 answers

bison/flex: print erroneous line

I am using bison+flex to parse file. On error yyerror() is invoked. How can I get the line number or string that is violating the rules, to print it with the error message?
Jakub M.
  • 32,471
  • 48
  • 110
  • 179
10
votes
3 answers

yylval undefined with flex and bison

I have searched almost every material online. But I am still confused why lexer cannot identify yylval. Here is the case: I have defined a bunch of ADT in node.h and realize them in node.c, my purpose is to generate a AST after these structures are…
chenrui
  • 8,910
  • 3
  • 33
  • 43
10
votes
5 answers

Flex, Bison, and C: Looking for a very basic introduction

I am looking for a very short working example of flex and bison with an accompanying Makefile which makes use of the builtin rules. I've tried several google results that were messy, wouldn't build, or were in C++ which isn't acceptable. Good online…
colechristensen
  • 475
  • 1
  • 3
  • 11
10
votes
2 answers

How to put header file to .tab.h in Bison?

I wrote bison code header: %{ #include "foo.h" %} And I defined a struct named 'Foo' in header. I'd like to use it as token type in Bison. %define api.value.type union %token bar Then I use -d option to generate bison.tab.h file. bison -d…
syxbyi
  • 141
  • 1
  • 6
10
votes
1 answer

How do i implement If statement in Flex/bison

I dont get the error, please can you help me out, here is the .l and .y file.thanks. %{ #include "ifanw.tab.h" extern int yylval; %} %% "=" { return EQ; } "!=" { return NE; } "<" { return LT; } "<=" { return LE; } ">" { return…
Imran
  • 157
  • 1
  • 2
  • 9
10
votes
3 answers

How should I handle lexical errors in my Flex lexer?

I'm currently trying to write a small compiler using Flex+Bison but I'm kinda of lost in terms of what to do with error handlling, specially how to make everything fit together. To motivate the discussion consider the following lexer fragment I'm…
hugomg
  • 68,213
  • 24
  • 160
  • 246
10
votes
3 answers

How to use yylval with strings in yacc

I want to pass the actual string of a token. If I have a token called ID, then I want my yacc file to actually know what ID is called. I thing I have to pass a string using yylval to the yacc file from the flex file. How do I do that?
neuromancer
  • 53,769
  • 78
  • 166
  • 223
10
votes
3 answers

What are the disadvantages of using ANTLR compared to Flex/Bison?

I've worked on Flex, Bison few years ago during my undergraduate studies. However, I don't remember much about it now. Recently, I have come to hear about ANTLR. Would you recommend that I learn ANTLR or better to brush up Flex/Bison? Does ANTLR…
user855
  • 19,048
  • 38
  • 98
  • 162
10
votes
5 answers

How to fix a missing ld library for -lfl while compiling?

I am trying to translate my .spl file into a C file (because there is no compiler). I have an example "Hello World" .spl file, and I have downloaded the Shakespeare Programming Language .tar and extracted it, but I have no idea what to do next. I…
10
votes
2 answers

Parsing optional semicolon at statement end

I was writing a parser to parse C-like grammars. First, it could now parse code like: a = 1; b = 2; Now I want to make the semicolon at the end of line optional. The original YACC rule was: stmt: expr ';' { ... } Where the new line is processed by…
shouya
  • 2,863
  • 1
  • 24
  • 45
9
votes
3 answers

Can Bison parse UTF-8 characters?

I'm trying to make a Bison parser to handle UTF-8 characters. I don't want the parser to actually interpret the Unicode character values, but I want it to parse the UTF-8 string as a sequence of bytes. Right now, Bison generates the following code…
Martin Cote
  • 28,864
  • 15
  • 75
  • 99
9
votes
2 answers

yacc - field has incomplete type

yacc doesn't seem to like when my tokens are of a type that I defined. At the top of my grammar (.y) file in a %{ ... %} block, I include a header file that defines the following structure: typedef struct _spim_register { spim_register_type…
ArIck
  • 418
  • 3
  • 10
9
votes
4 answers

How to get the AST from YACC?

I know how to make YACC generate an AST, but how do you actaully get it? I mean, how do you actaully get the value of the root node from YACC?
mtk358
  • 565
  • 1
  • 7
  • 20