I haven't worked on this in ages, illness somewhat interrupted my line of thought...
[fridhskrift.git] / fridh / parser.hpp
blob6355a5a6da377af5989c9f9b0e061034c8675a42
1 #pragma once
3 #include <string>
4 #include <vector>
5 #include <ail/types.hpp>
6 #include <fridh/symbol.hpp>
7 #include <fridh/lexer.hpp>
9 namespace fridh
11 namespace statement_processing
13 enum type
15 unrestricted,
16 atomic_only
20 struct sorted_binary_operator_entry
23 std::size_t index;
26 class parser
28 public:
29 parser();
30 bool process_module(std::string const & path, std::string const & name, module & output, std::string & error_message);
32 private:
33 bool running;
35 std::size_t
36 line_offset,
37 line_end;
39 uword indentation_level;
41 std::size_t
42 lexeme_offset,
43 lexeme_end;
45 uword nested_class_level;
47 lines_of_code lines;
49 symbol_tree_node * current_node;
51 bool name_is_used(std::string const & name);
52 std::string const & get_declaration_name();
53 void name_collision_check();
54 symbol_tree_node & add_name(symbol::type symbol_type);
56 void process_body(executable_units * output = 0, bool increment = true);
58 void process_atomic_statement(lexeme_container & lexemes, std::size_t & offset, parse_tree_nodes & output, bool allow_multi_statements = false, lexeme_type::type terminator = lexeme_type::non_terminating_placeholder, bool allow_empty_statements = false);
59 void process_offset_atomic_statement(parse_tree_node & output, std::size_t offset = 0);
60 void process_composite_term(parse_tree_node & output);
62 bool is_if_statement();
64 bool process_if(executable_unit & output);
65 bool process_while(executable_unit & output);
66 bool process_for(executable_unit & output);
67 bool process_return(executable_unit & output);
69 bool process_class();
70 bool process_function(function * output = 0);
71 void process_statement(executable_unit & output);
72 bool process_line(executable_unit * output = 0);
74 bool translate_data(module & target_module, std::string const & data, std::string const & module_name, std::string & error_message_output);
76 lexeme_container & get_lexemes();
78 void error(std::string const & message);
79 void single_lexeme_error(std::string const & message, std::size_t offset);
80 void double_lexeme_error(std::string const & message, std::size_t offset);
82 void process_node_group(parse_tree_nodes & arguments, parse_tree_nodes & output);
83 void operator_resolution(parse_tree_nodes & input, parse_tree_node & output);
85 void scope_up();
88 void lexeme_to_argument_node(lexeme & input, parse_tree_node & output);
89 void lexeme_to_unary_operator_node(lexeme & input, parse_tree_node & output);
90 void lexeme_to_binary_operator_node(lexeme & input, parse_tree_node & output);
92 word get_unary_operator_precedence(unary_operator_type::type input);
93 word get_binary_operator_precedence(binary_operator_type::type input);
94 bool get_parse_tree_node_precedence(parse_tree_node & input, word & output);
96 bool is_right_to_left_operator(parse_tree_node & input);
98 bool is_unary_post_fix_operator(lexeme_type::type input);