diff --git a/ast.py b/ast.py index 60bf578..58fc8a9 100644 --- a/ast.py +++ b/ast.py @@ -72,6 +72,17 @@ def __init__(self, value): self.value = value +class PrintExpressions(Node): + def __init__(self, expression, expressions): + self.expression = expression + self.expressions = expressions + + +class PrintExpression(Node): + def __init__(self, expression): + self.expression = expression + + class ReturnInstruction(Node): def __init__(self): pass diff --git a/main.py b/main.py index 88852d9..ee541ad 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ if __name__ == '__main__': try: - filename = sys.argv[1] if len(sys.argv) > 1 else "example.txt" + filename = sys.argv[1] if len(sys.argv) > 1 else "example3.txt" file = open(filename, "r") except IOError: print("Cannot open {0} file".format(filename)) diff --git a/parser.py b/parser.py index f55f6c5..54c38a8 100644 --- a/parser.py +++ b/parser.py @@ -243,9 +243,9 @@ def p_print_list(p): """vars_to_print : vars_to_print ',' expression | expression""" if len(p) == 2: - p[0] = p[1] + p[0] = PrintExpression(p[1]) else: - p[0] = p[3] + p[0] = PrintExpressions(p[1], p[3]) def p_matrix_init_instruction(p): @@ -272,7 +272,7 @@ def p_matrix_row(p): | INTNUM """ p[0] = Row() if len(p) == 4: - p[0].concat(p[1],p[3]) + p[0].concat(p[1], p[3]) else: p[0].append(p[1]) diff --git a/treeprinter.py b/treeprinter.py index e8f4856..81f1d41 100644 --- a/treeprinter.py +++ b/treeprinter.py @@ -86,7 +86,16 @@ def printTree(self, indent=0): @addToClass(ast.PrintInstruction) def printTree(self, indent=0): print(createIndent(indent) + "print") - print(createIndent(indent + 1)+str(self.value)) + self.value.printTree(indent+1) + + @addToClass(ast.PrintExpressions) + def printTree(self, indent=0): + self.expression.printTree(indent) + self.expressions.printTree(indent) + + @addToClass(ast.PrintExpression) + def printTree(self, indent=0): + self.expression.printTree(indent) @addToClass(ast.ReturnInstruction) def printTree(self, indent=0):