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

Error when attempting to use a type from GNU's GMP library as the yylval type for Bison

I'm attempting to use the type mpz_t from the GMP library as the type for yylval by including the following in the Bison file: %define api.value.type {mpz_t} I checked the generated parser and it correctly generates the line typedef mpz_t YYSTYPE,…
jeff
  • 8,300
  • 2
  • 31
  • 43
5
votes
1 answer

Parser generated by GNU Bison throws a segmentation fault 11 when given a non-empty file

Whenever I call yyparse() with a valid file, I get a seg fault that seems to be caused by this line (around line 1789) of code: if (yyss + yystacksize - 1 <= yyssp){ I arrived at this conclusion by printing debug messages before and after this line…
SamTebbs33
  • 5,507
  • 3
  • 22
  • 44
5
votes
1 answer

how to detect error line number using yacc parser

We have no idea on how to track errors in yacc parser. We're trying to use yylineno in our lex file and tried adding %option yylineno but it's still not workin', we cannot access these variables in yacc. All we want is to print out the syntax error…
Aron
  • 129
  • 1
  • 3
  • 13
5
votes
4 answers

How do I get Bison/YACC to not recognize a command until it parses the whole string?

I have some bison grammar: input: /* empty */ | input command ; command: builtin | external ; builtin: CD { printf("Changing to home directory...\n"); } | CD WORD { printf("Changing to directory %s\n", $2);…
chucknelson
  • 2,328
  • 3
  • 24
  • 31
5
votes
2 answers

Problems with yylval and yylloc after switching to bison 3.0

after upgrading from bison 2.7 to 3.0 I changed the following two lines in my parser definition file (.yy) -------old-------- %define parser_class_name smathparser %name-prefix = "imath" -------new-------- %define api.prefix {imath} %define…
jrheinlaender
  • 59
  • 1
  • 6
5
votes
3 answers

Where to free memory in Bison/Flex?

I'm using Bison & Flex for 1 month more or less, so I'm sorry if I don't see something obvious (but I don't think it is). I have a problem about freeing memory with Flex Bison. Here is what my code looks like: parser.l {DATE} { yylval.str=…
blackmesa
  • 250
  • 4
  • 14
5
votes
3 answers

Bison : Line number included in the error messages

OK, so I suppose my question is quite self-explanatory. I'm currently building a parser in Bison, and I want to make error reporting somewhat better. Currently, I've set %define parse.error verbose (which actually gives messages like syntax error,…
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
5
votes
1 answer

Unit test of flex bison scanner parse, how to drive the test case

I have a question about how to "drive" a flex bison based parser scanner in a unit test. The final solution will be a command parser available or telnet to a target board. I have a fully working flex bison implementation using stdin. Right now my…
rmcarlsson
  • 91
  • 6
5
votes
1 answer

Bison-Flex extern FILE *yyin isn't working (C language)

I know that in flex you just have to do yyin = fopen(filename, "r"); to read a file but if you want to do it from bison how is it possible? I'm trying to combine flex and bison for my purpose(read a file with 4 + 5 + 7; and print the outcome) but I…
captain monk
  • 719
  • 4
  • 11
  • 34
5
votes
2 answers

where to find a real example on flex and bison?

i need a n example on flex and bison , so i can learn how to build ast tree and symbol table and do semantic analysis
Radi
  • 6,548
  • 18
  • 63
  • 91
5
votes
1 answer

LR(k) to LR(1) grammar conversion

I am confused by the following quote from Wikipedia: In other words, if a language was reasonable enough to allow an efficient one-pass parser, it could be described by an LR(k) grammar. And that grammar could always be mechanically transformed…
user1095108
  • 14,119
  • 9
  • 58
  • 116
5
votes
1 answer

Can't figure out why Bison is throwing "Rules useless in parser due to conflicts"

I'm writing a BNF grammar for a very simple programming language and using Flex and Bison to compile. I only have 3 variable and constant types: real, integer, string. My .l file has a token definition for "ID" as follows: DIGIT [0-9] LETTER…
patr1c1a
  • 237
  • 4
  • 16
5
votes
1 answer

Flex/bison syntax error

I am trying to write a grammar which will be able to consume the following input: begin #this is a example x = 56; while x > 0 do begin point 15.6 78.96; end; end; Here is the lexer.l file: %option noyywrap %{ #include…
Vardan Hovhannisyan
  • 1,101
  • 3
  • 17
  • 40
5
votes
1 answer

Flex/Bison: segmentation fault core dump

I'm writing a simple calculator based on .gertrude esolang. What I'm trying to do is parse a text file that contains ratios (in the form of n/m) with flex, than check if the ratio is an index for an operation (+ - / *) or a number and than send the…
thebeefeater
  • 53
  • 1
  • 4
5
votes
1 answer

Why can't LEX/YACC be used to parse C++ for a compiler?

I'm aware there's a reason but I haven't found a good, concise explanation as to why LEX/YACC cannot be used for C++. I am also interested to know whether LEX/YACC could be used to parse Objective C, or whether that language suffers from the same…
Poppy
  • 59
  • 1
  • 3