File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,15 @@ def parse
38
38
identifier = tokenizer . identifier
39
39
40
40
Variable . new ( identifier )
41
+ when Tokenizer ::SYMBOL
42
+ fail 'Not an opening parenthesis' unless tokenizer . symbol == '('
43
+ tokenizer . advance
44
+
45
+ node = parse
46
+
47
+ fail 'Not a closing parenthesis' unless tokenizer . token_type == Tokenizer ::SYMBOL && tokenizer . symbol == ')'
48
+
49
+ node
41
50
end
42
51
43
52
return left_node unless tokenizer . has_more_tokens?
Original file line number Diff line number Diff line change 76
76
push constant 2
77
77
push constant 3
78
78
add
79
+ add
80
+ VM
81
+ end
82
+
83
+ it 'emits VM code for compound binary expressions with parentheses' do
84
+ tokenizer = Tokenizer . new ( '(1 + 2) + 3' )
85
+ tokenizer . advance
86
+
87
+ symbol_table = SymbolTable . new
88
+
89
+ result = ExpressionParser . new ( tokenizer ) . parse
90
+ output = StringIO . new
91
+ vm_writer = VMWriter . new ( output )
92
+ result . emit ( vm_writer , symbol_table )
93
+
94
+ expect ( output . string ) . to eq ( <<-VM )
95
+ push constant 1
96
+ push constant 2
97
+ add
98
+ push constant 3
79
99
add
80
100
VM
81
101
end
You can’t perform that action at this time.
0 commit comments