-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpl.y
89 lines (81 loc) · 2.05 KB
/
mpl.y
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
%{
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
extern int yylineno;
extern int yylex();
void yyerror(char *s);
%}
%token GE LE IS ISNT
%token AND OR NOT
%token REAL ALPHA NUMBER
%token UNTIL DO END_LOOP IF ELSE_IF DEFUALT THEN END_IF
%token IDENTIFIER
%token NUMBERVAL ALPHAVAL REALVAL
%token END
%nonassoc LOWER_ELSE
%nonassoc DEFAULT
%right GE LE '<' '>' IS ISNT
%left NOT
%left OR
%left AND
%left '+' '-'
%left '*' '/'
%%
program: stmt
| program stmt
;
stmt: ','
| exp ','
| ifStruct
| loopStruct
| END {printf("--------------------------------------------------------\nPROGRAM EXECUTED WITH NO ERRORS NUMBER OF LINES >> %d\n",yylineno);exit(0);}
;
exp:
| IDENTIFIER
| literal
| declartion
| exp IS exp
| exp ISNT exp
| exp '+' exp
| exp '-' exp
| exp '*' exp
| exp '/' exp
| exp LE exp
| exp GE exp
| exp OR exp
| exp AND exp
| exp NOT exp
| exp '>' exp
| exp '<' exp
| '(' exp ')'
;
declartion: REAL IDENTIFIER
| ALPHA IDENTIFIER
| NUMBER IDENTIFIER
;
ifStruct: IF exp THEN stmt %prec LOWER_ELSE
| IF exp THEN stmt DEFAULT THEN stmt
;
loopStruct: UNTIL exp DO stmt END_LOOP
;
literal: NUMBERVAL
| ALPHAVAL
| REALVAL
;
%%
void yyerror(char *s) {
fprintf(stderr, "Error | Line: %d >> %s\n",yylineno,s);
exit(0);
}
int main(){
printf(" _____ _ _ \n");
printf("| __ \\ | | | | \n");
printf("| |__) |__ ___ _ _ __| | ___ ______ ___ _ _ __| | ___ \n");
printf("| ___/ __|/ _ \\ | | |/ _` |/ _ \\______/ __| | | |/ _` |/ _ \\ \n");
printf("| | \\__ \\ __/ |_| | (_| | (_) | \\__ \\ |_| | (_| | (_) |\n");
printf("|_| |___/\\___|\\__,_|\\__,_|\\___/ |___/\\__,_|\\__,_|\\___/ \n");
printf("\n\tWELCOME PLEASE START WRITING CODE AND TO END JUST TYPE END\n--------------------------------------------------------\n");
yyparse();
return 0;
}