lex
%{ #include <string.h> #include <stdio.h> #include "y.tab.h" #define N 9 %} %% [1-9][0-9]* { printf("%s",yytext); strcpy(yylval.ystr,yytext); return (DEC_CONST); } "*" { printf("%s",yytext); strcpy(yylval.ystr,yytext); return ('*'); } "/" { printf("%s",yytext); strcpy(yylval.ystr,yytext); return ('/'); } "%" { printf("%s",yytext); strcpy(yylval.ystr,yytext); return ('%'); } "+" { printf("%s",yytext); strcpy(yylval.ystr,yytext); return ('+'); } "-" { printf("%s",yytext); strcpy(yylval.ystr,yytext); return ('-'); } "=" { printf("%s",yytext); strcpy(yylval.ystr,yytext); return ('='); } "(" { printf("%s",yytext); strcpy(yylval.ystr,yytext); return ('('); } ")" { printf("%s",yytext); strcpy(yylval.ystr,yytext); return (')'); } [a-zA-Z]([a-zA-Z]|[0-9])* { int i; printf("%s",yytext); i=id_or_keyword(yytext); if(i==ID) strcpy(yylval.ystr,yytext); else yylval.yint=i; return (i); } [ \f\n\r\t]+ printf("%s",yytext); . { printf("Agnwstos xaraktiras %s\n",yytext); } %% static char *kid[N]={"and","else","if","int","not","or","print","read","while"}; static int kval[N]={AND,ELSE,IF,INT,NOT,OR,PRINT,READ,WHILE}; int id_or_keyword(char *s){ int i; for(i=0; (i<N) && (strcmp(s,kid[i]) != 0);i++); if(i<N) return kval[i]; else return ID; }
yacc
%{ #include <string.h> #include <stdlib.h> #include <stdio.h> #include <ctype.h> %} %union { int yint; char ystr[81]; int nonterm; } %token <yint> AND ELSE IF INT NOT OR PRINT READ WHILE %token <ystr> DEC_CONST %token <ystr> '(' ')' %token <ystr> '*' '/' '%' '+' '-' '=' %token <ystr> ID %type <nonterm> PrimExpr Literal ParenExpr PrefixExpr MultExpr %type <nonterm> AddExpr Expr %start Expr %% PrimExpr : Literal { $$=$1; } ; Literal : DEC_CONST { $$=atoi($1); } ; ParenExpr : PrimExpr { $$=$1; } | '(' Expr ')' { $$=$2; } ; PrefixExpr : ParenExpr { $$=$1; } ; MultExpr : PrefixExpr { $$=$1; } | MultExpr '*' PrefixExpr { $$=$1*$3; } | MultExpr '/' PrefixExpr { $$=$1/$3; } | MultExpr '%' PrefixExpr { $$=$1%$3; } ; AddExpr : MultExpr { $$=$1; } | AddExpr '+' MultExpr { $$=$1+$3; } | AddExpr '=' MultExpr { $$=$1-$3; } ; Expr : AddExpr { $$=$1; printf("To apotelesma einai:%d\n",$1); } ; %% void yyerror(char *s) { fputs(s,stderr); putc('\n',stderr); } main(void) { yyparse(); }
I just want to show me why i have this error:
syd:90: warning: conflicting types for 'yyerror'
y.tab.c:1475: warning: previous implicit declaration of 'yyerror' was here
Undefined symbols:
"_yywrap", referenced from:
_yylex in ccy3LNwv.o
_input in ccy3LNwv.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Thanks in advance.