]> sourceware.org Git - systemtap.git/blame - parse.h
2007-12-01 Frank Ch. Eigler <fche@elastic.org>
[systemtap.git] / parse.h
CommitLineData
2f1a1aea 1// -*- C++ -*-
28fdf926 2// Copyright (C) 2005-2007 Red Hat Inc.
5811366a 3// Copyright (C) 2007 Bull S.A.S
69c68955
FCE
4//
5// This file is part of systemtap, and is free software. You can
6// redistribute it and/or modify it under the terms of the GNU General
7// Public License (GPL); either version 2, or (at your option) any
8// later version.
9
2f1a1aea 10
2b066ec1
FCE
11#ifndef PARSE_H
12#define PARSE_H
13
2f1a1aea
FCE
14#include <string>
15#include <fstream>
16#include <iostream>
17#include <vector>
18#include <stdexcept>
19
20
21struct source_loc
22{
23 std::string file;
24 unsigned line;
25 unsigned column;
26};
27
0323ed4d 28std::ostream& operator << (std::ostream& o, const source_loc& loc);
2f1a1aea 29
6e213f58
DS
30enum parse_context
31 {
32 con_unknown, con_probe, con_global, con_function, con_embedded
33 };
34
35
2f1a1aea
FCE
36enum token_type
37 {
54dfabe9 38 tok_junk, tok_identifier, tok_operator, tok_string, tok_number,
6e213f58 39 tok_embedded, tok_keyword
2f1a1aea
FCE
40 };
41
0fefb486 42
2f1a1aea
FCE
43struct token
44{
45 source_loc location;
46 token_type type;
47 std::string content;
48};
49
0fefb486 50
56099f08
FCE
51std::ostream& operator << (std::ostream& o, const token& t);
52
2f1a1aea
FCE
53
54struct parse_error: public std::runtime_error
55{
177a8ead 56 const token* tok;
cd7116b8
FCE
57 bool skip_some;
58 parse_error (const std::string& msg):
59 runtime_error (msg), tok (0), skip_some (true) {}
60 parse_error (const std::string& msg, const token* t):
61 runtime_error (msg), tok (t), skip_some (true) {}
62 parse_error (const std::string& msg, bool skip):
63 runtime_error (msg), tok (0), skip_some (skip) {}
2f1a1aea
FCE
64};
65
66
dc38c0ae
DS
67struct systemtap_session;
68
2f1a1aea
FCE
69class lexer
70{
71public:
5811366a 72 token* scan (bool expand_args=true);
213bee8f 73 lexer (std::istream&, const std::string&, systemtap_session&);
2f1a1aea
FCE
74
75private:
76 int input_get ();
3f99432c
FCE
77 void input_put (int);
78 void input_put (const std::string&);
bb2e3076 79 int input_peek (unsigned n=0);
2f1a1aea
FCE
80 std::istream& input;
81 std::string input_name;
bb2e3076 82 std::vector<int> lookahead;
3f99432c 83 unsigned cursor_suspend_count;
2f1a1aea
FCE
84 unsigned cursor_line;
85 unsigned cursor_column;
213bee8f 86 systemtap_session& session;
2f1a1aea
FCE
87};
88
89
dc38c0ae
DS
90struct stapfile;
91struct probe;
92struct probe_alias;
93struct vardecl;
94struct functiondecl;
95struct embeddedcode;
96struct probe_point;
97struct literal;
98struct block;
99struct for_loop;
100struct statement;
101struct if_statement;
102struct foreach_loop;
103struct expr_statement;
104struct return_statement;
105struct delete_statement;
106struct break_statement;
107struct next_statement;
108struct continue_statement;
109struct indexable;
110struct expression;
111struct hist_op;
112
2f1a1aea
FCE
113class parser
114{
115public:
177a8ead
FCE
116 parser (systemtap_session& s, std::istream& i, bool p);
117 parser (systemtap_session& s, const std::string& n, bool p);
2f1a1aea
FCE
118 ~parser ();
119
120 stapfile* parse ();
121
177a8ead
FCE
122 static stapfile* parse (systemtap_session& s, std::istream& i, bool privileged);
123 static stapfile* parse (systemtap_session& s, const std::string& n, bool privileged);
82919855 124
2f1a1aea 125private:
177a8ead 126 systemtap_session& session;
2f1a1aea
FCE
127 std::string input_name;
128 std::istream* free_input;
129 lexer input;
24cb178f 130 bool privileged;
6e213f58 131 parse_context context;
2f1a1aea 132
177a8ead
FCE
133 // preprocessing subordinate
134 std::vector<const token*> enqueued_pp;
5811366a 135 const token* scan_pp (bool expand_args=true);
177a8ead 136
2f1a1aea
FCE
137 // scanning state
138 const token* last ();
139 const token* next ();
140 const token* peek ();
141
142 const token* last_t; // the last value returned by peek() or next()
143 const token* next_t; // lookahead token
d7f3e0c5
GH
144
145 // expectations
146 const token* expect_known (token_type tt, std::string const & expected);
147 const token* expect_unknown (token_type tt, std::string & target);
493ee224
DS
148 const token* expect_unknown2 (token_type tt1, token_type tt2,
149 std::string & target);
d7f3e0c5
GH
150
151 // convenience forms
152 const token* expect_op (std::string const & expected);
153 const token* expect_kw (std::string const & expected);
57b73400 154 const token* expect_number (int64_t & expected);
d7f3e0c5 155 const token* expect_ident (std::string & target);
493ee224 156 const token* expect_ident_or_keyword (std::string & target);
d7f3e0c5
GH
157 bool peek_op (std::string const & op);
158 bool peek_kw (std::string const & kw);
2f1a1aea
FCE
159
160 void print_error (const parse_error& pe);
161 unsigned num_errors;
162
163private: // nonterminals
54dfabe9 164 void parse_probe (std::vector<probe*>&, std::vector<probe_alias*>&);
4b5f3e45 165 void parse_global (std::vector<vardecl*>&, std::vector<probe*>&);
24cb178f 166 void parse_functiondecl (std::vector<functiondecl*>&);
54dfabe9 167 embeddedcode* parse_embeddedcode ();
9c0c0e46 168 probe_point* parse_probe_point ();
2f1a1aea 169 literal* parse_literal ();
2f1a1aea
FCE
170 block* parse_stmt_block ();
171 statement* parse_statement ();
172 if_statement* parse_if_statement ();
69c68955 173 for_loop* parse_for_loop ();
f3c26ea5 174 for_loop* parse_while_loop ();
69c68955
FCE
175 foreach_loop* parse_foreach_loop ();
176 expr_statement* parse_expr_statement ();
56099f08
FCE
177 return_statement* parse_return_statement ();
178 delete_statement* parse_delete_statement ();
f3c26ea5
FCE
179 next_statement* parse_next_statement ();
180 break_statement* parse_break_statement ();
181 continue_statement* parse_continue_statement ();
d02548c0
GH
182 indexable* parse_indexable ();
183 const token *parse_hist_op_or_bare_name (hist_op *&hop, std::string &name);
2f1a1aea
FCE
184 expression* parse_expression ();
185 expression* parse_assignment ();
186 expression* parse_ternary ();
187 expression* parse_logical_or ();
188 expression* parse_logical_and ();
bb2e3076
FCE
189 expression* parse_boolean_or ();
190 expression* parse_boolean_xor ();
191 expression* parse_boolean_and ();
2f1a1aea
FCE
192 expression* parse_array_in ();
193 expression* parse_comparison ();
bb2e3076 194 expression* parse_shift ();
2f1a1aea
FCE
195 expression* parse_concatenation ();
196 expression* parse_additive ();
197 expression* parse_multiplicative ();
198 expression* parse_unary ();
2f1a1aea
FCE
199 expression* parse_crement ();
200 expression* parse_value ();
201 expression* parse_symbol ();
202};
2b066ec1
FCE
203
204
205
206#endif // PARSE_H
This page took 0.072929 seconds and 5 git commands to generate.