-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile2.y
More file actions
44 lines (43 loc) · 770 Bytes
/
file2.y
File metadata and controls
44 lines (43 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
%{
#include <stdio.h>
#include <stdlib.h>
int yylex();
int res=0;
int flag=0;
void yyerror(char *s);
%}
%start S
%token DEFINE ID TYPE NUM
%right "="
%left '+' '-'
%left '*' '/'
%right UMINUS
%left '!'
%%
S : DEFINE ID TYPE ';' {printf("\ninput accepted Type macro");exit(0);}
| DEFINE ID E ';' {printf("\ninput accepted Arithmetic expression");
printf("%d",$3);
exit(0);} ;
E: E'+'E {$$ = $1 + $3;}
|E'-'E {$$= $1 - $3;}
|E'*'E {$$= $1 * $3;}
|E'/'E {$$= $1 / $3;}
|E'^'E
|'('E')'
|'-'E %prec UMINUS
|ID
|NUM
;
%%
int yywrap()
{
return 1;
}
void main()
{
printf("enter");
yyparse();
}
void yyerror(char *s){
extern int yylineno;
fprintf(stderr,"line no %d:%s \n",yylineno,s);}