-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptable.c
89 lines (84 loc) · 2.13 KB
/
ptable.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
/**
* @file ptable.c
* @author Anastasia Butok (xbutok00@vutbr.cz)
* @brief Precedence table for PSA along with getSymbolValue LUT.
* @version 0.1
* @date 2023-11-24
*
* @copyright Copyright (c) 2023
* Project: IFJ compiler
*
*/
#include "psa.h"
char P_TABLE[10][10] = {
// INPUT >
//! */ +- REL LOG ?? i ( ) $
{'-', '>', '>', '>', '>', '>', '<', '<', '>', '>'}, // !
{'<', '>', '>', '>', '>', '>', '<', '<', '>', '>'}, // */
{'<', '<', '>', '>', '>', '>', '<', '<', '>', '>'}, // +-
{'<', '<', '<', '>', '>', '>', '<', '<', '>', '>'}, // REL
{'<', '<', '<', '<', '>', '>', '<', '<', '>', '>'}, // LOG
{'<', '<', '<', '<', '<', '>', '<', '<', '>', '>'}, // ??
{'>', '>', '>', '>', '>', '>', '-', '-', '>', '>'}, // i
{'<', '<', '<', '<', '<', '<', '<', '<', '=', '-'}, // (
{'>', '>', '>', '>', '>', '>', '-', '-', '>', '>'}, // )
{'<', '<', '<', '<', '<', '<', '<', '<', '-', '-'}, // $
// ^ TOP OF STACK
// REL = RELATIONAL OPERATOR (==, !=, <, >, <=, >=)
// LOG = LOGICAL OPERATOR (&&, ||)
};
unsigned int getSymbolValue(Token_type token)
{
// symbols: !,* /,+ -,== != < > <= >=,??,i,(,),$
switch (token)
{
// !
case TOKEN_NOT:
return 0;
// */
case TOKEN_MUL:
case TOKEN_DIV:
return 1;
// +-
case TOKEN_PLUS:
case TOKEN_MINUS:
return 2;
// REL: == != < > <= >=
case TOKEN_EQ:
case TOKEN_NEQ:
case TOKEN_LESS:
case TOKEN_MORE:
case TOKEN_LESS_EQ:
case TOKEN_MORE_EQ:
return 3;
// LOG: && ||
case TOKEN_AND:
case TOKEN_OR:
return 4;
// ??
case TOKEN_BINARY_OPERATOR:
return 5;
// i
case TOKEN_IDENTIFICATOR:
case TOKEN_FUNC_ID:
case TOKEN_INT:
case TOKEN_DOUBLE:
case TOKEN_EXP:
case TOKEN_BOOL:
case TOKEN_STRING:
case TOKEN_NIL:
return 6;
// (
case TOKEN_L_BRACKET:
return 7;
// )
case TOKEN_R_BRACKET:
return 8;
// $
case TOKEN_EOF:
return 9;
// error
default:
return 99;
}
}