-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursive Predictor.cpp
More file actions
79 lines (76 loc) · 895 Bytes
/
Recursive Predictor.cpp
File metadata and controls
79 lines (76 loc) · 895 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
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
#include <iostream>
#include <conio.h>
#include <stdlib.h>
using namespace std;
char lookhead;
void match();
void error();
void E();
void R();
void T();
void M();
void F();
int main(){
lookhead = getche();
E();
cout<<"\nAccepted"<<endl;
getch();
return 0;
}
void match(char symbol){
if(lookhead == symbol) lookhead = getche();
else error();
return;
}
void error(){
cout << "\nError";
exit(0);
}
void E(){
T();
R();
}
void R(){
if(lookhead == '+'){
match('+');
T();
R();
}
else;
return;
}
void T(){
F();
M();
}
void M(){
if(lookhead == '*'){
match('*');
F();
M();
}
else;
return;
}
void F(){
if(lookhead == '('){
match('(');
E();
match(')');
}
else if(lookhead == 'i'){
match('i');
match('d');
}
else error();
return;
}
/*
E --> TR
R --> +TR | ε
T --> FM
M --> *FM | ε
F --> (E) | id
example :
id*id+(id)+id*(id)+id*id+(id)
*/