diff --git a/pobrelanglib/lexer.py b/pobrelanglib/lexer.py index 686d7bb..24c06cc 100644 --- a/pobrelanglib/lexer.py +++ b/pobrelanglib/lexer.py @@ -9,6 +9,12 @@ def lex_line(line: str) -> list[str]: case "scream": tokens.append("SCR") + case "listen": + tokens.append("LST") + + case "antidisestablishmentarianism": + tokens.append("ADM") + case "work": tokens.append("WRK") diff --git a/pobrelanglib/parser.py b/pobrelanglib/parser.py index bbbe507..bd408e1 100644 --- a/pobrelanglib/parser.py +++ b/pobrelanglib/parser.py @@ -129,6 +129,24 @@ def parse_line(line: list[str]) -> None: # just a line break print() + case "LST" | "ADM": + if not len(line) == 2 or not is_token(line[1], "EXP"): + lt_panic("not learn how to use the input keywords correctly") + + var = extract_expression(line[1]) + + if not var in variables: + lt_panic("read user input into a non-existing variable") + + match line[0]: + case "LST": + variables[var] = input() + case "ADM": + try: + variables[var] = parse_math(input()) + except (NameError, SyntaxError): + lt_panic("input an invalid expression to the parser") + case "ITM" | "TAG": if not len(line) == 3 or not (is_token(line[1], "EXP") and is_token(line[2], "EXP")): lt_panic("create a variable like this") diff --git a/test.pbr b/test.pbr index b3bc8eb..f3566a5 100644 --- a/test.pbr +++ b/test.pbr @@ -25,4 +25,9 @@ stamp PobreLang/shit burn PobreLang/shit +item PobreLang/shit 0 +listen PobreLang/shit +antidisestablishmentarianism PobreLang/shit +burn PobreLang/shit + work PobreLang/shit+3