75 lines
No EOL
2.2 KiB
C++
75 lines
No EOL
2.2 KiB
C++
|
||
#include<memory>
|
||
|
||
#include<list>
|
||
#include<exception>
|
||
#include"Token.h"
|
||
#include"AST.h"
|
||
|
||
|
||
#ifndef LS_Parser_H_
|
||
#define LS_Parser_H_
|
||
namespace ls {
|
||
typedef std::list<Token> Container;
|
||
typedef Container::const_iterator Tokit;
|
||
|
||
class ExpectedException : public std::exception {
|
||
public:
|
||
ExpectedException(const char * const message, int l)
|
||
:std::exception(message), line(l) {}
|
||
|
||
int line;
|
||
};
|
||
|
||
|
||
|
||
using std::unique_ptr;
|
||
class Parser {
|
||
public:
|
||
inline void ThrowExpected(const char * const message) {
|
||
throw ExpectedException(message, it->line);
|
||
}
|
||
|
||
void set(Tokit begin) { it = begin; }
|
||
unique_ptr<AST_SentenceList> parseSentenceList();
|
||
unique_ptr<AST_Sentence> parseSentence();
|
||
inline unique_ptr<AST_Expr> expr() { return parseLogicalBinary(); }
|
||
private:
|
||
unique_ptr<AST_Sentence> parseCommonSentence();
|
||
unique_ptr<AST_Sentence> parseVarSentence();
|
||
unique_ptr<AST_Sentence> parseWhileSentence();
|
||
unique_ptr<AST_Sentence> parseIfSentence();
|
||
unique_ptr<AST_Sentence> parseForInSentence();
|
||
unique_ptr<AST_Sentence> parseReturn();
|
||
private:
|
||
//<LogicalBinary> := <LogicalUnary>{("and"|"or")-<LogicalUnary>}
|
||
unique_ptr<AST_Expr> parseLogicalBinary();
|
||
//<LogicalUnary> := ["not"]<Comparison>
|
||
unique_ptr<AST_Expr> parseLogicalUnary();
|
||
//<Comparison> := <AddAndSub>{("=="|"!="|"<="|"<"|">="|">")-<AddAndSub>}
|
||
unique_ptr<AST_Expr> parseComparison();
|
||
//<AddAndSub> := ["+"|"-"]<MulAndDiv>{("+"|"-")-<MulAndDiv>}
|
||
unique_ptr<AST_Expr> parseAddAndSub();
|
||
//<MulAndDiv> := <AttrAccess>{("*"|"/")-<AttrAccess>}
|
||
unique_ptr<AST_Expr> parseMulAndDiv();
|
||
//<AttrAccess> := <PrimaryExpr>{("["-<expr>-"]")|("("-([<Expr>],{","-<Expr>})-")")|"."<Identifer>}
|
||
unique_ptr<AST_Expr> parseAttrAccess();
|
||
//<Primary> := "("-<expr>-")"|<Identifier>|<Literal>
|
||
unique_ptr<AST_Expr> parsePrimary();
|
||
//<Literal> := <Interger>|<Floating>|<String>|<Table>|<Function>
|
||
unique_ptr<AST_Expr> parseLiteral();
|
||
unique_ptr<AST_Expr> parseInteger();
|
||
unique_ptr<AST_Expr> parseFloating();
|
||
unique_ptr<AST_Expr> parseFunction();
|
||
//<2F>ϼ<EFBFBD> <20>ȵ<EFBFBD>.
|
||
unique_ptr<AST_Expr> parseTableExpr();
|
||
|
||
unique_ptr<AST_Ident> parseIdentifier();
|
||
|
||
//unique_ptr<AST_Expr> level6()
|
||
private:
|
||
Tokit it;
|
||
Tokit end;
|
||
};
|
||
}
|
||
#endif |