Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
588 lines (508 sloc) 14.5 KB
#
# DO NOT MODIFY!!!!
# This file is automatically generated by Racc 1.4.6
# from Racc grammer file "".
#
require 'racc/parser.rb'
require "lexer"
require "nodes"
class Parser < Racc::Parser
module_eval(<<'...end grammar.y/module_eval...', 'grammar.y', 170)
def parse(code, show_tokens=false)
@tokens = Lexer.new.tokenize(code)
puts @tokens.inspect if show_tokens
do_parse
end
def next_token
@tokens.shift
end
...end grammar.y/module_eval...
##### State transition tables begin ###
racc_action_table = [
-5, 40, 6, 65, 10, 12, -5, 15, 17, 19,
21, 1, 4, 7, 53, 71, -5, 26, 57, 72,
37, 49, 52, 41, -1, 8, 6, 25, 10, 12,
-5, 15, 17, 19, 21, 1, 4, 7, 27, 73,
49, 70, 62, 52, 28, 6, 42, 10, 12, 8,
15, 17, 19, 21, 1, 4, 7, 47, 31, 32,
33, 34, 35, 49, 6, 30, 10, 12, 8, 15,
17, 19, 21, 1, 4, 7, 49, 31, 32, 33,
34, 35, 75, 6, 30, 10, 12, 8, 15, 17,
19, 21, 1, 4, 7, 56, 31, 32, 33, 34,
35, nil, 6, 30, 10, 12, 8, 15, 17, 19,
21, 1, 4, 7, nil, 31, 32, 33, 34, 35,
nil, 6, 30, 10, 12, 8, 15, 17, 19, 21,
1, 4, 7, nil, 31, 32, 33, 34, 35, nil,
6, 30, 10, 12, 8, 15, 17, 19, 21, 1,
4, 7, 51, 52, nil, nil, nil, nil, nil, 6,
nil, 10, 12, 8, 15, 17, 19, 21, 1, 4,
7, nil, nil, nil, nil, nil, nil, nil, 6, nil,
10, 12, 8, 15, 17, 19, 21, 1, 4, 7,
nil, nil, nil, nil, nil, nil, nil, 6, nil, 10,
12, 8, 15, 17, 19, 21, 1, 4, 7, 26,
nil, 26, nil, nil, nil, nil, nil, nil, 26, 25,
8, 25, 31, 32, 33, 34, 35, 26, 25, 30,
nil, nil, nil, 26, 60, nil, nil, 25, 31, 32,
33, 34, 35, 25, 26, 30, 31, 32, 33, 34,
35, nil, nil, 30, 25, nil, nil, nil, 49 ]
racc_action_check = [
24, 10, 24, 53, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 40, 66, 24, 63, 44, 66,
7, 40, 44, 12, 0, 24, 0, 63, 0, 0,
24, 0, 0, 0, 0, 0, 0, 0, 4, 68,
62, 63, 48, 68, 4, 8, 23, 8, 8, 0,
8, 8, 8, 8, 8, 8, 8, 30, 50, 50,
50, 50, 50, 41, 6, 50, 6, 6, 8, 6,
6, 6, 6, 6, 6, 6, 71, 5, 5, 5,
5, 5, 72, 28, 5, 28, 28, 6, 28, 28,
28, 28, 28, 28, 28, 42, 43, 43, 43, 43,
43, nil, 60, 43, 60, 60, 28, 60, 60, 60,
60, 60, 60, 60, nil, 64, 64, 64, 64, 64,
nil, 52, 64, 52, 52, 60, 52, 52, 52, 52,
52, 52, 52, nil, 38, 38, 38, 38, 38, nil,
27, 38, 27, 27, 52, 27, 27, 27, 27, 27,
27, 27, 39, 39, nil, nil, nil, nil, nil, 29,
nil, 29, 29, 27, 29, 29, 29, 29, 29, 29,
29, nil, nil, nil, nil, nil, nil, nil, 37, nil,
37, 37, 29, 37, 37, 37, 37, 37, 37, 37,
nil, nil, nil, nil, nil, nil, nil, 49, nil, 49,
49, 37, 49, 49, 49, 49, 49, 49, 49, 3,
nil, 46, nil, nil, nil, nil, nil, nil, 47, 3,
49, 46, 46, 46, 46, 46, 46, 45, 47, 46,
nil, nil, nil, 57, 47, nil, nil, 45, 45, 45,
45, 45, 45, 57, 73, 45, 36, 36, 36, 36,
36, nil, nil, 36, 73, nil, nil, nil, 36 ]
racc_action_pointer = [
24, nil, nil, 203, 16, 60, 62, -8, 43, nil,
-11, nil, 10, nil, nil, nil, nil, nil, nil, nil,
nil, nil, nil, 46, 0, nil, nil, 138, 81, 157,
45, nil, nil, nil, nil, nil, 229, 176, 117, 126,
-8, 34, 95, 79, -5, 221, 205, 212, 39, 195,
41, nil, 119, -9, nil, nil, nil, 227, nil, nil,
100, nil, 11, 11, 98, nil, -8, nil, 16, nil,
nil, 47, 70, 238, nil, nil, nil ]
racc_action_default = [
-36, -21, -14, -2, -27, -3, -36, -41, -36, -6,
-54, -7, -54, -8, -9, -17, -10, -18, -11, -19,
-12, -20, -13, -54, -36, -16, -15, -36, -36, -36,
-54, -22, -23, -24, -25, -26, -54, -36, -39, -54,
-54, -54, -54, -4, -54, -42, -31, -29, -52, -36,
-44, -37, -36, -47, -45, -50, 77, -28, -43, -35,
-36, -33, -54, -54, -40, -48, -54, -32, -54, -51,
-53, -54, -54, -30, -46, -49, -34 ]
racc_goto_table = [
39, 5, 3, 23, 66, 48, nil, 36, nil, 54,
55, 58, 59, 61, nil, nil, nil, nil, nil, 44,
nil, nil, nil, 67, nil, 43, nil, nil, nil, 45,
46, 69, nil, nil, nil, nil, nil, nil, 50, 76,
74, nil, nil, nil, nil, nil, nil, nil, nil, nil,
5, 63, 68, 64 ]
racc_goto_check = [
15, 3, 2, 1, 17, 16, nil, 3, nil, 16,
16, 4, 4, 4, nil, nil, nil, nil, nil, 15,
nil, nil, nil, 4, nil, 3, nil, nil, nil, 3,
3, 16, nil, nil, nil, nil, nil, nil, 3, 4,
16, nil, nil, nil, nil, nil, nil, nil, nil, nil,
3, 2, 15, 3 ]
racc_goto_pointer = [
nil, 3, 2, 1, -34, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil, -8, -31, -49 ]
racc_goto_default = [
nil, nil, nil, 38, 24, 9, 11, 13, 14, 16,
18, 20, 22, 2, 29, nil, nil, nil ]
racc_reduce_table = [
0, 0, :racc_error,
0, 32, :_reduce_1,
1, 32, :_reduce_2,
1, 33, :_reduce_3,
3, 33, :_reduce_4,
2, 33, :_reduce_5,
1, 34, :_reduce_none,
1, 34, :_reduce_none,
1, 34, :_reduce_none,
1, 34, :_reduce_none,
1, 34, :_reduce_none,
1, 34, :_reduce_none,
1, 34, :_reduce_none,
1, 34, :_reduce_none,
1, 34, :_reduce_none,
1, 35, :_reduce_none,
1, 35, :_reduce_none,
1, 36, :_reduce_17,
1, 36, :_reduce_18,
1, 36, :_reduce_19,
1, 36, :_reduce_20,
1, 36, :_reduce_21,
1, 45, :_reduce_none,
1, 45, :_reduce_none,
1, 45, :_reduce_none,
1, 45, :_reduce_none,
1, 45, :_reduce_none,
1, 38, :_reduce_27,
4, 37, :_reduce_28,
3, 37, :_reduce_29,
6, 37, :_reduce_30,
3, 37, :_reduce_31,
5, 37, :_reduce_32,
4, 37, :_reduce_33,
7, 37, :_reduce_34,
4, 37, :_reduce_35,
0, 44, :_reduce_none,
3, 44, :_reduce_37,
0, 46, :_reduce_38,
1, 46, :_reduce_39,
3, 46, :_reduce_40,
1, 39, :_reduce_41,
3, 40, :_reduce_42,
4, 40, :_reduce_43,
3, 40, :_reduce_44,
3, 41, :_reduce_45,
6, 41, :_reduce_46,
0, 48, :_reduce_47,
1, 48, :_reduce_48,
3, 48, :_reduce_49,
3, 42, :_reduce_50,
5, 43, :_reduce_51,
3, 43, :_reduce_52,
3, 47, :_reduce_53 ]
racc_reduce_n = 54
racc_shift_n = 77
racc_token_table = {
false => 0,
:error => 1,
:IF => 2,
:ELSE => 3,
:DEF => 4,
:CLASS => 5,
:NEWLINE => 6,
:NUMBER => 7,
:STRING => 8,
:TRUE => 9,
:FALSE => 10,
:NIL => 11,
:IDENTIFIER => 12,
:CONSTANT => 13,
:INDENT => 14,
:DEDENT => 15,
";" => 16,
"+" => 17,
"-" => 18,
"*" => 19,
"/" => 20,
"%" => 21,
"(" => 22,
")" => 23,
"." => 24,
"[" => 25,
"]" => 26,
"," => 27,
"=" => 28,
"{" => 29,
"}" => 30 }
racc_nt_base = 31
racc_use_result_var = true
Racc_arg = [
racc_action_table,
racc_action_check,
racc_action_default,
racc_action_pointer,
racc_goto_table,
racc_goto_check,
racc_goto_default,
racc_goto_pointer,
racc_nt_base,
racc_reduce_table,
racc_token_table,
racc_shift_n,
racc_reduce_n,
racc_use_result_var ]
Racc_token_to_s_table = [
"$end",
"error",
"IF",
"ELSE",
"DEF",
"CLASS",
"NEWLINE",
"NUMBER",
"STRING",
"TRUE",
"FALSE",
"NIL",
"IDENTIFIER",
"CONSTANT",
"INDENT",
"DEDENT",
"\";\"",
"\"+\"",
"\"-\"",
"\"*\"",
"\"/\"",
"\"%\"",
"\"(\"",
"\")\"",
"\".\"",
"\"[\"",
"\"]\"",
"\",\"",
"\"=\"",
"\"{\"",
"\"}\"",
"$start",
"Root",
"Expressions",
"Expression",
"Terminator",
"Literal",
"Call",
"Var",
"Constant",
"Assign",
"Def",
"Class",
"If",
"Array",
"BinaryOperator",
"ArgList",
"Block",
"ParamList" ]
Racc_debug_parser = false
##### State transition tables end #####
# reduce 0 omitted
module_eval(<<'.,.,', 'grammar.y', 33)
def _reduce_1(val, _values, result)
result = Nodes.new([])
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 34)
def _reduce_2(val, _values, result)
result = val[0]
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 39)
def _reduce_3(val, _values, result)
result = Nodes.new(val)
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 40)
def _reduce_4(val, _values, result)
result = val[0] << val[2]
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 42)
def _reduce_5(val, _values, result)
result = Nodes.new([val[0]])
result
end
.,.,
# reduce 6 omitted
# reduce 7 omitted
# reduce 8 omitted
# reduce 9 omitted
# reduce 10 omitted
# reduce 11 omitted
# reduce 12 omitted
# reduce 13 omitted
# reduce 14 omitted
# reduce 15 omitted
# reduce 16 omitted
module_eval(<<'.,.,', 'grammar.y', 65)
def _reduce_17(val, _values, result)
result = LiteralNode.new(val[0])
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 66)
def _reduce_18(val, _values, result)
result = LiteralNode.new(val[0])
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 67)
def _reduce_19(val, _values, result)
result = LiteralNode.new(true)
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 68)
def _reduce_20(val, _values, result)
result = LiteralNode.new(false)
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 69)
def _reduce_21(val, _values, result)
result = LiteralNode.new(nil)
result
end
.,.,
# reduce 22 omitted
# reduce 23 omitted
# reduce 24 omitted
# reduce 25 omitted
# reduce 26 omitted
module_eval(<<'.,.,', 'grammar.y', 83)
def _reduce_27(val, _values, result)
result = VarNode.new(val[0])
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 89)
def _reduce_28(val, _values, result)
result = CallNode.new(nil, val[0], val[2], false)
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 91)
def _reduce_29(val, _values, result)
result = CallNode.new(val[0], val[2], false)
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 94)
def _reduce_30(val, _values, result)
result = CallNode.new(val[0], val[2], val[4], false)
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 95)
def _reduce_31(val, _values, result)
result = CallNode.new(val[0], val[1], [val[2]], false)
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 97)
def _reduce_32(val, _values, result)
result = CallNode.new(nil, val[0], val[2], true)
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 99)
def _reduce_33(val, _values, result)
result = CallNode.new(val[0], val[2], nil, true)
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 102)
def _reduce_34(val, _values, result)
result = CallNode.new(val[0], val[2], val[4], true)
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 103)
def _reduce_35(val, _values, result)
result = CallNode.new(val[0], val[1], [val[2]], true)
result
end
.,.,
# reduce 36 omitted
module_eval(<<'.,.,', 'grammar.y', 107)
def _reduce_37(val, _values, result)
result = ArrayNode.new(val[1])
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 111)
def _reduce_38(val, _values, result)
result = []
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 112)
def _reduce_39(val, _values, result)
result = val
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 113)
def _reduce_40(val, _values, result)
result = val[0] << val[2]
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 117)
def _reduce_41(val, _values, result)
result = GetConstantNode.new(val[0])
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 122)
def _reduce_42(val, _values, result)
result = SetLocalNode.new(val[0], val[2], false)
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 123)
def _reduce_43(val, _values, result)
result = SetLocalNode.new(val[0], val[2], true)
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 124)
def _reduce_44(val, _values, result)
result = SetConstantNode.new(val[0], val[2])
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 130)
def _reduce_45(val, _values, result)
result = DefNode.new(val[1], [], val[2])
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 132)
def _reduce_46(val, _values, result)
result = DefNode.new(val[1], val[3], val[5])
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 136)
def _reduce_47(val, _values, result)
result = []
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 137)
def _reduce_48(val, _values, result)
result = val
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 138)
def _reduce_49(val, _values, result)
result = val[0] << val[2]
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 143)
def _reduce_50(val, _values, result)
result = ClassNode.new(val[1], val[2])
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 149)
def _reduce_51(val, _values, result)
result = IfNode.new(val[1], val[2], val[4])
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 150)
def _reduce_52(val, _values, result)
result = IfNode.new(val[1], val[2])
result
end
.,.,
module_eval(<<'.,.,', 'grammar.y', 160)
def _reduce_53(val, _values, result)
result = val[1]
result
end
.,.,
def _reduce_none(val, _values, result)
val[0]
end
end # class Parser