diff options
author | fche <fche> | 2005-02-12 02:28:43 +0000 |
---|---|---|
committer | fche <fche> | 2005-02-12 02:28:43 +0000 |
commit | 2f1a1aead38c1dcd329a694dd8d3290b37320466 (patch) | |
tree | 3700f34d81fadb3b3f2cf850cce7eaec73d70659 /parse.h | |
download | systemtap-steved-2f1a1aead38c1dcd329a694dd8d3290b37320466.tar.gz systemtap-steved-2f1a1aead38c1dcd329a694dd8d3290b37320466.tar.xz systemtap-steved-2f1a1aead38c1dcd329a694dd8d3290b37320466.zip |
* parser prototype snapshot
Diffstat (limited to 'parse.h')
-rw-r--r-- | parse.h | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/parse.h b/parse.h new file mode 100644 index 00000000..21178a3f --- /dev/null +++ b/parse.h @@ -0,0 +1,102 @@ +// -*- C++ -*- +// Copyright 2005 Red Hat Inc. +// GPL + +#include <string> +#include <fstream> +#include <iostream> +#include <vector> +#include <stdexcept> + + +struct source_loc +{ + std::string file; + unsigned line; + unsigned column; +}; + + +enum token_type + { + tok_junk, tok_identifier, tok_operator, tok_string, tok_number + }; + +struct token +{ + source_loc location; + token_type type; + std::string content; +}; + + +struct parse_error: public std::runtime_error +{ + parse_error (const std::string& msg): runtime_error (msg) {} +}; + + +class lexer +{ +public: + token* scan (); + lexer (std::istream&, const std::string&); + +private: + int input_get (); + std::istream& input; + std::string input_name; + unsigned cursor_line; + unsigned cursor_column; +}; + + +class parser +{ +public: + parser (std::istream& i); + parser (const std::string& n); + ~parser (); + + stapfile* parse (); + +private: + std::string input_name; + std::istream* free_input; + lexer input; + + // scanning state + const token* last (); + const token* next (); + const token* peek (); + + const token* last_t; // the last value returned by peek() or next() + const token* next_t; // lookahead token + + void print_error (const parse_error& pe); + unsigned num_errors; + +private: // nonterminals + probe* parse_probe (); + probe_point_spec* parse_probe_point_spec (); + literal* parse_literal (); + symbol* parse_global (); + block* parse_stmt_block (); + statement* parse_statement (); + if_statement* parse_if_statement (); + expression* parse_expression (); + expression* parse_assignment (); + expression* parse_ternary (); + expression* parse_logical_or (); + expression* parse_logical_and (); + expression* parse_array_in (); + expression* parse_comparison (); + expression* parse_concatenation (); + expression* parse_additive (); + expression* parse_multiplicative (); + expression* parse_unary (); + expression* parse_exponentiation (); + expression* parse_crement (); + expression* parse_value (); + expression* parse_symbol (); +}; |