Skip to content

Commit 34184f2

Browse files
committed
Test adam's working code
1 parent b429c26 commit 34184f2

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

Custom_Tests/test07.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var x = 10;
2+
{
3+
var y = 2;
4+
var z = x * y;
5+
x = z;
6+
}
7+
return x;

interpreter.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
; All errors, despite their text, return 'error for test purposes
3030
(define error->handler
3131
(lambda (exception) ; It is correct to not delete the lambda to abstract this out. [exn:fail? error->handler] relies on this format.
32-
'error))
32+
exception))
3333

3434
; Important section helper functions for abstraction are defined below
3535

state-manipulation.scm

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
((eq? 'var (get-upcoming-statement-name arglist)) (cons nullreturn (list (G-evaluate-var-declare-statement->state arglist state))))
4747
((eq? 'while (get-upcoming-statement-name arglist)) (G-evaluate-while-statement->retval_state arglist state nullreturn))
4848
((eq? 'if (get-upcoming-statement-name arglist)) (G-evaluate-if-statement->retval_state arglist state))
49+
;((eq? 'begin (get-upcoming-statement-name arglist)) (G-evaluate-block-statement->retval_state arglist state))
50+
((eq? 'begin (get-upcoming-statement-name arglist))
51+
(list
52+
(get-value-from-pair (evaluate-parse-tree->retval_state (cdr arglist) (G-add-scope-to-state->state state)))
53+
(get-tail-scope (get-state-from-pair (evaluate-parse-tree->retval_state (cdr arglist) (G-add-scope-to-state->state state))))))
4954
(else (cons nullreturn (list (get-state-from-pair (G-eval-atomic-statement->value_state arglist state))))))))
5055

5156
; Important section helper functions for abstraction are defined below
@@ -60,6 +65,20 @@
6065

6166

6267

68+
; Evaluate Block section
69+
70+
(define G-evaluate-block-statement->retval_state
71+
(lambda (argslist state)
72+
(cond
73+
((evaluate-parse-tree->retval_state (rest-of-program argslist)
74+
(G-remove-scope-from-state->state
75+
(get-state-from-pair
76+
(evaluate-parse-tree->retval_state
77+
(block-statements argslist) (G-add-scope-to-state->state state)))))))))
78+
79+
(define block-statements cdr)
80+
(define rest-of-program cdr)
81+
6382

6483

6584

@@ -82,13 +101,6 @@
82101

83102

84103

85-
86-
87-
88-
89-
90-
91-
92104
; if statement section
93105

94106
; Returns the value yielded from an if statement and the updated state

0 commit comments

Comments
 (0)