-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.h
60 lines (50 loc) · 1.09 KB
/
parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef PARSER_H
#define PARSER_H
#include "AST.h"
#include "Lexer.h"
#include "llvm/Support/raw_ostream.h"
class Parser {
Lexer &Lex;
Token Tok;
bool HasError;
void error()
{
llvm::errs() << "Unexpected: " << Tok.getText() << "\n";
HasError = true;
}
void advance() { Lex.next(Tok); }
bool expect(Token::TokenKind Kind)
{
if (Tok.getKind() != Kind)
{
error();
return true;
}
return false;
}
bool consume(Token::TokenKind Kind)
{
if (expect(Kind))
return true;
advance();
return false;
}
AST *parseGoal();
Expr *parseDec();
Expr *parseEquation();
Expr *parseExpr();
Expr *parseTerm();
Expr *parseFactor();
Expr *parseFinal();
Expr *parseCondition();
Expr *parseIf();
Expr *parseElif();
Expr *parseElse();
Expr *parseC();
Expr *parseLoop();
public:
Parser(Lexer &Lex) : Lex(Lex), HasError(false) { advance(); }
bool HasError() {return HasError(); }
AST *parse();
};
#endif