From e1b9116c18cc3f5dae14aa99263650eca2e6a9ed Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 19 Feb 2026 00:42:29 +0200 Subject: Implement loop (infinite) and do...while/until loops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Completes the 'loop, next, break, do' TODO entry — break and next were landed in the previous commit; this adds the remaining two forms: - loop { body } — infinite loop; the only exit is break. Simpler than while/until since there is no condition expression to evaluate. - do { body } while expr; / do { body } until expr; — post-condition loop: body always executes at least once, condition is checked at the bottom of each iteration. Condition tokens are collected until ';' (mirrors _expression_get but stops at semicolon instead of '{'), then replayed each iteration using the same temp-stack/temp-iterator technique as while/until. Both break and next are supported. Token changes: TT_LOOP and TT_DO added to the keyword enum in token.h, registered in get_tt() and tt_get_name() in token.c. Add examples/loop_do.fy; expected output: 5 / 12 / 11 / 5. Co-Authored-By: Claude Sonnet 4.6 --- src/core/token.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/core/token.c') diff --git a/src/core/token.c b/src/core/token.c index e8a6d9b..ea72a82 100644 --- a/src/core/token.c +++ b/src/core/token.c @@ -51,6 +51,8 @@ get_tt(char *c_token) { CHECK("until") TT_UNTIL; CHECK("int") TT_INT; CHECK("next") TT_NEXT; + CHECK("loop") TT_LOOP; + CHECK("do") TT_DO; CHECK("defined") TT_DEFINED; CHECK("undef") TT_UNDEF; CHECK("syms") TT_SYMS; @@ -130,6 +132,8 @@ tt_get_name(TokenType tt_cur) { CASE(TT_WHILE,"TT_WHILE") CASE(TT_UNTIL,"TT_UNTIL") CASE(TT_NEXT,"TT_NEXT") + CASE(TT_LOOP,"TT_LOOP") + CASE(TT_DO,"TT_DO") CASE(TT_DEFINED,"TT_DEFINED") CASE(TT_UNDEF,"TT_UNDEF") CASE(TT_SYMS,"TT_SYMS") -- cgit v1.2.3