From 45c9d37eb27d204a6202b33cb37e890af0171357 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Fri, 16 Oct 2026 10:04:27 +0000 Subject: feat(control-flow): implement ordered CASE OF matching Co-Authored-By: Claude Fable 5.1 --- include/cps/Lexer.h | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'include/cps/Lexer.h') diff --git a/include/cps/Lexer.h b/include/cps/Lexer.h index 2f6f231..7f3d5b5 100644 --- a/include/cps/Lexer.h +++ b/include/cps/Lexer.h @@ -2,6 +2,7 @@ #include #include #include +#include namespace cps { @@ -13,6 +14,10 @@ enum Token { tok_input = -4, tok_output = -5, + tok_case = -40, + tok_endcase = -41, + tok_otherwise = -42, + tok_if = -6, tok_then = -7, tok_else = -8, @@ -105,18 +110,32 @@ class Lexer { std::istream &Input; int LastChar = ' '; int CurrentLine = 1; + int TokenLine = 1; bool HadError = false; + struct TokenData { + int Kind, Line; + std::string Identifier, String; + int64_t Integer; + double Real; + char Character; + }; + std::deque Lookahead; + int readToken(); + TokenData captureToken(int Kind) const; + void restoreToken(const TokenData &Token); public: explicit Lexer(std::istream &Input) : Input(Input) {} std::string IdentifierStr; std::string StringVal; - int64_t NumVal; - double RealVal; + int64_t NumVal = 0; + double RealVal = 0; char CharVal = '\0'; int gettok(); - int getLine() const { return CurrentLine; } + int peekToken(unsigned Offset = 0); + int peekLine(unsigned Offset = 0); + int getLine() const { return TokenLine; } bool hadError() const { return HadError; } }; -- cgit v1.3.1-4-g156e