Add sources
This commit is contained in:
199
src/Parser.h
Normal file
199
src/Parser.h
Normal file
@@ -0,0 +1,199 @@
|
||||
#pragma once
|
||||
|
||||
#include "Lexer.h"
|
||||
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
#include "SL/Token.h"
|
||||
#include "SL/Identifier.h"
|
||||
#include "SL/Keyword.h"
|
||||
#include "SL/Number.h"
|
||||
#include "SL/Separator.h"
|
||||
#include "SL/Symbol.h"
|
||||
#include "SL/Endmark.h"
|
||||
|
||||
#include "AST/Declarations/FunctionDefinition.h"
|
||||
#include "AST/Declarations/NamespaceDefinition.h"
|
||||
#include "AST/Declarations/EmptyDeclaration.h"
|
||||
#include "AST/Declarations/StaticAssertDeclaration.h"
|
||||
#include "AST/Declarations/TemplateDeclaration.h"
|
||||
#include "AST/Declarations/ExplicitInstantiation.h"
|
||||
#include "AST/Declarations/ExplicitSpecialization.h"
|
||||
#include "AST/Declarations/AttributeDeclaration.h"
|
||||
#include "AST/Declarations/AssemblerDefinition.h"
|
||||
|
||||
#include "AST/Declarations/SimpleDeclaration.h"
|
||||
#include "AST/Declarations/Structure.h"
|
||||
#include "AST/Declarations/Class.h"
|
||||
|
||||
#include "AST/Statements/DeclarationList.h"
|
||||
#include "AST/Statements/ExpressionList.h"
|
||||
#include "AST/Statements/CompoundStatement.h"
|
||||
#include "AST/Statements/SelectionStatements/If.h"
|
||||
#include "AST/Statements/IterationStatements/While.h"
|
||||
#include "AST/Statements/IterationStatements/DoWhile.h"
|
||||
#include "AST/Statements/IterationStatements/For.h"
|
||||
#include "AST/Statements/JumpStatements/Return.h"
|
||||
|
||||
#include "AST/Expressions/Call.h"
|
||||
#include "AST/Expressions/Unary.h"
|
||||
#include "AST/Expressions/Binary.h"
|
||||
#include "AST/Expressions/Constant.h"
|
||||
#include "AST/Expressions/Variable.h"
|
||||
|
||||
class Parser
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
explicit Parser (const char * buffer);
|
||||
virtual ~Parser (void);
|
||||
|
||||
bool buildAST (void);
|
||||
|
||||
const std::vector<const AST::Node *> & getAST (void)
|
||||
{
|
||||
return(m_aNodes);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void error (const char * str);
|
||||
|
||||
void scan (void);
|
||||
SL::Token * lookAhead (unsigned int n);
|
||||
|
||||
void skip (SL::Token::EType t);
|
||||
void skip (SL::Symbol::ESymbol sym);
|
||||
void skip (SL::Separator::ESeparator op);
|
||||
void skip (SL::Keyword::EKeyword k);
|
||||
|
||||
protected:
|
||||
|
||||
void translation_unit (void);
|
||||
|
||||
// Statements
|
||||
const AST::Statement * statement (void);
|
||||
|
||||
void condition (bool opt = false);
|
||||
|
||||
const AST::Statement * labeled_statement (void);
|
||||
const AST::Statement * expression_statement (void);
|
||||
const AST::CompoundStatement * compound_statement (void);
|
||||
const AST::Statement * selection_statement (void);
|
||||
const AST::Statement * iteration_statement (void);
|
||||
const AST::JumpStatement * jump_statement (void);
|
||||
const AST::Statement * declaration_statement (void);
|
||||
|
||||
// Declarations
|
||||
const AST::Declaration * declaration (void);
|
||||
|
||||
const AST::Declaration * block_declaration (void);
|
||||
const AST::FunctionDefinition * function_definition (void);
|
||||
|
||||
// void linkage_specification (void);
|
||||
const AST::NamespaceDefinition * namespace_definition (void);
|
||||
const AST::EmptyDeclaration * empty_declaration (void);
|
||||
const AST::AttributeDeclaration * attribute_declaration (void);
|
||||
|
||||
void simple_declaration (void);
|
||||
const AST::AssemblerDefinition * asm_definition (void);
|
||||
const AST::Declaration * linkage_specification (void);
|
||||
void namespace_alias_definition (void);
|
||||
void using_declaration (void);
|
||||
void using_directive (void);
|
||||
const AST::StaticAssertDeclaration *static_assert_declaration (void);
|
||||
void alias_declaration (void);
|
||||
void opaque_enum_declaration (void);
|
||||
|
||||
// Declarators
|
||||
|
||||
// ...
|
||||
|
||||
// Classes
|
||||
|
||||
// ...
|
||||
|
||||
// Derived Classes
|
||||
|
||||
// ...
|
||||
|
||||
// Special member functions
|
||||
|
||||
// ...
|
||||
|
||||
// Overloading
|
||||
|
||||
// ...
|
||||
|
||||
// Templates
|
||||
const AST::TemplateDeclaration * template_declaration (void);
|
||||
void template_parameter_list (void);
|
||||
void template_parameter (void);
|
||||
void type_parameter (void);
|
||||
void type_parameter_key (void);
|
||||
const AST::ExplicitInstantiation * explicit_instantiation (void);
|
||||
const AST::ExplicitSpecialization * explicit_specialization (void);
|
||||
|
||||
// Exception handling
|
||||
const AST::Statement * try_block (void);
|
||||
|
||||
|
||||
|
||||
|
||||
const AST::Declaration * parse_member (void);
|
||||
const AST::Statement * parse_statement (void);
|
||||
|
||||
// global definitions
|
||||
|
||||
const AST::Structure * parse_struct (void);
|
||||
const AST::Class * parse_class (void);
|
||||
const AST::SimpleDeclaration * parse_variable (void);
|
||||
|
||||
// members
|
||||
const AST::FunctionDefinition * parse_method (void);
|
||||
const AST::SimpleDeclaration * parse_property (void);
|
||||
|
||||
// statements
|
||||
const AST::SimpleDeclaration * parse_simple_declaration(void);
|
||||
const AST::CompoundStatement * parse_block (void);
|
||||
const AST::If * parse_if (void);
|
||||
const AST::While * parse_while (void);
|
||||
const AST::DoWhile * parse_do_while (void);
|
||||
const AST::For * parse_for (void);
|
||||
const AST::Return * parse_return (void);
|
||||
|
||||
// expressions
|
||||
const AST::Expression * parse_expression (void);
|
||||
const AST::Expression * parse_expression_1 (const AST::Expression * lhs, unsigned int min_precedence);
|
||||
|
||||
//const AST::Expression * parse_equality_expression (void);
|
||||
//const AST::Expression * parse_additive_expression (void);
|
||||
//const AST::Expression * parse_multiplicative_expression (void);
|
||||
const AST::Expression * parse_primary_expression (void);
|
||||
|
||||
//const AST::Expression * parse_constant (void);
|
||||
//const AST::Unary * parse_unary_expression (void);
|
||||
|
||||
void parse_parameter (void);
|
||||
void parse_type (char * pType);
|
||||
void parse_name (char * pName, bool global);
|
||||
|
||||
const AST::Binary * create_binary_expr(const SL::Symbol * symbol, const AST::Expression * lhs, const AST::Expression * rhs);
|
||||
const AST::Unary * create_unary_expr(const SL::Symbol * symbol, const AST::Expression * rhs);
|
||||
|
||||
// other
|
||||
void attribute_specifier_seq(bool opt = false);
|
||||
void attribute_specifier(void);
|
||||
|
||||
private:
|
||||
|
||||
Lexer m_lexer;
|
||||
SL::Token * m_pNext;
|
||||
|
||||
std::queue<SL::Token*> m_queueAhead;
|
||||
|
||||
std::vector<const AST::Node *> m_aNodes;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user