hilbert 0.0.2700320 → 0.0.2700400
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hilbert/lexer/main_lexer.rb +3 -3
- data/lib/hilbert/lexer/tokens.rb +1 -1
- data/lib/hilbert/parser.rb +2 -0
- data/lib/hilbert/version.rb +1 -1
- data/lib/hilbert/world.rb +31 -22
- data/lib/hilbert.rb +0 -1
- data/test/interpreter/test_general.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaae59caf189918270514b0f61b45b2a6fd58205
|
4
|
+
data.tar.gz: accc47c0dba81a2cd05232171b1d30720c57e16f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fff4fc11e9d6afefd44c05e5f10b28e6d150bd37427e7eaea3ab56175e1c06a4960c1ed8fd5d50c9489900728d0b29be672027fa73182b2b37c9c57e7de6dcab
|
7
|
+
data.tar.gz: b262a9666e12a6f86e05eaaaad9cf948695219f445502b2dbaf54ad74a29fe1c1cc7e0d206eacdbed229ffdcf280eee13acd9a12410fe43d11227707a58c53c5
|
@@ -6,11 +6,11 @@ module Hilbert
|
|
6
6
|
rule(/paradox\?/) { :P_PARAD }
|
7
7
|
rule(/\A.*[A-RT-Z].*\?.*\z/m) { :EVALOGIC }
|
8
8
|
rule(/\A.*[A-RT-Z].*\z/m) { :DEFLOGIC }
|
9
|
-
rule(/
|
9
|
+
rule(/#{SPC}/)
|
10
10
|
|
11
|
-
rule(
|
11
|
+
rule(/#{NLIN}+/) { :NULL }
|
12
12
|
|
13
|
-
rule(/[^\(\)\{\}(\n\n)]+/) { :
|
13
|
+
rule(/[^\(\)\{\}(\n\n)]+/) { :UNKNOW }
|
14
14
|
class << self
|
15
15
|
include Tokens
|
16
16
|
def zfc_analysis!
|
data/lib/hilbert/lexer/tokens.rb
CHANGED
data/lib/hilbert/parser.rb
CHANGED
@@ -88,6 +88,8 @@ module Hilbert
|
|
88
88
|
|
89
89
|
when /:CONT(\d+)/
|
90
90
|
lexed.parsed!(lexed.get_value($1), $1)
|
91
|
+
when /:UNKNOW(\d+)/
|
92
|
+
raise "#{lexed.get_value($1)} can not be parsed ;("
|
91
93
|
end
|
92
94
|
lexed.squash!(($1.to_i)..($1.to_i+1)) if lexed.token_str =~ /:(?:CONT|R)(\d+):(?:CONT|R)(\d+)/
|
93
95
|
end
|
data/lib/hilbert/version.rb
CHANGED
data/lib/hilbert/world.rb
CHANGED
@@ -8,29 +8,25 @@ module Hilbert
|
|
8
8
|
class << self
|
9
9
|
def <<(logic_str)
|
10
10
|
@@propositions << to_rb_obj(logic_str)
|
11
|
-
|
11
|
+
Messanger.define(logic_str)
|
12
12
|
end
|
13
13
|
|
14
14
|
def impl(logic_str)
|
15
15
|
# HOTFIX: we need to ..
|
16
|
-
return
|
16
|
+
return Messanger.evaluate(logic_str, 'UNDEFINED') if @@propositions.empty?
|
17
|
+
|
17
18
|
logic = (@@propositions.inject(:*) >= to_rb_obj(logic_str))
|
18
19
|
str = logic.dpll!.to_s
|
19
20
|
case str
|
20
|
-
when 'TRUE'
|
21
|
-
|
22
|
-
when 'FALSE'
|
23
|
-
eval_rslt(logic_str, 'FALSE')
|
21
|
+
when 'TRUE' then Messanger.evaluate(logic_str, 'TRUE')
|
22
|
+
when 'FALSE' then Messanger.evaluate(logic_str, 'FALSE')
|
24
23
|
else
|
25
24
|
logic = (@@propositions.inject(:*) >= (~to_rb_obj(logic_str)))
|
26
25
|
str = logic.dpll!.to_s
|
27
26
|
case str
|
28
|
-
when 'TRUE'
|
29
|
-
|
30
|
-
|
31
|
-
eval_rslt(logic_str, 'TRUE')
|
32
|
-
else
|
33
|
-
eval_rslt(logic_str, 'UNDEFINED')
|
27
|
+
when 'TRUE' then Messanger.evaluate(logic_str, 'FALSE')
|
28
|
+
when 'FALSE' then Messanger.evaluate(logic_str, 'TRUE')
|
29
|
+
else Messanger.evaluate(logic_str, 'UNDEFINED')
|
34
30
|
end
|
35
31
|
end
|
36
32
|
end
|
@@ -47,13 +43,11 @@ module Hilbert
|
|
47
43
|
end
|
48
44
|
|
49
45
|
def paradox?
|
50
|
-
return
|
51
|
-
|
52
|
-
case
|
53
|
-
when 'TRUE'
|
54
|
-
|
55
|
-
else
|
56
|
-
%|"FALSE"|
|
46
|
+
return Messanger.tell_false if @@propositions.empty?
|
47
|
+
|
48
|
+
case (!!!!!!!(@@propositions.inject(:*) >= (atom(:P) * ~atom(:P)))).to_s
|
49
|
+
when 'TRUE' then Messanger.tell_true
|
50
|
+
else Messanger.tell_false
|
57
51
|
end
|
58
52
|
end
|
59
53
|
|
@@ -63,11 +57,26 @@ module Hilbert
|
|
63
57
|
Parser::WorldParser.execute(lexeds)
|
64
58
|
eval Parser::WorldParser.parsed_srt
|
65
59
|
end
|
60
|
+
end
|
66
61
|
|
67
|
-
|
68
|
-
|
69
|
-
|
62
|
+
module Messanger
|
63
|
+
class << self
|
64
|
+
def define(logic_str)
|
65
|
+
%|"Defined: #{logic_str} is TRUE"|
|
66
|
+
end
|
70
67
|
|
68
|
+
def evaluate(logic_str, rslt)
|
69
|
+
%|"Evaluate: #{logic_str} is #{rslt}"|
|
70
|
+
end
|
71
|
+
|
72
|
+
def tell_true
|
73
|
+
%|"TRUE"|
|
74
|
+
end
|
75
|
+
|
76
|
+
def tell_false
|
77
|
+
%|"FALSE"|
|
78
|
+
end
|
79
|
+
end
|
71
80
|
end
|
72
81
|
end
|
73
82
|
end
|
data/lib/hilbert.rb
CHANGED
@@ -10,6 +10,9 @@ class TestGeneral < TestInterpreterBase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_general
|
13
|
+
assert_iq_equal('2', '1 + 1')
|
14
|
+
assert_iq_equal('3 / 2', '1 + 1/2')
|
15
|
+
assert_iq_equal('1', '1/2 + 1/2')
|
13
16
|
assert_iq_equal('2x', '2x')
|
14
17
|
assert_iq_equal('2x', 'x + x')
|
15
18
|
# assert_iq_equal('xy', 'xy')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hilbert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2700400
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gogotanaka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dydx
|