-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.h
119 lines (105 loc) · 2.63 KB
/
parser.h
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Project name:
* Implementace interpretu imperativního jazyka IFJ14
*
* Repository:
* https://github.com/Dasio/IFJ
*
* Team:
* Dávid Mikuš (xmikus15)
* Peter Hostačný (xhosta03)
* Tomáš Kello (xkello00)
* Adam Lučanský (xlucan01)
* Michaela Lukášová (xlukas09)
*/
#ifndef PARSER_H
#define PARSER_H
#include "scanner.h"
#include "symbol.h"
#include "error.h"
#include "stack.h"
#include "expr.h"
#include "instruction.h"
void parse(TokenVector *tokvect);
void program();
void var_declr();
void var_def(uint8_t next);
void func();
void forward(SymbolType returnType);
void param_def_list();
void params_def(uint8_t next);
void compound_stmt(uint8_t semicolon);
void stmt_list();
void stmt_empty();
/**
* Process terms with brackets
* @return Count of parameters for write
*/
uint32_t term_list();
/**
* Process terms
* @param next If 1 TERMS_N else TERMS
* @return 1-if term was loaded
*/
uint8_t terms(uint8_t next);
/**
* @param1: 1 if stmt() was called from stmt_empty()
* @return: 1 if epsilon rule was used, else 0
*/
uint8_t stmt(uint8_t empty);
/**
* @return: 1 if epsilon rule was used, else 0
*/
uint8_t if_n(Instruction *if1, Instruction *if2);
void readln();
void write();
/**
* Add function to GST without returnType and stateFunc
* Add return symbol to LST of function
* @param name Name of function
*/
void addFunc(char *name);
/**
* Update info about actual function and check declaration and definition
* @param returnType Which type is function returning
* @param funcState Declaration/Definition
*/
void updateFunc(SymbolType returnType,FuncState funcState);
/**
* Add argument to function or if is called second time it will check name and type of arguments.
* @param type Type of argment
* @param name Name of argument
*/
void addArgToFunc(SymbolType type, char *name);
/**
* Check if all functions were defined
*/
void checkFuncDefinitions();
/**
* Add builtin functions
*/
void addBuiltInFunctions();
/**
* Find symbol in active context, if not found and active context was not function text, then it search in main context(GST)
* @param name Name of variable
* @param scope 0-global, 1-local
* @return Pointer to symbol or NULL if not found
*/
Symbol *findVar(char *name,VariableType *scope);
static inline SymbolType keywordToSymbol (KeywordTokenType key)
{
switch(key)
{
case Key_boolean:
return T_bool;
case Key_integer:
return T_int;
case Key_real:
return T_double;
case Key_string:
return T_String;
default:
return T_Undefined;
}
}
#endif