diff --git a/practice/stend_language/lexer/token_type.py b/practice/stend_language/lexer/token_type.py index 7ec959b..84d9a55 100644 --- a/practice/stend_language/lexer/token_type.py +++ b/practice/stend_language/lexer/token_type.py @@ -56,4 +56,7 @@ class TokenType(Enum): FALSE = 52 EQUAL = 53 NOT_EQUAL = 54 - COMMA = 55 \ No newline at end of file + COMMA = 55 + SWITCH = 56 + CASE = 57 + IWS = 58 \ No newline at end of file diff --git a/practice/stend_language/parser/list_statements/list_statements.py b/practice/stend_language/parser/list_statements/list_statements.py index 1cfe06b..9389216 100644 --- a/practice/stend_language/parser/list_statements/list_statements.py +++ b/practice/stend_language/parser/list_statements/list_statements.py @@ -29,6 +29,7 @@ def statement() -> bool: or if_statement() or write_statement() or read_statement() + or switch_statement() or ( match_token(TokenType.LBRACKET) and pop_token() @@ -110,6 +111,33 @@ def while_statement() -> bool: and pop_token() ) +def switch_statement() -> bool: + """ -> SWITCH CASE """ + + return ( + match_token(TokenType.SWITCH) + and pop_token() + and identifier() + and pop_token() + and case() + ) + + +def case() -> bool(): + """CASE -> CASE | CASE iws""" + + if match_token(TokenType.CASE): + return ( + pop_token() + and number() + and pop_token() + and list_statements() + and case() + ) + + return match_token(TokenType.IWS) + + def read_statement() -> bool: """ -> | """ return readline() or read()