File indexing completed on 2024-04-28 04:36:08
0001 // THIS FILE IS GENERATED 0002 // WARNING! All changes made in this file will be lost! 0003 0004 #ifndef FACT_H_INCLUDED 0005 #define FACT_H_INCLUDED 0006 0007 #include "factast.h" 0008 #include <kdev-pg-memory-pool.h> 0009 #include <kdev-pg-allocator.h> 0010 #include <kdev-pg-token-stream.h> 0011 0012 namespace fact 0013 { 0014 0015 class Parser 0016 { 0017 public: 0018 typedef KDevPG::TokenStream::Token Token; 0019 KDevPG::TokenStream *tokenStream; 0020 int yytoken; 0021 0022 inline Token LA(qint64 k = 1) const 0023 { 0024 return tokenStream->token(tokenStream->index() - 1 + k - 1); 0025 } 0026 inline int yylex() 0027 { 0028 return (yytoken = tokenStream->nextToken()); 0029 } 0030 inline void rewind(qint64 index) 0031 { 0032 tokenStream->rewind(index); 0033 yylex(); 0034 } 0035 0036 // token stream 0037 void setTokenStream(KDevPG::TokenStream *s) 0038 { 0039 tokenStream = s; 0040 } 0041 0042 // error handling 0043 void expectedSymbol(int kind, const QString& name); 0044 void expectedToken(int kind, qint64 token, const QString& name); 0045 0046 bool mBlockErrors; 0047 inline bool blockErrors(bool block) 0048 { 0049 bool previous = mBlockErrors; 0050 mBlockErrors = block; 0051 return previous; 0052 } 0053 0054 // memory pool 0055 typedef KDevPG::MemoryPool memoryPoolType; 0056 0057 KDevPG::MemoryPool *memoryPool; 0058 void setMemoryPool(KDevPG::MemoryPool *p) 0059 { 0060 memoryPool = p; 0061 } 0062 template <class T> 0063 inline T *create() 0064 { 0065 T *node = new (memoryPool->allocate(sizeof(T))) T(); 0066 node->kind = T::KIND; 0067 return node; 0068 } 0069 0070 enum TokenType 0071 { 0072 Token_ASSIGN = 1000, 0073 Token_COMMA = 1001, 0074 Token_ELSE = 1002, 0075 Token_EOF = 1003, 0076 Token_EQUAL = 1004, 0077 Token_FUNCTION = 1005, 0078 Token_IDENTIFIER = 1006, 0079 Token_IF = 1007, 0080 Token_INVALID = 1008, 0081 Token_LBRACE = 1009, 0082 Token_LPAREN = 1010, 0083 Token_MINUS = 1011, 0084 Token_NUMBER = 1012, 0085 Token_RBRACE = 1013, 0086 Token_RETURN = 1014, 0087 Token_RPAREN = 1015, 0088 Token_SEMICOLON = 1016, 0089 Token_STAR = 1017, 0090 Token_VAR = 1018, 0091 TokenTypeSize 0092 }; // TokenType 0093 0094 // user defined declarations: 0095 public: 0096 0097 /** 0098 * Transform the raw input into tokens. 0099 * When this method returns, the parser's token stream has been filled 0100 * and any parse_*() method can be called. 0101 */ 0102 void tokenize( const QString& contents ); 0103 0104 enum ProblemType 0105 { 0106 Error, 0107 Warning, 0108 Info 0109 }; 0110 void reportProblem( Parser::ProblemType type, const QString& message ); 0111 0112 QString tokenText(qint64 begin, qint64 end) const; 0113 0114 void setDebug( bool debug ); 0115 0116 0117 private: 0118 0119 QString m_contents; 0120 bool m_debug; 0121 0122 0123 public: 0124 Parser() 0125 { 0126 memoryPool = 0; 0127 tokenStream = 0; 0128 yytoken = Token_EOF; 0129 mBlockErrors = false; 0130 } 0131 0132 virtual ~Parser() {} 0133 0134 bool parseAssignmentStatement(AssignmentStatementAst **yynode); 0135 bool parseBlockStatement(BlockStatementAst **yynode); 0136 bool parseBody(BodyAst **yynode); 0137 bool parseCondition(ConditionAst **yynode); 0138 bool parseDeclaration(DeclarationAst **yynode); 0139 bool parseExpression(ExpressionAst **yynode); 0140 bool parseFunctionDefinition(FunctionDefinitionAst **yynode); 0141 bool parseIfStatement(IfStatementAst **yynode); 0142 bool parseMultExpression(MultExpressionAst **yynode); 0143 bool parsePrimary(PrimaryAst **yynode); 0144 bool parseProgram(ProgramAst **yynode); 0145 bool parseReturnStatement(ReturnStatementAst **yynode); 0146 bool parseStatement(StatementAst **yynode); 0147 bool parseVariable(VariableAst **yynode); 0148 }; 0149 0150 } // end of namespace fact 0151 0152 #endif 0153