Files
BlitzNext/compiler/parser.hpp
T

65 lines
1.4 KiB
C++
Raw Normal View History

2014-01-31 08:23:00 +13:00
/*
The parser builds an abstact syntax tree from input tokens.
*/
#ifndef PARSER_H
#define PARSER_H
2019-01-18 15:55:51 +01:00
#include "nodes.hpp"
2019-01-18 17:04:57 +01:00
#include "toker.hpp"
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
class Parser {
public:
Parser(Toker& t);
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
ProgNode* parse(const string& main);
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
private:
string incfile;
set<string> included;
Toker * toker, *main_toker;
map<string, DimNode*> arrayDecls;
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
DeclSeqNode* consts;
DeclSeqNode* structs;
DeclSeqNode* funcs;
DeclSeqNode* datas;
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
StmtSeqNode* parseStmtSeq(int scope);
void parseStmtSeq(StmtSeqNode* stmts, int scope);
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
void ex(const string& s);
void exp(const string& s);
2014-01-31 08:23:00 +13:00
string parseIdent();
2019-01-18 17:04:57 +01:00
void parseChar(int c);
2014-01-31 08:23:00 +13:00
string parseTypeTag();
2019-01-18 17:04:57 +01:00
VarNode* parseVar();
VarNode* parseVar(const string& ident, const string& tag);
CallNode* parseCall(const string& ident, const string& tag);
IfNode* parseIf();
DeclNode* parseVarDecl(int kind, bool constant);
DimNode* parseArrayDecl();
DeclNode* parseFuncDecl();
DeclNode* parseStructDecl();
ExprSeqNode* parseExprSeq();
ExprNode* parseExpr(bool opt);
ExprNode* parseExpr1(bool opt); //And, Or, Eor
ExprNode* parseExpr2(bool opt); //<,=,>,<=,<>,>=
ExprNode* parseExpr3(bool opt); //+,-
ExprNode* parseExpr4(bool opt); //Lsr,Lsr,Asr
ExprNode* parseExpr5(bool opt); //*,/,Mod
ExprNode* parseExpr6(bool opt); //^
ExprNode* parseUniExpr(bool opt); //+,-,Not,~
ExprNode* parsePrimary(bool opt);
2014-01-31 08:23:00 +13:00
};
#endif