diff --git a/main.py b/main.py index 3a5b9af..d72d9dc 100755 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ def do_system_print(env, args): (text_type, text_value) = args[0] - if text_type == "symbol": + if text_type == "reference": (text_type, text_value) = env[text_value] if text_type != "text": print("Invalid print value: %s" % (text_type)) @@ -27,8 +27,10 @@ } def run_statement(env, ast): - command = env[ast[1]][ast[2]] - return command(env, ast[3]) + subject = env[ast[1][1]] + command = subject[ast[2]] + args = ast[3] + return command(env, args) def run_set(env, ast): env[ast[1]] = run_statement(env, ast[2]) diff --git a/parse.py b/parse.py index 0f8338b..ad76322 100644 --- a/parse.py +++ b/parse.py @@ -83,12 +83,14 @@ print("Parsed language version %s" % (value)) return value -def parse_subject(): - (type, value) = parser_next() - if type != "symbol": - print("Expected symbol, got %s" % (type)) +def parse_value(type, value): + if type == "symbol": + return ('reference', value) + elif type == "text": + return ('text', value) + else: + print("Unexpected type %s" % (type)) return None - return value def parse_verb(): (type, value) = parser_next() @@ -107,14 +109,16 @@ else: print("Unexpected keyword %s" % (value)) return None - elif type == "text" or type == "symbol": - args.append((type, value)) else: - print("Unexpected type %s" % (type)) - return None + arg = parse_value(type, value) + if not arg: + print("While parsing argument") + return None + args.append(arg) def parse_statement(terminator): - subject = parse_subject() + (type, value) = parser_next() + subject = parse_value(type, value) if not subject: print("While parsing subject") return None @@ -130,10 +134,11 @@ return ('statement', subject, verb, arguments) def parse_set(): - subject = parse_subject() - if not subject: - print("While parsing subject") + (type, value) = parser_next() + if type != "symbol": + print("Expect symbol, got %s" % (type)) return None + subject = value (type, value) = parser_next() if type != "keyword" or value != "to": print("Expect to, got %s %s" % (type, value)) @@ -213,4 +218,3 @@ ast.append(directive) print("Parsed file") return ast -