X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogramparser.h;h=0a46c09ece6202e18c71625afd916b8680f4806a;hb=0ab875bdc9fbf84ecfce883b188410bb45882447;hp=0a91c500b1a24884401614d7188953a77ae809a8;hpb=6e6ee01b68056b23c6709d7f60396710dd7623b9;p=libs%2Fgl.git diff --git a/source/programparser.h b/source/programparser.h index 0a91c500..0a46c09e 100644 --- a/source/programparser.h +++ b/source/programparser.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include "programsyntax.h" @@ -13,18 +14,46 @@ namespace GL { class ProgramParser { 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::const_iterator iter; std::deque next_tokens; - ProgramSyntax::Module main_module; - ProgramSyntax::Module *cur_module; + ProgramSyntax::Module *module; + ProgramSyntax::Stage *cur_stage; + std::set declared_types; + + static Operator operators[]; public: + ProgramParser(); + ~ProgramParser(); + ProgramSyntax::Module &parse(const std::string &); ProgramSyntax::Module &parse(IO::Base &); private: - void parse_source(ProgramSyntax::Module &); + void parse_source(); const std::string &peek_token(unsigned = 0); std::string parse_token(); @@ -43,20 +72,24 @@ private: static bool is_qualifier(const std::string &); static bool is_builtin_type(const std::string &); bool is_type(const std::string &); + bool is_identifier(const std::string &); - ProgramSyntax::Node *parse_global_declaration(); - ProgramSyntax::Node *parse_statement(); - ProgramSyntax::Layout *parse_layout(); + RefPtr parse_global_declaration(); + RefPtr parse_statement(); + RefPtr parse_import(); + RefPtr parse_layout(); void parse_block(ProgramSyntax::Block &, bool); - void parse_expression(ProgramSyntax::Expression &); - ProgramSyntax::StructDeclaration *parse_struct_declaration(); - ProgramSyntax::VariableDeclaration *parse_variable_declaration(); - ProgramSyntax::FunctionDeclaration *parse_function_declaration(); - void parse_function_parameter_list(ProgramSyntax::FunctionDeclaration &); - ProgramSyntax::InterfaceBlock *parse_interface_block(); - ProgramSyntax::Conditional *parse_conditional(); - ProgramSyntax::Iteration *parse_iteration(); - ProgramSyntax::Return *parse_return(); + RefPtr parse_expression(unsigned = 0); + RefPtr parse_binary(const RefPtr &, const Operator *); + RefPtr parse_function_call(const ProgramSyntax::VariableReference &); + RefPtr parse_struct_declaration(); + RefPtr parse_variable_declaration(); + RefPtr parse_function_declaration(); + RefPtr parse_interface_block(); + RefPtr parse_conditional(); + RefPtr parse_iteration(); + RefPtr parse_passthrough(); + RefPtr parse_return(); }; } // namespace GL