-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.h
71 lines (62 loc) · 1.91 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
/**
* Implementace překladače imperativního jazyka IFJ22
*
* @file parser.h
* @author Josef Kuchař ([email protected])
* @author Matej Sirovatka ([email protected])
* @author Tomáš Běhal ([email protected])
* @author Šimon Benčík ([email protected])
* @brief Header file for semantic and syntax parser
*/
#ifndef __PARSER_H__
#define __PARSER_H__
#include <stdbool.h>
#include "gen.h"
#include "scanner.h"
#include "symtable.h"
#include "token.h"
typedef struct {
scanner_t* scanner; // Scanner instance
gen_t* gen; // Generator instance
token_t token; // Current token
htab_t* local_symtable; // Local symbol table
htab_t* global_symtable; // Global symbol table
htab_pair_t* function; // Current function
htab_pair_t* function_call; // Current function call
int construct_count; // Counter of if/else/while constructs (for generator)
int param_count; // Counter of function call params (for checking)
bool buffer_token_valid; // Is old token valid?
token_t buffer_token; // Old token
bool last_default; // Was last case default?
} parser_t;
typedef struct {
bool in_loop; // Whether we're in a loop (e.g. while)
bool in_function; // Whether we're in a function
int construct_count;
int loop_parent;
} parser_state_t;
/**
* @brief Initialize parser
*
* @param scanner Scanner instance
* @return Initialized parser
*/
parser_t parser_new(scanner_t* scanner, gen_t* gen);
/**
* @brief Free exising parser
*
* @param state Parser state
*/
void parser_free(parser_t* state);
/**
* @brief Run parser
*
*/
void parser_run(parser_t* state);
/**
* @brief Asks scanner for next token and keeps the previous one
*
* @param parser Instance of parser
*/
void next_token_keep(parser_t* parser);
#endif // __PARSER_H__