]>
Commit | Line | Data |
---|---|---|
2f1a1aea | 1 | // -*- C++ -*- |
69c68955 FCE |
2 | // Copyright (C) 2005 Red Hat Inc. |
3 | // | |
4 | // This file is part of systemtap, and is free software. You can | |
5 | // redistribute it and/or modify it under the terms of the GNU General | |
6 | // Public License (GPL); either version 2, or (at your option) any | |
7 | // later version. | |
8 | ||
2f1a1aea | 9 | |
2b066ec1 FCE |
10 | #ifndef PARSE_H |
11 | #define PARSE_H | |
12 | ||
2f1a1aea FCE |
13 | #include <string> |
14 | #include <fstream> | |
15 | #include <iostream> | |
16 | #include <vector> | |
17 | #include <stdexcept> | |
18 | ||
19 | ||
20 | struct source_loc | |
21 | { | |
22 | std::string file; | |
23 | unsigned line; | |
24 | unsigned column; | |
25 | }; | |
26 | ||
27 | ||
28 | enum token_type | |
29 | { | |
54dfabe9 FCE |
30 | tok_junk, tok_identifier, tok_operator, tok_string, tok_number, |
31 | tok_embedded | |
2b066ec1 | 32 | // XXX: add tok_keyword throughout |
2f1a1aea FCE |
33 | }; |
34 | ||
0fefb486 | 35 | |
2f1a1aea FCE |
36 | struct token |
37 | { | |
38 | source_loc location; | |
39 | token_type type; | |
40 | std::string content; | |
41 | }; | |
42 | ||
0fefb486 | 43 | |
56099f08 FCE |
44 | std::ostream& operator << (std::ostream& o, const token& t); |
45 | ||
2f1a1aea FCE |
46 | |
47 | struct parse_error: public std::runtime_error | |
48 | { | |
49 | parse_error (const std::string& msg): runtime_error (msg) {} | |
50 | }; | |
51 | ||
52 | ||
53 | class lexer | |
54 | { | |
55 | public: | |
56 | token* scan (); | |
57 | lexer (std::istream&, const std::string&); | |
58 | ||
59 | private: | |
60 | int input_get (); | |
bb2e3076 | 61 | int input_peek (unsigned n=0); |
2f1a1aea FCE |
62 | std::istream& input; |
63 | std::string input_name; | |
bb2e3076 | 64 | std::vector<int> lookahead; |
2f1a1aea FCE |
65 | unsigned cursor_line; |
66 | unsigned cursor_column; | |
67 | }; | |
68 | ||
69 | ||
70 | class parser | |
71 | { | |
72 | public: | |
24cb178f FCE |
73 | parser (std::istream& i, bool p); |
74 | parser (const std::string& n, bool p); | |
2f1a1aea FCE |
75 | ~parser (); |
76 | ||
77 | stapfile* parse (); | |
78 | ||
24cb178f FCE |
79 | static stapfile* parse (std::istream& i, bool privileged); |
80 | static stapfile* parse (const std::string& n, bool privileged); | |
82919855 | 81 | |
2f1a1aea FCE |
82 | private: |
83 | std::string input_name; | |
84 | std::istream* free_input; | |
85 | lexer input; | |
24cb178f | 86 | bool privileged; |
2f1a1aea FCE |
87 | |
88 | // scanning state | |
89 | const token* last (); | |
90 | const token* next (); | |
91 | const token* peek (); | |
92 | ||
93 | const token* last_t; // the last value returned by peek() or next() | |
94 | const token* next_t; // lookahead token | |
95 | ||
96 | void print_error (const parse_error& pe); | |
97 | unsigned num_errors; | |
98 | ||
99 | private: // nonterminals | |
54dfabe9 FCE |
100 | void parse_probe (std::vector<probe*>&, std::vector<probe_alias*>&); |
101 | void parse_global (std::vector<vardecl*>&); | |
24cb178f | 102 | void parse_functiondecl (std::vector<functiondecl*>&); |
54dfabe9 | 103 | embeddedcode* parse_embeddedcode (); |
9c0c0e46 | 104 | probe_point* parse_probe_point (); |
2f1a1aea | 105 | literal* parse_literal (); |
2f1a1aea FCE |
106 | block* parse_stmt_block (); |
107 | statement* parse_statement (); | |
108 | if_statement* parse_if_statement (); | |
69c68955 | 109 | for_loop* parse_for_loop (); |
f3c26ea5 | 110 | for_loop* parse_while_loop (); |
69c68955 FCE |
111 | foreach_loop* parse_foreach_loop (); |
112 | expr_statement* parse_expr_statement (); | |
56099f08 FCE |
113 | return_statement* parse_return_statement (); |
114 | delete_statement* parse_delete_statement (); | |
f3c26ea5 FCE |
115 | next_statement* parse_next_statement (); |
116 | break_statement* parse_break_statement (); | |
117 | continue_statement* parse_continue_statement (); | |
2f1a1aea FCE |
118 | expression* parse_expression (); |
119 | expression* parse_assignment (); | |
120 | expression* parse_ternary (); | |
121 | expression* parse_logical_or (); | |
122 | expression* parse_logical_and (); | |
bb2e3076 FCE |
123 | expression* parse_boolean_or (); |
124 | expression* parse_boolean_xor (); | |
125 | expression* parse_boolean_and (); | |
2f1a1aea FCE |
126 | expression* parse_array_in (); |
127 | expression* parse_comparison (); | |
bb2e3076 | 128 | expression* parse_shift (); |
2f1a1aea FCE |
129 | expression* parse_concatenation (); |
130 | expression* parse_additive (); | |
131 | expression* parse_multiplicative (); | |
132 | expression* parse_unary (); | |
2f1a1aea FCE |
133 | expression* parse_crement (); |
134 | expression* parse_value (); | |
135 | expression* parse_symbol (); | |
136 | }; | |
2b066ec1 FCE |
137 | |
138 | ||
139 | ||
140 | #endif // PARSE_H |