antelope 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -0
- data/CONTRIBUTING.md +4 -4
- data/GENERATORS.md +61 -19
- data/README.md +84 -9
- data/TODO.md +58 -0
- data/examples/deterministic.ace +21 -9
- data/examples/example.ace +16 -10
- data/examples/example.output +213 -146
- data/examples/simple.ace +1 -1
- data/lib/antelope/ace/compiler.rb +52 -15
- data/lib/antelope/ace/errors.rb +7 -0
- data/lib/antelope/ace/grammar/generation.rb +3 -3
- data/lib/antelope/ace/grammar/precedences.rb +5 -7
- data/lib/antelope/ace/grammar/productions.rb +36 -11
- data/lib/antelope/ace/grammar/{terminals.rb → symbols.rb} +25 -2
- data/lib/antelope/ace/grammar.rb +12 -3
- data/lib/antelope/ace/precedence.rb +4 -0
- data/lib/antelope/ace/scanner/argument.rb +57 -0
- data/lib/antelope/ace/scanner/first.rb +32 -6
- data/lib/antelope/ace/scanner/second.rb +23 -8
- data/lib/antelope/ace/scanner.rb +32 -26
- data/lib/antelope/ace/token.rb +21 -2
- data/lib/antelope/cli.rb +22 -2
- data/lib/antelope/generation/constructor/first.rb +1 -1
- data/lib/antelope/generation/constructor.rb +2 -0
- data/lib/antelope/generation/null.rb +13 -0
- data/lib/antelope/generation/recognizer/rule.rb +4 -3
- data/lib/antelope/generation/recognizer/state.rb +18 -3
- data/lib/antelope/generation/recognizer.rb +19 -24
- data/lib/antelope/generation/tableizer.rb +30 -2
- data/lib/antelope/generation.rb +1 -0
- data/lib/antelope/generator/base.rb +150 -13
- data/lib/antelope/generator/c.rb +11 -0
- data/lib/antelope/generator/c_header.rb +105 -0
- data/lib/antelope/generator/c_source.rb +39 -0
- data/lib/antelope/generator/null.rb +5 -0
- data/lib/antelope/generator/output.rb +3 -3
- data/lib/antelope/generator/ruby.rb +23 -5
- data/lib/antelope/generator/templates/c_header.ant +36 -0
- data/lib/antelope/generator/templates/c_source.ant +202 -0
- data/lib/antelope/generator/templates/output.ant +68 -0
- data/lib/antelope/generator/templates/ruby.ant +146 -0
- data/lib/antelope/generator.rb +15 -3
- data/lib/antelope/template/compiler.rb +78 -0
- data/lib/antelope/template/errors.rb +9 -0
- data/lib/antelope/template/scanner.rb +111 -0
- data/lib/antelope/template.rb +60 -0
- data/lib/antelope/version.rb +1 -1
- data/lib/antelope.rb +1 -0
- data/spec/antelope/template_spec.rb +39 -0
- data/subl/Ace (Ruby).JSON-tmLanguage +94 -0
- data/subl/Ace (Ruby).tmLanguage +153 -0
- metadata +21 -8
- data/examples/deterministic.output +0 -131
- data/examples/simple.output +0 -121
- data/lib/antelope/generator/templates/output.erb +0 -56
- data/lib/antelope/generator/templates/ruby.erb +0 -63
data/examples/simple.output
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
Productions:
|
2
|
-
0 $start: e $
|
3
|
-
1 e: l "=" r
|
4
|
-
2 e: r
|
5
|
-
3 l: IDENT
|
6
|
-
4 l: "*" r
|
7
|
-
5 r: l
|
8
|
-
|
9
|
-
Precedence:
|
10
|
-
--- highest
|
11
|
-
nonassoc 1:
|
12
|
-
{_}
|
13
|
-
nonassoc 0:
|
14
|
-
{$}
|
15
|
-
--- lowest
|
16
|
-
|
17
|
-
State 0:
|
18
|
-
0/n0: $start → • e $
|
19
|
-
{}
|
20
|
-
1/n1: e → • l "=" r
|
21
|
-
{}
|
22
|
-
2/n1: e → • r
|
23
|
-
{}
|
24
|
-
3/n1: l → • IDENT
|
25
|
-
{}
|
26
|
-
4/n1: l → • "*" r
|
27
|
-
{}
|
28
|
-
5/n1: r → • l
|
29
|
-
{}
|
30
|
-
transitions:
|
31
|
-
e: State 1
|
32
|
-
l: State 2
|
33
|
-
r: State 3
|
34
|
-
IDENT: State 4
|
35
|
-
"*": State 5
|
36
|
-
|
37
|
-
State 1:
|
38
|
-
6/n0: $start → e • $
|
39
|
-
{}
|
40
|
-
transitions:
|
41
|
-
$: State 6
|
42
|
-
|
43
|
-
State 2:
|
44
|
-
7/n1: e → l • "=" r
|
45
|
-
{}
|
46
|
-
8/n1: r → l •
|
47
|
-
{$}
|
48
|
-
transitions:
|
49
|
-
"=": State 7
|
50
|
-
reductions:
|
51
|
-
$: Rule 5
|
52
|
-
|
53
|
-
State 3:
|
54
|
-
9/n1: e → r •
|
55
|
-
{$}
|
56
|
-
reductions:
|
57
|
-
$: Rule 2
|
58
|
-
|
59
|
-
State 4:
|
60
|
-
10/n1: l → IDENT •
|
61
|
-
{"=", $}
|
62
|
-
reductions:
|
63
|
-
"=": Rule 3
|
64
|
-
$: Rule 3
|
65
|
-
|
66
|
-
State 5:
|
67
|
-
11/n1: l → "*" • r
|
68
|
-
{}
|
69
|
-
12/n1: r → • l
|
70
|
-
{}
|
71
|
-
13/n1: l → • IDENT
|
72
|
-
{}
|
73
|
-
14/n1: l → • "*" r
|
74
|
-
{}
|
75
|
-
transitions:
|
76
|
-
r: State 8
|
77
|
-
l: State 9
|
78
|
-
IDENT: State 4
|
79
|
-
"*": State 5
|
80
|
-
|
81
|
-
State 6:
|
82
|
-
15/n0: $start → e $ •
|
83
|
-
{}
|
84
|
-
accepting:
|
85
|
-
$: Rule 0
|
86
|
-
|
87
|
-
State 7:
|
88
|
-
16/n1: e → l "=" • r
|
89
|
-
{}
|
90
|
-
17/n1: r → • l
|
91
|
-
{}
|
92
|
-
18/n1: l → • IDENT
|
93
|
-
{}
|
94
|
-
19/n1: l → • "*" r
|
95
|
-
{}
|
96
|
-
transitions:
|
97
|
-
r: State 10
|
98
|
-
l: State 9
|
99
|
-
IDENT: State 4
|
100
|
-
"*": State 5
|
101
|
-
|
102
|
-
State 8:
|
103
|
-
20/n1: l → "*" r •
|
104
|
-
{"=", $}
|
105
|
-
reductions:
|
106
|
-
"=": Rule 4
|
107
|
-
$: Rule 4
|
108
|
-
|
109
|
-
State 9:
|
110
|
-
21/n1: r → l •
|
111
|
-
{"=", $}
|
112
|
-
reductions:
|
113
|
-
"=": Rule 5
|
114
|
-
$: Rule 5
|
115
|
-
|
116
|
-
State 10:
|
117
|
-
22/n1: e → l "=" r •
|
118
|
-
{$}
|
119
|
-
reductions:
|
120
|
-
$: Rule 1
|
121
|
-
|
@@ -1,56 +0,0 @@
|
|
1
|
-
Productions:
|
2
|
-
% len = grammar.all_productions.size.to_s.size
|
3
|
-
% productions = grammar.all_productions.
|
4
|
-
% map { |x| ["#{x.label}: #{x.items.join(' ')}", x.block] }
|
5
|
-
% body = productions.map { |_| _.first.size }.max
|
6
|
-
% productions.each_with_index do |prod, i|
|
7
|
-
<%= "%#{len}s" % i %> <%= "%-#{body}s" % prod[0] %> <%= prod[1] %>
|
8
|
-
% end
|
9
|
-
|
10
|
-
% if unused_symbols.any?
|
11
|
-
Symbols unused in grammar:
|
12
|
-
% unused_symbols.each do |sym|
|
13
|
-
<%= sym %>
|
14
|
-
% end
|
15
|
-
% end
|
16
|
-
|
17
|
-
Precedence:
|
18
|
-
--- highest
|
19
|
-
% grammar.precedence.each do |pr|
|
20
|
-
<%= "%-8s" % pr.type %> <%= pr.level %>:
|
21
|
-
{<%= pr.tokens.to_a.join(", ") %>}
|
22
|
-
% end
|
23
|
-
--- lowest
|
24
|
-
|
25
|
-
% len = tableizer.table.flatten.map(&:keys).flatten.map(&:size).max
|
26
|
-
% states = grammar.states.to_a
|
27
|
-
% tableizer.table.each_with_index do |v, i|
|
28
|
-
% state = states[i]
|
29
|
-
State <%= i %>:
|
30
|
-
% state.rules.each do |rule|
|
31
|
-
<%= rule %>
|
32
|
-
{<%= rule.lookahead.to_a.join(", ") %>}
|
33
|
-
% end
|
34
|
-
% transitions = v.each.select { |_, a| a && a[0] == :state }
|
35
|
-
% reductions = v.each.select { |_, a| a && a[0] == :reduce}
|
36
|
-
% accepting = v.each.select { |_, a| a && a[0] == :accept}
|
37
|
-
% conflicts = tableizer.conflicts[i].each
|
38
|
-
% thing = [:transitions, :reductions, :accepting]
|
39
|
-
% num_type = {transitions: "State", reductions: "Rule", accepting: "Rule"}
|
40
|
-
% h = Hash[thing.zip([transitions, reductions, accepting])]
|
41
|
-
% h.each do |key, value|
|
42
|
-
% next unless value.any?
|
43
|
-
<%= key %>:
|
44
|
-
% value.each do |token, (_, name)|
|
45
|
-
% token_value = grammar.terminals.find { |_| _.name == token } || token
|
46
|
-
<%= token_value %>: <%= num_type[key] %> <%= name %>
|
47
|
-
% end
|
48
|
-
% end
|
49
|
-
% if conflicts.any?
|
50
|
-
conflicts:
|
51
|
-
% conflicts.each do |token, (first, second, rule, terminal)|
|
52
|
-
<%= token %>: <%= first.join(" ") %>/<%= second.join(" ") %> (<%= rule %> vs <%= terminal %>)
|
53
|
-
% end
|
54
|
-
% end
|
55
|
-
|
56
|
-
% end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
|
2
|
-
# This file assumes that the output of the generator will be placed
|
3
|
-
# within a module or a class. However, the module/class requires a
|
4
|
-
# `type` method, which takes a terminal and gives its type, as a
|
5
|
-
# symbol. These types should line up with the terminals that were
|
6
|
-
# defined in the original grammar.
|
7
|
-
|
8
|
-
# The actions to take during parsing. In every state, there are a
|
9
|
-
# set of acceptable peek tokens; this table tells the parser what
|
10
|
-
# to do on each acceptable peek token. The possible actions include
|
11
|
-
# `:accept`, `:reduce`, and `:state`; `:accept` means to accept the
|
12
|
-
# input and return the value of the pasing. `:reduce` means to
|
13
|
-
# reduce the top of the stack into a given nonterminal. `:state`
|
14
|
-
# means to transition to another state.
|
15
|
-
#
|
16
|
-
# @return [Array<Hash<(Symbol, Array<(Symbol, Numeric)>)>>]
|
17
|
-
ACTION_TABLE = <%= generate_action_table %>.freeze # >
|
18
|
-
|
19
|
-
# A list of all of the productions. Only includes the left-hand side,
|
20
|
-
# the number of tokens on the right-hand side, and the block to call
|
21
|
-
# on reduction.
|
22
|
-
#
|
23
|
-
# @return [Array<Array<(Symbol, Numeric, Proc)>>]
|
24
|
-
PRODUCTIONS = <%= generate_productions_list %>.freeze # >
|
25
|
-
|
26
|
-
# Runs the parser.
|
27
|
-
#
|
28
|
-
# @param input [Array<Object>] the input to run the parser over.
|
29
|
-
# @return [Object] the result of the accept.
|
30
|
-
def parse(input)
|
31
|
-
stack = []
|
32
|
-
stack.push([nil, 0])
|
33
|
-
input = input.dup
|
34
|
-
last = nil
|
35
|
-
|
36
|
-
until stack.empty? do
|
37
|
-
peek_token = if input.empty?
|
38
|
-
:"$"
|
39
|
-
else
|
40
|
-
type(input.first)
|
41
|
-
end
|
42
|
-
|
43
|
-
action = ACTION_TABLE[stack.last.last].fetch(peek_token)
|
44
|
-
case action.first
|
45
|
-
when :accept
|
46
|
-
production = PRODUCTIONS[action.last]
|
47
|
-
last = stack.pop(production[1]).first.first
|
48
|
-
stack.pop
|
49
|
-
when :reduce
|
50
|
-
production = PRODUCTIONS[action.last]
|
51
|
-
removing = stack.pop(production[1])
|
52
|
-
value = instance_exec(*removing.map(&:first), &production[2])
|
53
|
-
goto = ACTION_TABLE[stack.last.last][production[0]]
|
54
|
-
stack.push([value, goto.last])
|
55
|
-
when :state
|
56
|
-
stack.push([input.shift, action.last])
|
57
|
-
else
|
58
|
-
raise
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
last
|
63
|
-
end
|