rley 0.0.03 → 0.0.04
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 +8 -8
- data/CHANGELOG.md +3 -0
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/parser/dotted_item.rb +73 -68
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODc2MTFmNTM3MjNjNTEyMzYzOWNmNmQ1OGM0NDUwNGFiNjViYzEyMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjA5ZWUzYzczYzJhODQxMmM3MDJhNzYzMTA0NWRjNmNkNWYyOTFiNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTBmMGU1NWIxYjhlODQ2YmNkZWQyYmIwZGZiNDQzNGExNGI0ZjgwNjZmYjNi
|
10
|
+
NmZmZDNkOWZkNjE5NmI4ZjE0ZjJkZmIwNzUxOWIxNzUxZDI0ZWRlZWJjZWI1
|
11
|
+
NjM0NGM3NGM0NmI5N2QzNjBhNjExNjRmMWM4MDJkZmFiMDE5ZTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWQyYjUzMzVmZjRlNDE4ZGZmODMwNmNkNWQ4ODZhM2U5NGFhM2ZmNzM4MjQ3
|
14
|
+
MDI3M2JlMWFiNDNiN2VlNTYxYTE3YWZlZTFiYzFkYTViMmFhMjlmMzk2OGY1
|
15
|
+
MDY3NjI4M2Y0NDE3MTQ2ODI2OTU3MjJhYTg4YjJmYjU2NmZlMzk=
|
data/CHANGELOG.md
CHANGED
data/lib/rley/constants.rb
CHANGED
@@ -1,80 +1,85 @@
|
|
1
|
-
#
|
2
|
-
# It partitions the rhs of the rule in two parts.
|
3
|
-
# The left part consists of the symbols in the rules that are matched
|
4
|
-
# by the input tokens.
|
5
|
-
# The right part consists of symbols that are predicted to match the
|
6
|
-
# input tokens.
|
7
|
-
# The terminology stems from the traditional way to visualize the partition
|
8
|
-
# by using a fat dot character as a separator between the left and right parts
|
9
|
-
# An item with the dot at the beginning (i.e. before any rhs symbol)
|
10
|
-
# is called a predicted item.
|
11
|
-
# An item with the dot at the end (i.e. after all rhs symbols)
|
12
|
-
# is called a reduce item.
|
13
|
-
# An item with a dot in front of a terminal is called a shift item.
|
14
|
-
class DottedItem
|
15
|
-
# Production rule
|
16
|
-
attr_reader(:production)
|
1
|
+
module Rley # This module is used as a namespace
|
17
2
|
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
|
3
|
+
# A dotted item is a parse state for a given production/grammar rule
|
4
|
+
# It partitions the rhs of the rule in two parts.
|
5
|
+
# The left part consists of the symbols in the rules that are matched
|
6
|
+
# by the input tokens.
|
7
|
+
# The right part consists of symbols that are predicted to match the
|
8
|
+
# input tokens.
|
9
|
+
# The terminology stems from the traditional way to visualize the partition
|
10
|
+
# by using a fat dot character as a separator between the left and right
|
11
|
+
# parts
|
12
|
+
# An item with the dot at the beginning (i.e. before any rhs symbol)
|
13
|
+
# is called a predicted item.
|
14
|
+
# An item with the dot at the end (i.e. after all rhs symbols)
|
15
|
+
# is called a reduce item.
|
16
|
+
# An item with a dot in front of a terminal is called a shift item.
|
17
|
+
class DottedItem
|
18
|
+
# Production rule
|
19
|
+
attr_reader(:production)
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# Return true if the dot position is at the start of the rhs.
|
31
|
-
def at_start?()
|
32
|
-
return position == 0 || position == -2
|
33
|
-
end
|
21
|
+
# Index of the next symbol (from the rhs) after the 'dot'.
|
22
|
+
# If the dot is at the end of the rhs (i.e.) there is no next
|
23
|
+
# symbol, then the position takes the value -1.
|
24
|
+
# It the rhs is empty, then the postion is -2
|
25
|
+
attr_reader(:position)
|
34
26
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
def lhs()
|
46
|
-
return production.lhs
|
47
|
-
end
|
48
|
-
|
49
|
-
# Return the symbol after the dot.
|
50
|
-
# nil is returned if the dot is at the end
|
51
|
-
def next_symbol()
|
52
|
-
result = (position < 0) ? nil : production.rhs[position]
|
53
|
-
end
|
27
|
+
# @param aProduction
|
28
|
+
def initialize(aProduction, aPosition)
|
29
|
+
@production = aProduction
|
30
|
+
@position = valid_position(aPosition)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Return true if the dot position is at the start of the rhs.
|
34
|
+
def at_start?()
|
35
|
+
return position == 0 || position == -2
|
36
|
+
end
|
54
37
|
|
55
|
-
|
56
|
-
|
57
|
-
|
38
|
+
# An item with the dot at the beginning is called
|
39
|
+
# predicted item
|
40
|
+
alias :predicted_item? :at_start?
|
58
41
|
|
59
|
-
|
42
|
+
# A dotted item is called a reduce item if the dot is at the end.
|
43
|
+
def reduce_item?()
|
44
|
+
return position < 0 # Either -1 or -2
|
45
|
+
end
|
46
|
+
|
47
|
+
# The non-terminal symbol that is on the left-side of the production
|
48
|
+
def lhs()
|
49
|
+
return production.lhs
|
50
|
+
end
|
51
|
+
|
52
|
+
# Return the symbol after the dot.
|
53
|
+
# nil is returned if the dot is at the end
|
54
|
+
def next_symbol()
|
55
|
+
result = (position < 0) ? nil : production.rhs[position]
|
56
|
+
end
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
rhs_size = production.rhs.size
|
64
|
-
if aPosition < 0 || aPosition > rhs_size
|
65
|
-
fail StandardError, 'Out of bound index'
|
58
|
+
# An item with the dot in front of a terminal is called a shift item
|
59
|
+
def shift_item?()
|
66
60
|
end
|
67
61
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
62
|
+
private
|
63
|
+
|
64
|
+
# Return the given after its validation.
|
65
|
+
def valid_position(aPosition)
|
66
|
+
rhs_size = production.rhs.size
|
67
|
+
if aPosition < 0 || aPosition > rhs_size
|
68
|
+
fail StandardError, 'Out of bound index'
|
69
|
+
end
|
70
|
+
|
71
|
+
if rhs_size == 0
|
72
|
+
index = -2 # Minus 2 at start/end of empty production
|
73
|
+
elsif aPosition == rhs_size
|
74
|
+
index = -1 # Minus 1 at end of non-empty production
|
75
|
+
else
|
76
|
+
index = aPosition
|
77
|
+
end
|
78
|
+
|
79
|
+
return index
|
74
80
|
end
|
81
|
+
end # class
|
75
82
|
|
76
|
-
|
77
|
-
end
|
78
|
-
end # class
|
83
|
+
end # module
|
79
84
|
|
80
85
|
# End of file
|