From 4573880fcc32bd76a72a4ae713190cd997194583 Mon Sep 17 00:00:00 2001 From: ov-4 Date: Thu, 29 Jan 2026 13:02:49 +0000 Subject: Added loop statements, FOR, WHILE and REPEAT --- lib/Lexer/Lexer.cc | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'lib/Lexer') diff --git a/lib/Lexer/Lexer.cc b/lib/Lexer/Lexer.cc index c50897b..7f7a167 100644 --- a/lib/Lexer/Lexer.cc +++ b/lib/Lexer/Lexer.cc @@ -1,6 +1,8 @@ #include "cps/Lexer.h" #include #include +#include +#include using namespace cps; @@ -19,10 +21,24 @@ int Lexer::gettok() { if (IdentifierStr == "INTEGER") return tok_integer_kw; if (IdentifierStr == "INPUT") return tok_input; if (IdentifierStr == "OUTPUT") return tok_output; + if (IdentifierStr == "IF") return tok_if; if (IdentifierStr == "THEN") return tok_then; if (IdentifierStr == "ELSE") return tok_else; if (IdentifierStr == "ENDIF") return tok_endif; + + if (IdentifierStr == "WHILE") return tok_while; + if (IdentifierStr == "DO") return tok_do; + if (IdentifierStr == "ENDWHILE") return tok_endwhile; + + if (IdentifierStr == "REPEAT") return tok_repeat; + if (IdentifierStr == "UNTIL") return tok_until; + + if (IdentifierStr == "FOR") return tok_for; + if (IdentifierStr == "TO") return tok_to; + if (IdentifierStr == "STEP") return tok_step; + if (IdentifierStr == "NEXT") return tok_next; + return tok_identifier; } @@ -67,6 +83,11 @@ int Lexer::gettok() { return tok_eq; } + if (LastChar == ':') { + LastChar = getchar(); + return tok_colon; + } + if (LastChar == '/') { int NextChar = getchar(); if (NextChar == '/') { @@ -81,11 +102,6 @@ int Lexer::gettok() { return '/'; } } - - if (LastChar == ':') { - LastChar = getchar(); - return tok_colon; - } if (LastChar == EOF) return tok_eof; -- cgit v1.3.1-4-g156e