#ifndef MSP_GL_SL_PARSER_H_
#define MSP_GL_SL_PARSER_H_
-#include <deque>
-#include <map>
#include <set>
#include <string>
#include <msp/io/base.h>
+#include "preprocessor.h"
#include "syntax.h"
+#include "tokenizer.h"
namespace Msp {
namespace GL {
class Parser
{
private:
- enum OperatorType
- {
- NO_OPERATOR,
- BINARY,
- PREFIX,
- POSTFIX
- };
-
- enum Associativity
- {
- LEFT_TO_RIGHT,
- RIGHT_TO_LEFT
- };
-
- struct Operator
- {
- const char token[4];
- unsigned precedence;
- OperatorType type;
- Associativity assoc;
- };
-
std::string source;
std::string source_name;
unsigned source_index;
- unsigned current_line;
- std::string::const_iterator iter;
- std::string::const_iterator source_end;
- bool allow_preprocess;
+ Tokenizer tokenizer;
+ Preprocessor preprocessor;
bool allow_stage_change;
- std::string last_token;
- std::deque<std::string> next_tokens;
Module *module;
Stage *cur_stage;
std::set<std::string> declared_types;
- static Operator operators[];
-
public:
Parser();
~Parser();
Module &parse(IO::Base &, const std::string &, unsigned = 0);
private:
- void parse_source();
-
- std::string format_error(const std::string &);
- std::string format_syntax_error(const std::string &);
+ void parse_source(const std::string &);
+ void set_required_version(const Version &);
+ void stage_change(Stage::Type);
- const std::string &peek_token(unsigned = 0);
- const std::string &parse_token();
- std::string parse_token_();
- std::string parse_identifier();
- std::string parse_number();
- std::string parse_other();
- void skip_comment_and_whitespace();
- void expect(const std::string &);
std::string expect_type();
std::string expect_identifier();
bool check(const std::string &);