2012-11-02 23:07:00 +00:00
|
|
|
#ifndef PARSER_H
|
|
|
|
#define PARSER_H
|
|
|
|
#include <string>
|
2012-12-06 17:41:16 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <cstdlib>
|
2012-11-02 23:07:00 +00:00
|
|
|
#include "Token.h"
|
2012-12-08 19:59:05 +00:00
|
|
|
#include "Context.h"
|
2012-12-06 17:41:16 +00:00
|
|
|
#include "AST/AllTypesOfASTNodes.h"
|
|
|
|
#include "AST/AST.h"
|
2012-11-02 23:07:00 +00:00
|
|
|
|
|
|
|
using namespace std;
|
2012-12-03 22:40:47 +00:00
|
|
|
|
2012-11-02 23:07:00 +00:00
|
|
|
class Parser
|
|
|
|
{
|
|
|
|
public:
|
2012-12-08 19:59:05 +00:00
|
|
|
Parser(Context * context);
|
|
|
|
Context * context;
|
|
|
|
|
2012-11-02 23:07:00 +00:00
|
|
|
virtual ~Parser();
|
|
|
|
void interpret();
|
|
|
|
string error_message;
|
2012-11-08 20:16:00 +00:00
|
|
|
void add_tokens(vector<Token> tokens);
|
2012-11-17 15:54:16 +00:00
|
|
|
string show_tokens();
|
2012-12-07 15:58:27 +00:00
|
|
|
AST tree;
|
|
|
|
ProgramNode * program;
|
|
|
|
void erase_all();
|
2012-12-09 16:42:13 +00:00
|
|
|
bool is_function_name();
|
2012-12-03 22:40:47 +00:00
|
|
|
|
2012-11-02 23:07:00 +00:00
|
|
|
protected:
|
2012-12-03 22:40:47 +00:00
|
|
|
|
2012-11-02 23:07:00 +00:00
|
|
|
private:
|
|
|
|
Token current_token;
|
|
|
|
string tok_value;
|
|
|
|
vector<Token> token_stream;
|
2012-12-08 19:59:05 +00:00
|
|
|
unsigned int position_in_stream;
|
2012-11-08 20:16:00 +00:00
|
|
|
|
2012-11-17 15:54:16 +00:00
|
|
|
bool in_statement;
|
2012-11-02 23:07:00 +00:00
|
|
|
bool read_next();
|
|
|
|
bool peek(string s);
|
|
|
|
bool accept(string s);
|
|
|
|
bool expect(string s);
|
|
|
|
bool is_type();
|
|
|
|
|
|
|
|
void error(string s);
|
2012-12-22 10:18:47 +00:00
|
|
|
|
2012-12-08 19:59:05 +00:00
|
|
|
|
2012-12-05 22:27:03 +00:00
|
|
|
ASTStatement * statement(ASTNode * node);
|
2012-11-04 16:16:02 +00:00
|
|
|
|
2012-12-22 16:56:32 +00:00
|
|
|
ASTExpression * log_expr(ASTNode * node);
|
2012-12-05 22:27:03 +00:00
|
|
|
ASTExpression * mul_expr(ASTNode * node);
|
|
|
|
ASTExpression * add_expr(ASTNode * node);
|
|
|
|
ASTExpression * prim_expr(ASTNode * node);
|
|
|
|
ASTExpression * postfix_expr(ASTNode * node);
|
|
|
|
ASTExpression * rel_expr(ASTNode * node);
|
|
|
|
ASTExpression * eq_expr(ASTNode * node);
|
|
|
|
ASTExpression * expr(ASTNode * node);
|
2012-11-02 23:07:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PARSER_H
|