2014-12-08 6 views
-1
내가 주석 행은 # 문자 여기 에 태초에 간단한 계산기를 만들기 위해 노력하고있어

이 .L 파일 코드플렉스/들소 계산기 - 컴파일 오류가

%{ 
#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
#include "y.tab.h" 
char str[256]; 
void yyerror(char *); 
%} 

%x COM 

%% 
<INITIAL>^# BEGIN(COM); 
<COM>[\t\x20-\x7E]*\\\n ; 
<COM>[\t\x20-\x7E]* ; BEGIN(INITIAL); 
<COM>[\t\x20-\x7E]*\\* ; BEGIN(INITIAL); 
[ \t]+ ; 
[0-9]+ { yylval = atoi(yytext); strcat(str,yytext); strcat(str, " ") ; return INTEGER;} 
\\\n ; 
[-\+\*\/\^()%] {strcat(str, yytext); strcat(str," ") ;return *yytext;} 
\n { str[0] = '\0'; return *yytext;} 
. { char msg[25]; sprintf(msg, "niedozwolony znak '%s'", yytext); yyerror(msg);} 

%% 


int yywrap(void) 
{ 
    return 1; 
}} 

.Y 파일입니다

%{ 
#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
#include <math.h> 
int yylex(void); 
void yyerror(char *s) 

%} 

%token INTEGER 

%% 

program: 
program line 
| line 
; 

line: 
expr '\n' {printf("%d\n",$1);} 
| '\n' 
; 

expr: 
expr '-' mulex { $$ = $1 - $3; } 
| mulex { $$ = $1; } 
; 

mulex: 
mulex '*' term { $$ = $1 * $3; } 
| mulex '/' term { $$ = $1/$3; } 
| mulex '^' term { $$ = pow($1,$3); } 
| mulex '%' term { $$ = $1 % $3; } 
| term { $$ = $1; } 
; 

term: 
'(' expr ')' { $$ = $2 } 
| INTEGER { $$ = $1 } 
; 

%% 

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

int main(void) 
{ 
    /* yydebug = 1; */ 
    yyparse(); 
    return 0; 
} 

및 여기에 오류가 있습니다

C:\Users\User\Desktop>gcc lex.yy.c y.tab.c -o calc 
calc.l:31:2: error: expected identifier or '(' before '}' token 
y.tab.c: In function 'yyerror': 
y.tab.c:109:4: warning: empty declaration [enabled by default] 
y.tab.c:120:13: error: storage class specified for parameter 'YYSTYPE' 
y.tab.c:140:23: error: storage class specified for parameter 'yytype_uint8' 
y.tab.c:147:21: error: storage class specified for parameter 'yytype_int8' 
y.tab.c:155:28: error: storage class specified for parameter 'yytype_uint16' 
y.tab.c:161:19: error: storage class specified for parameter 'yytype_int16' 
y.tab.c:294:3: error: expected specifier-qualifier-list before 'yytype_int16' 
y.tab.c:292:1: warning: empty declaration [enabled by default] 
y.tab.c:365:27: error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 
yytranslate' 
y.tab.c:393:2: error: expected declaration specifiers before ';' token 
y.tab.c:444:27: error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 
yyr1' 
y.tab.c:448:2: error: expected declaration specifiers before ';' token 
y.tab.c:451:27: error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 
yyr2' 
y.tab.c:455:2: error: expected declaration specifiers before ';' token 
y.tab.c:460:27: error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 
yydefact' 
y.tab.c:465:2: error: expected declaration specifiers before ';' token 
y.tab.c:468:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 
yydefgoto' 
y.tab.c:471:2: error: expected declaration specifiers before ';' token 
y.tab.c:476:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 
yypact' 
y.tab.c:481:2: error: expected declaration specifiers before ';' token 
y.tab.c:484:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 
yypgoto' 
y.tab.c:487:2: error: expected declaration specifiers before ';' token 
y.tab.c:494:27: error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 
yytable' 
y.tab.c:499:2: error: expected declaration specifiers before ';' token 
y.tab.c:501:27: error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 
yycheck' 
y.tab.c:506:2: error: expected declaration specifiers before ';' token 
y.tab.c:510:27: error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 
yystos' 
y.tab.c:515:2: error: expected declaration specifiers before ';' token 
y.tab.c:1008:44: error: expected declaration specifiers or '...' before 'YYSTYPE 
' 
y.tab.c:1051:1: error: expected declaration specifiers before 'YYSTYPE' 
y.tab.c:1083:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 
{' token 
calc.y:46:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' 
token 
calc.y:51:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' 
token 
calc.y:7:6: error: old-style parameter declarations in prototyped function defin 
ition 
calc.y:55:1: error: expected '{' at end of input 

그래서 내가 뭔가 잘못하고있는 중이거나 flex-bison이 Windows 시스템에서 고장났습니다. tem? 오류가 있습니다. 일부 닫혀 있지 않은 중괄호가 있지만 그 수가 참이 아니라고 계산합니다.

+2

필자는 flex-bison을 사용하지 않지만, .l 파일의 yyerror 프로토 타입 이후에';'가 없습니까? –

+0

'char str [256]; void yyerror (char *); '그것이있다 – whd

+2

죄송합니다. y 파일을 말합니다 :'int yylex (void); void yyerror (char * s)'입니다. –

답변

0

의견에 요청한대로 모든 것이 첫 번째 게시물 아래에 댓글에 있습니다.