]>
Commit | Line | Data |
---|---|---|
2f1a1aea FCE |
1 | // -*- C++ -*- |
2 | // Copyright 2005 Red Hat Inc. | |
3 | // GPL | |
4 | ||
5 | #include <string> | |
6 | #include <fstream> | |
7 | #include <iostream> | |
8 | #include <vector> | |
9 | #include <stdexcept> | |
10 | ||
11 | ||
12 | struct source_loc | |
13 | { | |
14 | std::string file; | |
15 | unsigned line; | |
16 | unsigned column; | |
17 | }; | |
18 | ||
19 | ||
20 | enum token_type | |
21 | { | |
22 | tok_junk, tok_identifier, tok_operator, tok_string, tok_number | |
23 | }; | |
24 | ||
25 | struct token | |
26 | { | |
27 | source_loc location; | |
28 | token_type type; | |
29 | std::string content; | |
30 | }; | |
31 | ||
32 | ||
33 | struct parse_error: public std::runtime_error | |
34 | { | |
35 | parse_error (const std::string& msg): runtime_error (msg) {} | |
36 | }; | |
37 | ||
38 | ||
39 | class lexer | |
40 | { | |
41 | public: | |
42 | token* scan (); | |
43 | lexer (std::istream&, const std::string&); | |
44 | ||
45 | private: | |
46 | int input_get (); | |
47 | std::istream& input; | |
48 | std::string input_name; | |
49 | unsigned cursor_line; | |
50 | unsigned cursor_column; | |
51 | }; | |
52 | ||
53 | ||
54 | class parser | |
55 | { | |
56 | public: | |
57 | parser (std::istream& i); | |
58 | parser (const std::string& n); | |
59 | ~parser (); | |
60 | ||
61 | stapfile* parse (); | |
62 | ||
63 | private: | |
64 | std::string input_name; | |
65 | std::istream* free_input; | |
66 | lexer input; | |
67 | ||
68 | // scanning state | |
69 | const token* last (); | |
70 | const token* next (); | |
71 | const token* peek (); | |
72 | ||
73 | const token* last_t; // the last value returned by peek() or next() | |
74 | const token* next_t; // lookahead token | |
75 | ||
76 | void print_error (const parse_error& pe); | |
77 | unsigned num_errors; | |
78 | ||
79 | private: // nonterminals | |
80 | probe* parse_probe (); | |
81 | probe_point_spec* parse_probe_point_spec (); | |
82 | literal* parse_literal (); | |
83 | symbol* parse_global (); | |
84 | block* parse_stmt_block (); | |
85 | statement* parse_statement (); | |
86 | if_statement* parse_if_statement (); | |
87 | expression* parse_expression (); | |
88 | expression* parse_assignment (); | |
89 | expression* parse_ternary (); | |
90 | expression* parse_logical_or (); | |
91 | expression* parse_logical_and (); | |
92 | expression* parse_array_in (); | |
93 | expression* parse_comparison (); | |
94 | expression* parse_concatenation (); | |
95 | expression* parse_additive (); | |
96 | expression* parse_multiplicative (); | |
97 | expression* parse_unary (); | |
98 | expression* parse_exponentiation (); | |
99 | expression* parse_crement (); | |
100 | expression* parse_value (); | |
101 | expression* parse_symbol (); | |
102 | }; |