-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprogram.hpp
More file actions
54 lines (41 loc) · 1.72 KB
/
program.hpp
File metadata and controls
54 lines (41 loc) · 1.72 KB
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
/*=============================================================================
Copyright (c) 2001-2009 Joel de Guzman
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef PROGRAM_HPP_
#define PROGRAM_HPP_
#include "white_space.hpp"
#include "statement.hpp"
#include "compile_op.hpp"
#include "function_adder.hpp"
#include "function_state_reset.hpp"
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <vector>
///////////////////////////////////////////////////////////////////////////////
// Our program grammar and compiler
///////////////////////////////////////////////////////////////////////////////
template <typename Iterator>
struct program : boost::spirit::qi::grammar<Iterator, white_space<Iterator> >
{
program(std::vector<int>& code);
typedef white_space<Iterator> white_space_;
std::vector<int>& code;
boost::spirit::qi::rule<Iterator, std::string(), white_space_> identifier;
boost::spirit::qi::rule<Iterator, white_space_> start;
typedef
boost::spirit::qi::locals<
std::string // function name
, int // address
>
function_locals;
boost::spirit::qi::symbols<char, function_info> functions;
statement<Iterator> statement_;
boost::spirit::qi::rule<Iterator, function_locals, white_space_>
function_definition;
boost::phoenix::function<function_adder> add_function;
boost::phoenix::function<function_state_reset> state_reset;
boost::phoenix::function<compile_op> op;
};
#endif /* PROGRAM_HPP_ */