forked from t123yh/compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_program.cpp
32 lines (29 loc) · 1.07 KB
/
parser_program.cpp
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
//
// Created by t123yh on 2020/10/1.
//
#include "parser_program.h"
#include "parser_variable.h"
#include "parser_function.h"
program_parser::return_type program_parser::parse(parsing_context &context) const {
program result;
std::vector<var_def>& global_symbol_table = result.symbols;
if (context.match(const_description_parser())) {
auto r = context.expect_one(const_description_parser());
for (auto& x : r) {
global_symbol_table.push_back(x);
}
}
if (context.match(var_definition_parser()) && !context.match(decl_header_parser(), token_parser<LPARENT>())) {
auto r = context.expect_one( var_description_parser());
for (auto& x : r) {
global_symbol_table.push_back(x);
}
}
while (!context.match(token_parser<VOIDTK>(), token_parser<MAINTK>())) {
auto func = context.expect_one(function_parser());
result.functions.push_back(std::move(func));
}
result.main_function = context.expect_one(main_function_parser());
context.record("程序");
return result;
}