diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-16 10:04:27 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-16 10:04:27 +0000 |
| commit | 45c9d37eb27d204a6202b33cb37e890af0171357 (patch) | |
| tree | dba23170b16053c5e1ec4bf78efc2a533cb94a4e /include/cps/Lexer.h | |
| parent | 522742e9df7fc5ac596ce4aa53d41b31e4f6a030 (diff) | |
feat(control-flow): implement ordered CASE OF matching
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/Lexer.h')
| -rw-r--r-- | include/cps/Lexer.h | 25 |
1 files changed, 22 insertions, 3 deletions
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 <istream> #include <string> #include <cstdint> +#include <deque> 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<TokenData> 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; } }; |
