0
votes
%{
#include <stdio.h>
#include <string.h>

void yyerror(const char *str)
{
        fprintf(stderr,"error: %s\n",str);
}

int yywrap()
{
        return 1;
}

int main()
{
        yyparse();
}
%}

%token TOKMACHINE TOKLOGIN TOKPASSWORD VALUE SPACE NEWLINE
input: auth input | input;
delim: SPACE | NEWLINE;
auth: TOKMACHINE delim VALUE delim TOKLOGIN delim  VALUE delim  TOKPASSWORD delim VALUE delim
{
    printf("Found auth {%s,%s,%s}", $1,$3,$5);
};

Here is simple bison grammar, with which I want to parse .netrc file. But I get error on input line:

netrc.y:23.1-5: syntax error, unexpected identifier:

I am new to Flex/Bison, but this example near literal copy from here

2
Line 23 is input: auth input | input;; columns 1-5 are the identifier input, which seems to be what it's complaining about. I don't remember bison well enough to figure out the problem. - Keith Thompson
This is anything but a near literal copy. Look at the original example exactly and you'll spot a handful of differences, all resulting in various errors. Yacc is unforgiving. - Jens
@Jens Of course, this question is about Bison, not Yacc, but they are part of the same bestiary... ;-) - twalberg

2 Answers

2
votes

Looks like you are missing the %% delimiter. Make that

%}
%token ...

%%
input : ...
2
votes

You need a %% line after your %token line to separate the definitions section from the grammar section.