当我在Ubuntu
中输入此命令时,我写了一个bison的解析器 bison bison.txt
它会返回以下错误:
Inspiron-N5110:~/Desktop/BisonProject$ bison bison.txt "bison.txt", line 10: unknown character with code 0xd in declaration section "bison.txt", line 10: no input grammar *** Error in `bison': double free or corruption (!prev): 0x0000000000915780 *** Aborted (core dumped)
bison.txt:
%{
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include "lex.yy.c"
void yyerror(char *);
extern FILE* yyin;
extern char* yytext;
%}
%token int_kw void_kw bool_kw open_bracket close_bracket number semicolon ID comma
%start Program
%%
Program:
DeclarationList;
DeclarationList:
DeclarationList Declaration | Declaration;
Declaration:
VarDeclaration;
VarDeclaration:
TypeSpecifier VarDecList;
VarDecList:
VarDecList comma VarDecId | VarDecId;
VarDecId:
ID | ID open_bracket number close_bracket ;
TypeSpecifier:
int_kw | void_kw | bool_kw;
%%
int main(){
char fname[50];
printf("Enter the name of your file:\n");
scanf("%s",fname);
fopen(fname,"r");
yyparse();
return 0;
}
void yyerror(char *s1){
printf("%s\n",s1);
return;
}