Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird C code in Bison (yyerror)

Tags:

c

bison

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 what this actually means.

The code I refer to is from http://dinosaur.compilertools.net/bison/bison_7.html#SEC66 :

yyerror (s) 
     char *s;
{
  // Some code here
}
like image 484
rickythefox Avatar asked Dec 06 '11 15:12

rickythefox


4 Answers

That's K&R C

In modern C (C89/90 or C99) that would be:

int yyerror(char *s)
{
}
like image 153
Šimon Tóth Avatar answered Oct 08 '22 02:10

Šimon Tóth


It means

int yyerror(char* s){
  //some code here
}

code attached to your question is just another way of specifying function argument types.

like image 44
KCH Avatar answered Oct 08 '22 03:10

KCH


GNU bison is now at version 2.5, see here. Why do you use such an ancient version (you refer to bison 1.25 from 1996)?

The  yyerror function is for error recovery. A simple example is here

like image 1
Basile Starynkevitch Avatar answered Oct 08 '22 02:10

Basile Starynkevitch


This is old K&R C.

like image 3
Some programmer dude Avatar answered Oct 08 '22 01:10

Some programmer dude