diff options
| author | _ov4 <ov4@ov4.org> | 2026-07-26 12:02:32 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-07-26 12:02:32 +0000 |
| commit | 4df7c22b99349dcf2175d69679eafa175d49aa9f (patch) | |
| tree | 1b44c329ed3e3f75787d9410d211ad0ed597b681 /include/cps/Parser.h | |
| parent | 0b4cdf7b28b3855d2dee18d91e9319d66a8ec25f (diff) | |
refactor: batch 1 - correctness and error contract
- MID/RIGHT/LEFT integer args now coerced at call sites (RIGHT(s, n/2)
no longer emits invalid IR); drop emitLeft's private conversion
- FOR loop direction decided at run time via select on STEP sign;
descending FOR works, STEP evaluated once per iteration
- ArrayHandler: extract emitCheckedIndices/loadElement; index count is
validated before emission, fixing a compiler-crash (vector OOB UB) on
OUTPUT with too many indices
- Error contract: Lexer/Parser/CodeGen track errors; all silent failure
paths now print Error: diagnostics with line numbers; unterminated
char literal no longer truncates the rest of the program; module is
verified with verifyModule; driver exits non-zero on any error
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/Parser.h')
| -rw-r--r-- | include/cps/Parser.h | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/include/cps/Parser.h b/include/cps/Parser.h index 19f49be..87d1dee 100644 --- a/include/cps/Parser.h +++ b/include/cps/Parser.h @@ -4,6 +4,7 @@ #include <vector> #include <memory> #include <map> +#include <optional> #include <tuple> #include <string> @@ -12,7 +13,8 @@ namespace cps { class Parser { Lexer &Lex; int CurTok; - + unsigned NumErrors = 0; + std::map<int, int> BinopPrecedence; int getNextToken(); @@ -31,6 +33,7 @@ class Parser { std::unique_ptr<ExprAST> ParseStringBuiltin(const std::string &FuncName); std::unique_ptr<StmtAST> ParseStatement(); + std::unique_ptr<StmtAST> ParseStatementImpl(); std::unique_ptr<StmtAST> ParseIfStmt(); std::unique_ptr<StmtAST> ParseWhileStmt(); std::unique_ptr<StmtAST> ParseRepeatStmt(); @@ -42,11 +45,12 @@ class Parser { std::unique_ptr<StmtAST> ParseProcedure(); std::unique_ptr<StmtAST> ParseCallStmt(); std::unique_ptr<StmtAST> ParseReturnStmt(); - std::vector<std::tuple<std::string, std::string, bool>> ParsePrototypeArgs(); - + std::optional<std::vector<std::tuple<std::string, std::string, bool>>> ParsePrototypeArgs(); + public: Parser(Lexer &L); std::vector<std::unique_ptr<StmtAST>> Parse(); + bool hadError() const { return NumErrors != 0; } }; } // namespace cps |
