-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.hpp
More file actions
103 lines (88 loc) · 3.48 KB
/
Copy pathparser.hpp
File metadata and controls
103 lines (88 loc) · 3.48 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Sözdizimsel çözümleyici.
//
// Deyimler: özyinelemeli iniş (recursive descent).
// İfadeler: öncelik tırmanışı — SPEC §8 tablosundaki 11 kademe, her biri bir
// fonksiyon. (Pratt'ın tablo sürücülü hâli yerine kademe zinciri seçildi:
// gramer sabit olduğu için tablo bir esneklik kazandırmıyor, okunabilirlik ise
// belirgin şekilde artıyor.)
//
// Hata kurtarma: hatadan sonra bir sonraki satır sonuna/blok çıkışına atlanır,
// böylece tek koşuda birden çok hata raporlanabilir.
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include "ast.hpp"
#include "diag.hpp"
#include "source.hpp"
#include "token.hpp"
namespace rs {
class Parser {
public:
Parser(const Source& src, std::vector<Token> tokens, Diagnostics& diag)
: src_(&src), toks_(std::move(tokens)), diag_(&diag) {}
[[nodiscard]] Program parseProgram();
private:
// --- imleç ---
[[nodiscard]] const Token& peek(std::size_t ileri = 0) const;
[[nodiscard]] const Token& previous() const;
[[nodiscard]] bool check(Tok k) const { return peek().kind == k; }
[[nodiscard]] bool atEnd() const { return peek().kind == Tok::Eof; }
const Token& advance();
bool match(Tok k);
bool matchAny(std::initializer_list<Tok> ks);
const Token& expect(Tok k, std::string_view ne);
void skipNewlines();
void endOfStatement(); // NEWLINE | ';' | '}' önü | DEDENT önü | dosya sonu
void synchronize();
void err(const Token& t, std::string mesaj, std::string ipucu = {});
// --- deyimler ---
StmtPtr statement();
StmtPtr simpleStatement();
StmtPtr compoundStatement();
StmtPtr block(); // ':' NEWLINE INDENT ... DEDENT | ':' simple
StmtPtr braceBlock(); // '{' ... '}' (lambda gövdesi)
StmtPtr ifStatement();
StmtPtr whileStatement();
StmtPtr forStatement();
StmtPtr tryStatement();
StmtPtr ImportStatement();
StmtPtr functionDecl(std::vector<Decorator> dekoratorler, bool isAsync);
StmtPtr classDecl();
StmtPtr traitDecl();
std::vector<Param> paramList();
std::vector<Decorator> decorators();
// --- ifadeler: SPEC §8 öncelik kademeleri ---
ExprPtr expression(); // 0 ternary
ExprPtr orExpr(); // 1 or
ExprPtr andExpr(); // 2 and
ExprPtr notExpr(); // 3 not
ExprPtr comparison(); // 4 == != < > <= >= is in
ExprPtr rangeExpr(); // 5 .. ..=
ExprPtr bitOr(); // 6 |
ExprPtr bitXor(); // 7 ^
ExprPtr bitAnd(); // 8 &
ExprPtr shift(); // 9 << >>
ExprPtr sum(); // 10 + -
ExprPtr product(); // 11 * / // %
ExprPtr unary(); // 12 - + ~ await
ExprPtr power(); // 13 ** (sağ birleşmeli)
ExprPtr postfix(); // 14 () [] . ?.
ExprPtr primary();
ExprPtr lambdaOrGrouped(); // '(' sonrası: lambda mı parantezli ifade mi
ExprPtr listLiteral();
ExprPtr mapLiteral();
ExprPtr fstring(const Token& t); // gövdeyi alt-lexer'la çözer
// --- tipler ---
TypePtr typeNode();
// --- yardımcı ---
[[nodiscard]] static bool assignable(const Expr& e) noexcept;
template <class T> std::unique_ptr<T> make(Span span);
const Source* src_;
std::vector<Token> toks_;
Diagnostics* diag_;
std::size_t i_ = 0;
int hataSayisi_ = 0;
static constexpr int MAKS_HATA = 40; // kaskad hataları sonsuza gitmesin
};
} // namespace rs