Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion practice/stend_language/lexer/token_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ class TokenType(Enum):
FALSE = 52
EQUAL = 53
NOT_EQUAL = 54
COMMA = 55
COMMA = 55
SWITCH = 56
CASE = 57
IWS = 58
28 changes: 28 additions & 0 deletions practice/stend_language/parser/list_statements/list_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -110,6 +111,33 @@ def while_statement() -> bool:
and pop_token()
)

def switch_statement() -> bool:
"""<SWITCH_STATEMENT> -> SWITCH <IDENTIFIER> CASE <NUMBER> <LIST STATEMENTS>"""

return (
match_token(TokenType.SWITCH)
and pop_token()
and identifier()
and pop_token()
and case()
)


def case() -> bool():
"""CASE -> CASE <NUMBER> <LIST STATEMENTS> <CASE>| CASE <NUMBER> <LIST STATEMENTS> 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:
"""<READ STATEMENT> -> <READLINE> | <READ>"""
return readline() or read()
Expand Down