Skip to content

Commit

Permalink
adding user input functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
decrovert committed Aug 8, 2022
1 parent 926e6d8 commit 02741bd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pobrelanglib/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
18 changes: 18 additions & 0 deletions pobrelanglib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions test.pbr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 02741bd

Please sign in to comment.