-
Notifications
You must be signed in to change notification settings - Fork 0
/
optab.c
91 lines (81 loc) · 4.1 KB
/
optab.c
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
90
91
/**********************************************************************/
/* lab 1 DVG C01 - Operator Table OBJECT */
/**********************************************************************/
/**********************************************************************/
/* Include files */
/**********************************************************************/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
/**********************************************************************/
/* Other OBJECT's METHODS (IMPORTED) */
/**********************************************************************/
#include "keytoktab.h"
/**********************************************************************/
/* OBJECT ATTRIBUTES FOR THIS OBJECT (C MODULE) */
/**********************************************************************/
#define NENTS 4
static int optab[][NENTS] = {
{'+', integer, integer, integer},
{'+', real, real, real},
{'+', integer, real, real},
{'+', real, integer, real},
{'*', integer, integer, integer},
{'*', real, real, real},
{'*', integer, real, real},
{'*', real, integer, real},
{'$', undef, undef, undef}
};
/**********************************************************************/
/* PRIVATE METHODS for this OBJECT (using "static" in C) */
/**********************************************************************/
/**********************************************************************/
/* PUBLIC METHODS for this OBJECT (EXPORTED) */
/**********************************************************************/
void p_optab()
{
printf("\n________________________________________________________\nTHE OPERATOR TABLE\n________________________________________________________\n");
printf("\noperator\t\targ1\t\targ2\t\tresult\n________________________________________________________");
int i = 0;
while(i < 7)
{
<<<<<<< HEAD
printf("\n\t%s,\t\t%s,\t\t%s,\t\t%s", tok2lex(optab[i][0]), tok2lex(optab[i][1]), tok2lex(optab[i][2]), tok2lex(optab[i][3]));
=======
printf("\n\t\t\t%s,\t\t%s,\t\t%s,\t\t%s", tok2lex(optab[i][0]), tok2lex(optab[i][1]), tok2lex(optab[i][2]), tok2lex(optab[i][3]));
>>>>>>> 5d2f52e96458d03d51c9b62dbf3dfce636fe3119
i++;
}
printf("\n________________________________________________________");
}
/**********************************************************************/
/* return the type of a binary expression op arg1 arg2 */
/**********************************************************************/
int get_otype(int op, int arg1, int arg2)
{
<<<<<<< HEAD
int i = 0;
while(i < 7)
{
//printf("\nComparing: %s with %s\n%s with %s\n%s with %s\n\n", tok2lex(op), tok2lex(optab[i][0]), tok2lex(arg1), tok2lex(optab[i][1]), tok2lex(arg2),tok2lex(optab[i][2]));
if(strcmp(tok2lex(op), tok2lex(optab[i][0])) == 0 && strcmp(tok2lex(arg1), tok2lex(optab[i][1])) == 0 && strcmp(tok2lex(arg2), tok2lex(optab[i][2])) == 0)
{
//printf("\n*** RETURNING: %s\t%s\t%s\t%s", tok2lex(optab[i][0]), tok2lex(optab[i][1]), tok2lex(optab[i][2]), tok2lex(optab[i][3]));
return optab[i][3];
}else if(strcmp(tok2lex(op), tok2lex(optab[i][0])) == 0 && strcmp(tok2lex(arg2), tok2lex(optab[i][1])) == 0 && strcmp(tok2lex(arg1), tok2lex(optab[i][2])) == 0)
{
//printf("\n*** RETURNING: %s\t%s\t%s\t%s", tok2lex(optab[i][0]), tok2lex(optab[i][1]), tok2lex(optab[i][2]), tok2lex(optab[i][3]));
return optab[i][3];
}
i++;
}
//printf("\n*** RETURNING: %s\t%s\t%s\t%s", tok2lex(optab[8][0]), tok2lex(optab[8][1]), tok2lex(optab[8][2]), tok2lex(optab[8][3]));
return optab[8][3];
=======
printf("*** TO BE DONE!");
return 0;
>>>>>>> 5d2f52e96458d03d51c9b62dbf3dfce636fe3119
}
/**********************************************************************/
/* End of code */
/**********************************************************************/