diff options
| author | ov-4 <hausemasterstream@gmail.com> | 2026-01-29 13:02:49 +0000 |
|---|---|---|
| committer | ov-4 <hausemasterstream@gmail.com> | 2026-01-29 13:02:49 +0000 |
| commit | 4573880fcc32bd76a72a4ae713190cd997194583 (patch) | |
| tree | 3ce19dc8805996f65ba60b0f2144cce89c46ea1f /lib/Lexer | |
| parent | 73634b66d412735c292b3941d1281ff0a3c9e5a1 (diff) | |
Added loop statements, FOR, WHILE and REPEAT
Diffstat (limited to 'lib/Lexer')
| -rw-r--r-- | lib/Lexer/Lexer.cc | 26 |
1 files changed, 21 insertions, 5 deletions
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 <cctype> #include <cstdio> +#include <string> +#include <algorithm> 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; |
