calc_jquinon1 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/calc +0 -0
- data/lib/ast.rb +42 -1
- data/lib/parser.rb +22 -4
- data/lib/scanner.rb +5 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76c7ac93939d677abd36237d64c0b3c44f5f3cf9
|
4
|
+
data.tar.gz: f274eb75a3b6c430411364ce677cce3386611ec9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad12adb567014fd10d6a61d23a2debae55f24ee0f3581e4bb2649d654cd41243f958d44571d651572f07639617063cac61e3884bb46e48eacb4c2658b0fdc578
|
7
|
+
data.tar.gz: 46eb36af5f1d41b950f7ca8f3385a8af61a39c4987754f0ceb6c99bd958cbdf111b7454cb92cb29cb1e15429e4d58f1447aae8a848beb7b82973b4022d2cedfa
|
data/bin/calc
CHANGED
File without changes
|
data/lib/ast.rb
CHANGED
@@ -57,6 +57,16 @@ class DivideNode < BinaryNode
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
class ModuleNode < BinaryNode
|
61
|
+
def initialize(left,right)
|
62
|
+
super(left,right)
|
63
|
+
end
|
64
|
+
|
65
|
+
def evaluate
|
66
|
+
@left.evaluate % @right.evaluate
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
60
70
|
class StoreNode < UnaryNode
|
61
71
|
def initialize(subTree)
|
62
72
|
super(subTree)
|
@@ -67,18 +77,49 @@ class StoreNode < UnaryNode
|
|
67
77
|
end
|
68
78
|
end
|
69
79
|
|
80
|
+
class PlusNode < UnaryNode
|
81
|
+
def initialize(subTree)
|
82
|
+
super(subTree)
|
83
|
+
end
|
84
|
+
|
85
|
+
def evaluate
|
86
|
+
result1 = @subTree.evaluate
|
87
|
+
result2 = $calc.memory
|
88
|
+
result1+result2
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class MinusNode < UnaryNode
|
93
|
+
def initialize(subTree)
|
94
|
+
super(subTree)
|
95
|
+
end
|
96
|
+
|
97
|
+
def evaluate
|
98
|
+
result1 = @subTree.evaluate
|
99
|
+
result2 = $calc.memory
|
100
|
+
result1-result2
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
70
104
|
class RecallNode
|
71
105
|
def evaluate
|
72
106
|
$calc.memory
|
73
107
|
end
|
74
108
|
end
|
75
109
|
|
110
|
+
class ClearNode
|
111
|
+
|
112
|
+
def evaluate
|
113
|
+
$calc.memory = 0
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
76
117
|
class NumNode
|
77
118
|
def initialize(num)
|
78
119
|
@num = num
|
79
120
|
end
|
80
121
|
|
81
|
-
def evaluate
|
122
|
+
def evaluate
|
82
123
|
return @num
|
83
124
|
end
|
84
125
|
end
|
data/lib/parser.rb
CHANGED
@@ -72,6 +72,11 @@ class Parser
|
|
72
72
|
if t.type==:divide
|
73
73
|
return RestTerm(DivideNode.new(e,Storable()))
|
74
74
|
end
|
75
|
+
|
76
|
+
if t.type == :module
|
77
|
+
return RestTerm(ModuleNode.new(e,Storable()))
|
78
|
+
end
|
79
|
+
|
75
80
|
@scan.putBackToken
|
76
81
|
return e
|
77
82
|
end
|
@@ -82,9 +87,18 @@ class Parser
|
|
82
87
|
t=@scan.getToken
|
83
88
|
if t.type == :keyword
|
84
89
|
if t.lex == "S"
|
85
|
-
return
|
90
|
+
return StoreNode.new(result)
|
91
|
+
end
|
92
|
+
|
93
|
+
if t.lex == "P"
|
94
|
+
return PlusNode.new(result)
|
86
95
|
end
|
87
|
-
|
96
|
+
|
97
|
+
if t.lex == "M"
|
98
|
+
return MinusNode.new(result)
|
99
|
+
end
|
100
|
+
|
101
|
+
puts "Expected S, P or M found: ", t.lex
|
88
102
|
raise ParseError.new
|
89
103
|
end
|
90
104
|
|
@@ -102,10 +116,14 @@ class Parser
|
|
102
116
|
|
103
117
|
if t.type == :keyword
|
104
118
|
if t.lex == "R"
|
105
|
-
return RecallNode
|
119
|
+
return RecallNode.new
|
120
|
+
end
|
121
|
+
|
122
|
+
if t.lex == "C"
|
123
|
+
return ClearNode.new
|
106
124
|
end
|
107
125
|
|
108
|
-
puts "Expected R found: " + t.lex
|
126
|
+
puts "Expected R or C found: " + t.lex
|
109
127
|
raise ParseError.new
|
110
128
|
end
|
111
129
|
|
data/lib/scanner.rb
CHANGED
@@ -4,7 +4,7 @@ require 'calcex'
|
|
4
4
|
class Scanner
|
5
5
|
def initialize(inStream)
|
6
6
|
@istream = inStream
|
7
|
-
@keywords = Set.new(["S","R"])
|
7
|
+
@keywords = Set.new(["S","R","C","M","P"])
|
8
8
|
@lineCount = 1
|
9
9
|
@colCount = -1
|
10
10
|
@needToken = true
|
@@ -45,6 +45,7 @@ class Scanner
|
|
45
45
|
elsif c == ?/ then state = 6
|
46
46
|
elsif c == ?( then state = 7
|
47
47
|
elsif c == ?) then state = 8
|
48
|
+
elsif c == ?% then state = 9
|
48
49
|
elsif c == ?\n then
|
49
50
|
@colCount = -1
|
50
51
|
@lineCount = @lineCount+1
|
@@ -91,6 +92,9 @@ class Scanner
|
|
91
92
|
when 8
|
92
93
|
type = :rparen
|
93
94
|
foundOne = true
|
95
|
+
when 9
|
96
|
+
type = :module
|
97
|
+
foundOne = true
|
94
98
|
end
|
95
99
|
|
96
100
|
if !foundOne then
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calc_jquinon1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Kent D. Lee - Juan Francisco Cardona Mc
|
7
|
+
- Kent D. Lee - Juan Francisco Cardona Mc - Jhonatan Quiñonez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
44
|
version: '0'
|
45
45
|
requirements: []
|
46
46
|
rubyforge_project:
|
47
|
-
rubygems_version: 2.4.
|
47
|
+
rubygems_version: 2.4.5.1
|
48
48
|
signing_key:
|
49
49
|
specification_version: 4
|
50
50
|
summary: Another calculator in ruby
|