diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-28 16:18:04 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-28 16:18:04 +0200 |
| commit | 6bcaef138f13f9894abe3790aca52591a3d2d1f6 (patch) | |
| tree | fd57d227e69784d18da8004feaf11e91c178a53e /src | |
| parent | 2a2227d529f3788b8e08752d37deb1a449f3b9bc (diff) | |
Remove vestigial double-retry loop in _statement() [POLA]
_statement() wrapped its six parse rules in `for (int i = 0; i < 2; ++i)`
with no explanation. Investigation shows every rule is atomic: it either
consumes tokens and returns 1, or leaves the stream untouched and returns 0.
A second pass would see identical parser state, so the retry was a no-op.
Replace the loop with a flat priority-ordered try sequence and add a comment
explaining the invariant so future readers are not confused.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/build.h | 2 | ||||
| -rw-r--r-- | src/core/interpret.c | 18 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/build.h b/src/build.h index 8c250dc..cd6ed73 100644 --- a/src/build.h +++ b/src/build.h @@ -36,7 +36,7 @@ #ifndef BUILD_H #define BUILD_H -#define BUILDNR 9707 +#define BUILDNR 9709 #define OS_LINUX #endif diff --git a/src/core/interpret.c b/src/core/interpret.c index ba0eade..7fc9334 100644 --- a/src/core/interpret.c +++ b/src/core/interpret.c @@ -467,18 +467,20 @@ _func_decl(Interpret *p_interpret) { return (0); } +/* Try each parse rule in priority order; the first that matches + * returns 1. Every rule either consumes tokens and returns 1, + * or leaves the token stream untouched and returns 0, so a single + * pass suffices — the former double-retry loop was vestigial. */ int _statement(Interpret *p_interpret) { _CHECK TRACK - for (int i = 0; i < 2; ++i) { - if (_proc_decl(p_interpret)) return (1); - if (_func_decl(p_interpret)) return (1); - if (_var_decl(p_interpret)) return (1); - if (_control(p_interpret)) return (1); - if (_expression(p_interpret)) return (1); - if (_block(p_interpret)) return (1); - } + if (_proc_decl(p_interpret)) return (1); + if (_func_decl(p_interpret)) return (1); + if (_var_decl(p_interpret)) return (1); + if (_control(p_interpret)) return (1); + if (_expression(p_interpret)) return (1); + if (_block(p_interpret)) return (1); return (0); } |
