From 4df7c22b99349dcf2175d69679eafa175d49aa9f Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 26 Jul 2026 12:02:32 +0000 Subject: 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 --- include/cps/Parser.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'include/cps/Parser.h') 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 #include #include +#include #include #include @@ -12,7 +13,8 @@ namespace cps { class Parser { Lexer &Lex; int CurTok; - + unsigned NumErrors = 0; + std::map BinopPrecedence; int getNextToken(); @@ -31,6 +33,7 @@ class Parser { std::unique_ptr ParseStringBuiltin(const std::string &FuncName); std::unique_ptr ParseStatement(); + std::unique_ptr ParseStatementImpl(); std::unique_ptr ParseIfStmt(); std::unique_ptr ParseWhileStmt(); std::unique_ptr ParseRepeatStmt(); @@ -42,11 +45,12 @@ class Parser { std::unique_ptr ParseProcedure(); std::unique_ptr ParseCallStmt(); std::unique_ptr ParseReturnStmt(); - std::vector> ParsePrototypeArgs(); - + std::optional>> ParsePrototypeArgs(); + public: Parser(Lexer &L); std::vector> Parse(); + bool hadError() const { return NumErrors != 0; } }; } // namespace cps -- cgit v1.3.1-4-g156e