-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.rb
More file actions
33 lines (27 loc) · 856 Bytes
/
program.rb
File metadata and controls
33 lines (27 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require_relative 'slang'
module SLang
# step1
puts "step1: TESTING BinaryExpression & UnaryExpression"
e = BinaryExpression.new(NumericConstant.new(10), NumericConstant.new(5), '*')
puts e.evaluate(nil);
e = UnaryExpression.new(NumericConstant.new(10), '-')
puts e.evaluate(nil);
# step2
puts "step2 TESTING ExpressionBuilder"
b = ExpressionBuilder.new("-2*(3+3)")
e = b.get_expression()
puts e.evaluate(nil)
b = ExpressionBuilder.new("(-2*3)+(8/2)*(3+3)")
e = b.get_expression()
puts e.evaluate(nil)
# step3
puts "step3 TESTING PRINTLINE, PRINT statements"
e1 = "PRINTLINE 2*3; \n\rPRINTLINE (40/5)/3 ; \r"
e1 = "PRINTLINE -2*10;" + "\r\n" + "PRINTLINE -10*-1;\r\n PRINT 2*10;\r\n"
[e1, e1].each do |e|
statements = RDparser.new(e).parse()
statements.each do |st|
st.execute(nil)
end
end
end