kalculator 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kalculator/evaluator.rb +10 -0
- data/lib/kalculator/lexer.rb +2 -0
- data/lib/kalculator/parser.rb +3 -0
- data/lib/kalculator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5026dd4c73a2ebf6f64a18d11d6ef1c8838f902a4fb9fdee31bba43c0819d998
|
4
|
+
data.tar.gz: dacfcdd98e1bc4c08048052b1f4ce4fa94449ac05d7217842c9fbfbce8c0efc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35c4bab92d9ed7b895f7f60231a8cfbd01a4ecefec46f0eebdff27a465543fe3ab6f14b6a2876df636ebb9fc20a02ebfbb1695a04d50197c80b7678cc513222b
|
7
|
+
data.tar.gz: 243833c66d4dc6a3eb952a53610226cf28c5f8d94b49c77b95d71737d33ec35ef32bafd3ebda38511b96be36fda8cc9ac59cc71ff47ae958940bd5401f6af2a5
|
data/lib/kalculator/evaluator.rb
CHANGED
@@ -44,6 +44,10 @@ class Kalculator
|
|
44
44
|
evaluate(left) == evaluate(right)
|
45
45
|
end
|
46
46
|
|
47
|
+
def !=(_, left, right)
|
48
|
+
evaluate(left) != evaluate(right)
|
49
|
+
end
|
50
|
+
|
47
51
|
def and(_, left, right)
|
48
52
|
evaluate(left) && evaluate(right)
|
49
53
|
end
|
@@ -80,6 +84,12 @@ class Kalculator
|
|
80
84
|
expressions.map{|expression| evaluate(expression) }
|
81
85
|
end
|
82
86
|
|
87
|
+
def not(_, expression)
|
88
|
+
bool = evaluate(expression)
|
89
|
+
raise TypeError, "! only works with booleans, got #{bool.inspect}" unless bool === true || bool === false
|
90
|
+
!bool
|
91
|
+
end
|
92
|
+
|
83
93
|
def number(_, number)
|
84
94
|
number
|
85
95
|
end
|
data/lib/kalculator/lexer.rb
CHANGED
@@ -15,8 +15,10 @@ class Kalculator
|
|
15
15
|
rule(/</) { :LT }
|
16
16
|
rule(/<=/) { :LTE }
|
17
17
|
rule(/==/) { :EQ }
|
18
|
+
rule(/!=/) { :NEQ }
|
18
19
|
rule(/AND/) { :AND }
|
19
20
|
rule(/OR/) { :OR }
|
21
|
+
rule(/!/) { :BANG }
|
20
22
|
rule(/\-?\d+/) { |t| [:NUMBER, t.to_i] }
|
21
23
|
rule(/\-?\.\d+/) { |t| [:NUMBER, t.to_f] }
|
22
24
|
rule(/\-?\d+\.\d+/) { |t| [:NUMBER, t.to_f] }
|
data/lib/kalculator/parser.rb
CHANGED
@@ -30,6 +30,7 @@ class Kalculator
|
|
30
30
|
clause('expression LT expression') { |e0, _, e1| [:<, e0, e1] }
|
31
31
|
clause('expression LTE expression') { |e0, _, e1| [:<=, e0, e1] }
|
32
32
|
clause('expression EQ expression') { |e0, _, e1| [:==, e0, e1] }
|
33
|
+
clause('expression NEQ expression') { |e0, _, e1| [:!=, e0, e1] }
|
33
34
|
|
34
35
|
clause('expression AND expression') { |e0, _, e1| [:and, e0, e1] }
|
35
36
|
clause('expression OR expression') { |e0, _, e1| [:or, e0, e1] }
|
@@ -38,6 +39,8 @@ class Kalculator
|
|
38
39
|
clause('expression SUB expression') { |e0, _, e1| [:-, e0, e1] }
|
39
40
|
clause('expression MUL expression') { |e0, _, e1| [:*, e0, e1] }
|
40
41
|
clause('expression DIV expression') { |e0, _, e1| [:/, e0, e1] }
|
42
|
+
|
43
|
+
clause('BANG expression') { |_, e0| [:not, e0] }
|
41
44
|
end
|
42
45
|
|
43
46
|
production(:expressions) do
|
data/lib/kalculator/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kalculator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Ries
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rltk
|