1 // THIS FILE IS GENERATED
2 // WARNING! All changes made in this file will be lost!
3 
4 #ifndef FACT_H_INCLUDED
5 #define FACT_H_INCLUDED
6 
7 #include "factast.h"
8 #include <kdev-pg-memory-pool.h>
9 #include <kdev-pg-allocator.h>
10 #include <kdev-pg-token-stream.h>
11 
12 namespace fact
13 {
14 
15 class  Parser
16 {
17 public:
18     typedef KDevPG::TokenStream::Token Token;
19     KDevPG::TokenStream *tokenStream;
20     int yytoken;
21 
22     inline Token LA(qint64 k = 1) const
23     {
24         return tokenStream->token(tokenStream->index() - 1 + k - 1);
25     }
yylex()26     inline int yylex()
27     {
28         return (yytoken = tokenStream->nextToken());
29     }
rewind(qint64 index)30     inline void rewind(qint64 index)
31     {
32         tokenStream->rewind(index);
33         yylex();
34     }
35 
36 // token stream
setTokenStream(KDevPG::TokenStream * s)37     void setTokenStream(KDevPG::TokenStream *s)
38     {
39         tokenStream = s;
40     }
41 
42 // error handling
43     void expectedSymbol(int kind, const QString& name);
44     void expectedToken(int kind, qint64 token, const QString& name);
45 
46     bool mBlockErrors;
blockErrors(bool block)47     inline bool blockErrors(bool block)
48     {
49         bool previous = mBlockErrors;
50         mBlockErrors = block;
51         return previous;
52     }
53 
54 // memory pool
55     typedef KDevPG::MemoryPool memoryPoolType;
56 
57     KDevPG::MemoryPool *memoryPool;
setMemoryPool(KDevPG::MemoryPool * p)58     void setMemoryPool(KDevPG::MemoryPool *p)
59     {
60         memoryPool = p;
61     }
62     template <class T>
create()63     inline T *create()
64     {
65         T *node = new (memoryPool->allocate(sizeof(T))) T();
66         node->kind = T::KIND;
67         return node;
68     }
69 
70     enum TokenType
71     {
72         Token_ASSIGN = 1000,
73         Token_COMMA = 1001,
74         Token_ELSE = 1002,
75         Token_EOF = 1003,
76         Token_EQUAL = 1004,
77         Token_FUNCTION = 1005,
78         Token_IDENTIFIER = 1006,
79         Token_IF = 1007,
80         Token_INVALID = 1008,
81         Token_LBRACE = 1009,
82         Token_LPAREN = 1010,
83         Token_MINUS = 1011,
84         Token_NUMBER = 1012,
85         Token_RBRACE = 1013,
86         Token_RETURN = 1014,
87         Token_RPAREN = 1015,
88         Token_SEMICOLON = 1016,
89         Token_STAR = 1017,
90         Token_VAR = 1018,
91         TokenTypeSize
92     }; // TokenType
93 
94 // user defined declarations:
95 public:
96 
97     /**
98      * Transform the raw input into tokens.
99      * When this method returns, the parser's token stream has been filled
100      * and any parse_*() method can be called.
101      */
102     void tokenize( const QString& contents );
103 
104     enum ProblemType
105     {
106         Error,
107         Warning,
108         Info
109     };
110     void reportProblem( Parser::ProblemType type, const QString& message );
111 
112     QString tokenText(qint64 begin, qint64 end) const;
113 
114     void setDebug( bool debug );
115 
116 
117 private:
118 
119     QString m_contents;
120     bool m_debug;
121 
122 
123 public:
Parser()124     Parser()
125     {
126         memoryPool = 0;
127         tokenStream = 0;
128         yytoken = Token_EOF;
129         mBlockErrors = false;
130     }
131 
~Parser()132     virtual ~Parser() {}
133 
134     bool parseAssignmentStatement(AssignmentStatementAst **yynode);
135     bool parseBlockStatement(BlockStatementAst **yynode);
136     bool parseBody(BodyAst **yynode);
137     bool parseCondition(ConditionAst **yynode);
138     bool parseDeclaration(DeclarationAst **yynode);
139     bool parseExpression(ExpressionAst **yynode);
140     bool parseFunctionDefinition(FunctionDefinitionAst **yynode);
141     bool parseIfStatement(IfStatementAst **yynode);
142     bool parseMultExpression(MultExpressionAst **yynode);
143     bool parsePrimary(PrimaryAst **yynode);
144     bool parseProgram(ProgramAst **yynode);
145     bool parseReturnStatement(ReturnStatementAst **yynode);
146     bool parseStatement(StatementAst **yynode);
147     bool parseVariable(VariableAst **yynode);
148 };
149 
150 } // end of namespace fact
151 
152 #endif
153 
154