Improve lisp compiler and interpreter.
This commit is contained in:
parent
be97b30e86
commit
8b7e6ae7ba
1 changed files with 4 additions and 2 deletions
|
@ -73,6 +73,8 @@ class Environment:
|
||||||
'-': lambda _, a, b: a - b,
|
'-': lambda _, a, b: a - b,
|
||||||
'*': lambda _, *a: functools.reduce(lambda a, b: a * b, a),
|
'*': lambda _, *a: functools.reduce(lambda a, b: a * b, a),
|
||||||
'/': lambda _, a, b: a // b,
|
'/': lambda _, a, b: a // b,
|
||||||
|
'|': lambda _, *a: functools.reduce(lambda a, b: a or b, a),
|
||||||
|
'&': lambda _, *a: functools.reduce(lambda a, b: a and b, a),
|
||||||
}
|
}
|
||||||
self._lazy_functions = {
|
self._lazy_functions = {
|
||||||
'?': lazy_fc_if,
|
'?': lazy_fc_if,
|
||||||
|
@ -242,11 +244,11 @@ def token_extract_boolean(stream: str) -> tuple[Token, str]:
|
||||||
|
|
||||||
def token_extract_keyword(stream: str) -> tuple[Token, str]:
|
def token_extract_keyword(stream: str) -> tuple[Token, str]:
|
||||||
i = 0
|
i = 0
|
||||||
if stream[i] in string.ascii_letters + '_-><=!+-*/?':
|
if stream[i] in string.ascii_letters + '_-><=!+-*/?&|':
|
||||||
i += 1
|
i += 1
|
||||||
else:
|
else:
|
||||||
raise ValueError('No keyword in stream')
|
raise ValueError('No keyword in stream')
|
||||||
while stream[i] in string.ascii_letters + '_-><=!+-*/?':
|
while stream[i] in string.ascii_letters + '_-><=!+-*/?&|':
|
||||||
i += 1
|
i += 1
|
||||||
return Token(Token.KEYWORD, stream[:i]), stream[i:]
|
return Token(Token.KEYWORD, stream[:i]), stream[i:]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue