qoobaa-lol 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,15 @@
1
+ = LOL
2
+
3
+ LOL is a simple LOLCODE interpreter written in Ruby, using Racc and StringScanner.
4
+
5
+ == Usage
6
+
7
+ To execute program hello.lol type:
8
+ lol hello.lol
9
+
10
+ To show the abstract syntax tree of program type:
11
+ lol -t hello.lol
12
+
13
+ = License
14
+
15
+ Copyright (c) 2009 Jakub Kuźma, released under the MIT license
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 0
data/bin/lol ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ gem "lol"
5
+ require "lol"
6
+
7
+ if ARGV[0] == "-t"
8
+ Parser.new.parse_and_print(open(ARGV[1]).read)
9
+ elsif ARGV[0].nil?
10
+ puts "no file given"
11
+ else
12
+ Parser.new.parse_and_execute(open(ARGV[0]).read)
13
+ end
@@ -0,0 +1,4 @@
1
+ HAI
2
+ CAN HAS STDIO?
3
+ VISIBLE "HAI WORLD!"
4
+ KTHXBYE
@@ -0,0 +1,16 @@
1
+ HAI
2
+ CAN HAS STDIO?
3
+ I HAS A VAR
4
+ VISIBLE "CAN HAS NUMBAR? "!
5
+ GIMMEH VAR
6
+ VISIBLE "U SEIZ "!
7
+ VISIBLE VAR
8
+ IZ VAR BIGR THAN 10?
9
+ YARLY
10
+ BTW this is true
11
+ VISIBLE "BIG NUMBAR!!"
12
+ NOWAI
13
+ BTW this is false
14
+ VISIBLE "LITTL NUMBAR!!"
15
+ KTHX
16
+ KTHXBYE
@@ -0,0 +1,29 @@
1
+ HAI
2
+ CAN HAS STDIO?
3
+ I HAS A VAR ITZ 3
4
+ GIMMEH YARN
5
+ VISIBLE VAR
6
+ VISIBLE YARN
7
+ LOL VAR R 1
8
+ LOL YARN R "HAI"
9
+ VISIBLE YARN
10
+ IM IN YR LOOP
11
+ UPZ VAR!!
12
+ VISIBLE "I M THIS MENNY YRS OLD: "!
13
+ VISIBLE VAR
14
+ I HAS A KITTENZ
15
+ IM IN YR LOOP
16
+ UPZ KITTENZ!!1
17
+ VISIBLE "I HASD THIS MENNY KITTENZ THIS YR: "!
18
+ VISIBLE KITTENZ
19
+ IZ KITTENZ BIGR THAN 5?
20
+ YARLY
21
+ GTFO
22
+ NOWAI
23
+ VISIBLE "STILL POPPEN EM OUT!!!"
24
+ KTHX
25
+ KTHX
26
+ IZ VAR LIEK 5? GTFO KTHX
27
+ KTHX
28
+ DIAF 1 "BAI"
29
+ KTHXBYE
data/lib/lol.rb ADDED
@@ -0,0 +1,81 @@
1
+ require "lol/lexer"
2
+ require "lol/parser.tab"
3
+
4
+ class Lol
5
+ def initialize(tree)
6
+ @tree = tree
7
+ @variables = { }
8
+ end
9
+
10
+ def execute
11
+ execute_statement_list(@tree)
12
+ end
13
+
14
+ protected
15
+
16
+ def execute_statement_list(statement_list)
17
+ statement_list.each { |statement| execute_statement(statement) }
18
+ end
19
+
20
+ def execute_statement(statement)
21
+ return if statement.nil?
22
+ case statement[0]
23
+ when :print
24
+ STDOUT.print evaluate_expression(statement[1])
25
+ when :declare
26
+ define_variable(statement[1])
27
+ when :printline
28
+ STDOUT.puts evaluate_expression(statement[1])
29
+ when :define
30
+ define_variable(statement[1], evaluate_expression(statement[2]))
31
+ when :getline
32
+ define_variable(statement[1], STDIN.gets.chomp)
33
+ when :getword
34
+ define_variable(statement[1], STDIN.gets.scan(/\w+/)[0] || "")
35
+ when :getchar
36
+ define_variable(statement[1], STDIN.gets.scan(/\w/)[0] || "")
37
+ when :assign
38
+ define_variable(statement[1], evaluate_expression(statement[2]))
39
+ when :if
40
+ if evaluate_expression(statement[1]) == 0
41
+ execute_statement_list(statement[3]) if statement[3]
42
+ else
43
+ execute_statement_list(statement[2])
44
+ end
45
+ when :break
46
+ throw :break
47
+ when :loop
48
+ catch :break do
49
+ loop { execute_statement_list(statement[1]) }
50
+ end
51
+ when :"/=", :"*=", :"+=", :"-="
52
+ var = get_variable(statement[1])
53
+ var = var.send(statement[0].to_s[0].chr, evaluate_expression(statement[2]))
54
+ define_variable(statement[1], var)
55
+ when :exit
56
+ puts statement[2] if statement[2]
57
+ exit(statement[1].to_i)
58
+ end
59
+ end
60
+
61
+ def evaluate_expression(expression)
62
+ return expression unless expression.kind_of? Array
63
+ case expression[0]
64
+ when :var
65
+ get_variable(expression[1])
66
+ else
67
+ result = evaluate_expression(expression[1]).to_i.send(expression[0], evaluate_expression(expression[2]).to_i)
68
+ result = 0 if result == false
69
+ result = 1 if result == true
70
+ result
71
+ end
72
+ end
73
+
74
+ def get_variable(name)
75
+ @variables[name.to_sym] or raise "undeclared identifier #{name}"
76
+ end
77
+
78
+ def define_variable(name, value = 0)
79
+ @variables[name.to_sym] = value
80
+ end
81
+ end
data/lib/lol/lexer.rb ADDED
@@ -0,0 +1,34 @@
1
+ require "strscan"
2
+
3
+ class Lexer < StringScanner
4
+ KEYWORDS = ["SMALR THAN", "BIGR THAN", "NOT SMALR THAN", "NOT BIGR THAN",
5
+ "LIEK", "NOT LIEK", "IZ", "NOWAI", "YARLY", "VISIBLE",
6
+ "KTHXBYE", "BYES", "DIAF", "GTFO", "HAI", "CAN HAS STDIO",
7
+ "IM IN YR LOOP", "KTHX", "UPZ", "NERFZ", "TIEMZD", "OVARZ",
8
+ "I HAS A", "ITZ", "UP", "NERF", "TIEMZ", "OVAR", "LOL", "R",
9
+ "LINE", "WORD", "LETTAR", "GIMMEH", "OUTTA"].freeze
10
+
11
+ def next_token
12
+ until eos? do
13
+ case
14
+ when scan(/BTW /)
15
+ skip_until(/\n/)
16
+ when scan(/\d+/)
17
+ return [:NUMBAR, matched.to_i]
18
+ when scan(/"[^"]*"/)
19
+ return [:YARN, matched[1..-2]]
20
+ when scan(Regexp.new(KEYWORDS.join("|")))
21
+ return [matched.gsub(/ /, "_").to_sym, nil]
22
+ when scan(/[A-Z]+/)
23
+ return [:VARIABLE, matched]
24
+ when scan(/\?|\!/)
25
+ return [matched, nil]
26
+ when scan(/\n+/)
27
+ return [:EOS, nil]
28
+ else
29
+ getch
30
+ end
31
+ end
32
+ [false, false]
33
+ end
34
+ end
data/lib/lol/parser.ry ADDED
@@ -0,0 +1,93 @@
1
+ class Parser
2
+ token SMALR_THAN BIGR_THAN NOT_SMALR_THAN NOT_BIGR_THAN LIEK NOT_LIEK IZ NOWAI YARLY VISIBLE KTHXBYE BYES DIAF GTFO HAI CAN_HAS_STDIO IM_IN_YR_LOOP KTHX UPZ NERFZ TIEMZD OVARZ I_HAS_A ITZ NERF TIEMZ OVAR LOL R LINE WORD LETTAR GIMMEH OUTTA VARIABLE NUMBAR YARN UP EOS
3
+
4
+ prechigh
5
+ left TIEMZ OVAR
6
+ left UP NERF
7
+ left BIGR_THAN SMALR_THAN NOT_SMALR_THAN NOT_BIGR_THAN NOT_LIEK LIEK
8
+ preclow
9
+
10
+ rule
11
+
12
+ program
13
+ : HAI EOS statement_list EOS KTHXBYE EOS { @tree = val[2] }
14
+ ;
15
+
16
+ statement_list
17
+ : statement_list EOS statement { result = val[2] ? val[0] + [val[2]] : val[0] }
18
+ | statement { result = [val[0]] }
19
+ ;
20
+
21
+ statement
22
+ : expression
23
+ | VISIBLE expression '!' { result = [:print, val[1]] }
24
+ | VISIBLE expression { result = [:printline, val[1]] }
25
+ | LOL VARIABLE R expression { result = [:assign, val[1], val[3]] }
26
+ | IZ expression optional_question_mark statement KTHX { result = [:if, val[1], [val[3]]] }
27
+ | IZ expression optional_question_mark EOS YARLY EOS statement_list EOS KTHX { result = [:if, val[1], val[6]] }
28
+ | IZ expression optional_question_mark EOS YARLY EOS statement_list EOS NOWAI EOS statement_list EOS KTHX { result = [:if, val[1], val[6], val[10]] }
29
+ | CAN_HAS_STDIO '?' { result = [:stdio] }
30
+ | GTFO { result = [:break] }
31
+ | IM_IN_YR_LOOP EOS statement_list EOS KTHX { result = [:loop, val[2]] }
32
+ | UPZ VARIABLE '!' '!' { result = [:"+=", val[1], 1] }
33
+ | UPZ VARIABLE '!' '!' expression { result = [:"+=", val[1], val[4]] }
34
+ | NERFZ VARIABLE '!' '!' { result = [:"-=", val[1], 1] }
35
+ | NERFZ VARIABLE '!' '!' expression { result = [:"-=", val[1], val[4]] }
36
+ | OVARZ VARIABLE '!' '!' { result = [:"/=", val[1], 1] }
37
+ | OVARZ VARIABLE '!' '!' expression { result = [:"/=", val[1], val[4]] }
38
+ | TIEMZD VARIABLE '!' '!' { result = [:"*=", val[1], 1] }
39
+ | TIEMZD VARIABLE '!' '!' expression { result = [:"*=", val[1], val[4]] }
40
+ | I_HAS_A VARIABLE ITZ expression { result = [:define, val[1], val[3]] }
41
+ | I_HAS_A VARIABLE { result = [:declare, val[1]] }
42
+ | GIMMEH VARIABLE { result = [:getline, val[1]] }
43
+ | GIMMEH LINE VARIABLE { result = [:getline, val[2]] }
44
+ | GIMMEH LETTAR VARIABLE { result = [:getchar, val[2]] }
45
+ | GIMMEH WORD VARIABLE { result = [:getword, val[2]] }
46
+ | DIAF { result = [:exit, 0] }
47
+ | DIAF NUMBAR { result = [:exit, val[1]] }
48
+ | DIAF NUMBAR YARN { result = [:exit, val[1], val[2]] }
49
+ ;
50
+
51
+ expression
52
+ : NUMBAR
53
+ | VARIABLE { result = [:var, val[0]] }
54
+ | YARN
55
+ | expression UP expression { result = [:"+", val[0], val[2]] }
56
+ | expression NERF expression { result = [:"-", val[0], val[2]] }
57
+ | expression TIEMZ expression { result = [:"*", val[0], val[2]] }
58
+ | expression OVAR expression { result = [:"/", val[0], val[2]] }
59
+ | expression BIGR_THAN expression { result = [:">", val[0], val[2]] }
60
+ | expression SMALR_THAN expression { result = [:"<", val[0], val[2]] }
61
+ | expression NOT_SMALR_THAN expression { result = [:">=", val[0], val[2]] }
62
+ | expression NOT_BIGR_THAN expression { result = [:"<=", val[0], val[2]] }
63
+ | expression NOT_LIEK expression { result = [:"!=", val[0], val[2]] }
64
+ | expression LIEK expression { result = [:"==", val[0], val[2]] }
65
+ ;
66
+
67
+ optional_question_mark
68
+ : '?'
69
+ |
70
+ ;
71
+
72
+ end
73
+
74
+ ---- inner
75
+ def parse(src)
76
+ @lexer = Lexer.new(src)
77
+ @yydebug = true
78
+ do_parse
79
+ end
80
+
81
+ def parse_and_execute(src)
82
+ parse(src)
83
+ Lol.new(@tree).execute
84
+ end
85
+
86
+ def parse_and_print(src)
87
+ parse(src)
88
+ p @tree
89
+ end
90
+
91
+ def next_token
92
+ @lexer.next_token
93
+ end
@@ -0,0 +1,650 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by racc 1.4.5
4
+ # from racc grammer file "parser.ry".
5
+ #
6
+
7
+ require 'racc/parser'
8
+
9
+
10
+ class Parser < Racc::Parser
11
+
12
+ module_eval <<'..end parser.ry modeval..id173dda2250', 'parser.ry', 75
13
+ def parse(src)
14
+ @lexer = Lexer.new(src)
15
+ @yydebug = true
16
+ do_parse
17
+ end
18
+
19
+ def parse_and_execute(src)
20
+ parse(src)
21
+ Lol.new(@tree).execute
22
+ end
23
+
24
+ def parse_and_print(src)
25
+ parse(src)
26
+ p @tree
27
+ end
28
+
29
+ def next_token
30
+ @lexer.next_token
31
+ end
32
+ ..end parser.ry modeval..id173dda2250
33
+
34
+ ##### racc 1.4.5 generates ###
35
+
36
+ racc_reduce_table = [
37
+ 0, 0, :racc_error,
38
+ 6, 44, :_reduce_1,
39
+ 3, 45, :_reduce_2,
40
+ 1, 45, :_reduce_3,
41
+ 1, 46, :_reduce_none,
42
+ 3, 46, :_reduce_5,
43
+ 2, 46, :_reduce_6,
44
+ 4, 46, :_reduce_7,
45
+ 5, 46, :_reduce_8,
46
+ 9, 46, :_reduce_9,
47
+ 13, 46, :_reduce_10,
48
+ 2, 46, :_reduce_11,
49
+ 1, 46, :_reduce_12,
50
+ 5, 46, :_reduce_13,
51
+ 4, 46, :_reduce_14,
52
+ 5, 46, :_reduce_15,
53
+ 4, 46, :_reduce_16,
54
+ 5, 46, :_reduce_17,
55
+ 4, 46, :_reduce_18,
56
+ 5, 46, :_reduce_19,
57
+ 4, 46, :_reduce_20,
58
+ 5, 46, :_reduce_21,
59
+ 4, 46, :_reduce_22,
60
+ 2, 46, :_reduce_23,
61
+ 2, 46, :_reduce_24,
62
+ 3, 46, :_reduce_25,
63
+ 3, 46, :_reduce_26,
64
+ 3, 46, :_reduce_27,
65
+ 1, 46, :_reduce_28,
66
+ 2, 46, :_reduce_29,
67
+ 3, 46, :_reduce_30,
68
+ 1, 47, :_reduce_none,
69
+ 1, 47, :_reduce_32,
70
+ 1, 47, :_reduce_none,
71
+ 3, 47, :_reduce_34,
72
+ 3, 47, :_reduce_35,
73
+ 3, 47, :_reduce_36,
74
+ 3, 47, :_reduce_37,
75
+ 3, 47, :_reduce_38,
76
+ 3, 47, :_reduce_39,
77
+ 3, 47, :_reduce_40,
78
+ 3, 47, :_reduce_41,
79
+ 3, 47, :_reduce_42,
80
+ 3, 47, :_reduce_43,
81
+ 1, 48, :_reduce_none,
82
+ 0, 48, :_reduce_none ]
83
+
84
+ racc_reduce_n = 46
85
+
86
+ racc_shift_n = 103
87
+
88
+ racc_action_table = [
89
+ 35, 36, 37, 39, 41, 44, 35, 36, 37, 39,
90
+ 41, 44, 40, 42, 38, 40, 42, 13, 16, 18,
91
+ 38, 40, 42, 50, 38, 40, 42, 43, 40, 42,
92
+ 38, 40, 42, 43, 29, 30, 27, 43, 78, 28,
93
+ 74, 77, 76, 43, 75, 52, 35, 36, 37, 39,
94
+ 41, 44, 35, 36, 37, 39, 41, 44, 46, 72,
95
+ 35, 36, 37, 39, 41, 44, 38, 40, 42, 47,
96
+ 38, 40, 42, 13, 16, 18, 38, 40, 42, 43,
97
+ 13, 16, 18, 43, 38, 40, 42, 79, 60, 43,
98
+ 35, 36, 37, 39, 41, 44, 81, 43, 35, 36,
99
+ 37, 39, 41, 44, 35, 36, 37, 39, 41, 44,
100
+ 13, 16, 18, 59, 38, 40, 42, 45, 38, 40,
101
+ 42, 85, 38, 40, 42, 86, 56, 43, 38, 40,
102
+ 42, 43, 13, 16, 18, 43, 38, 40, 42, 55,
103
+ 34, 43, 35, 36, 37, 39, 41, 44, 22, 43,
104
+ 33, 7, 32, 90, 14, 17, 91, 19, 20, 54,
105
+ 23, 24, 6, 9, 11, 53, 38, 40, 42, 21,
106
+ 38, 40, 42, 31, 8, 49, 13, 16, 18, 43,
107
+ 84, 22, 94, 43, 7, 51, 25, 14, 17, 5,
108
+ 19, 20, 96, 23, 24, 6, 9, 11, 13, 16,
109
+ 18, 4, 21, 13, 16, 18, 99, 8, 3, 13,
110
+ 16, 18, 22, 101, 2, 7, nil, nil, 14, 17,
111
+ nil, 19, 20, nil, 23, 24, 6, 9, 11, 13,
112
+ 16, 18, nil, 21, 13, 16, 18, nil, 8, nil,
113
+ 13, 16, 18, 22, 98, nil, 7, nil, nil, 14,
114
+ 17, nil, 19, 20, 97, 23, 24, 6, 9, 11,
115
+ 13, 16, 18, nil, 21, 13, 16, 18, nil, 8,
116
+ nil, 13, 16, 18, 22, nil, nil, 7, nil, nil,
117
+ 14, 17, nil, 19, 20, 89, 23, 24, 6, 9,
118
+ 11, 13, 16, 18, nil, 21, 13, 16, 18, nil,
119
+ 8, nil, 13, 16, 18, 22, nil, nil, 7, nil,
120
+ nil, 14, 17, nil, 19, 20, nil, 23, 24, 6,
121
+ 9, 11, 13, 16, 18, nil, 21, 13, 16, 18,
122
+ nil, 8, nil, 13, 16, 18, 22, nil, nil, 7,
123
+ nil, nil, 14, 17, nil, 19, 20, nil, 23, 24,
124
+ 6, 9, 11, 13, 16, 18, nil, 21, 13, 16,
125
+ 18, nil, 8, nil, 13, 16, 18, 22, nil, nil,
126
+ 7, 57, nil, 14, 17, nil, 19, 20, nil, 23,
127
+ 24, 6, 9, 11, 13, 16, 18, nil, 21, nil,
128
+ nil, nil, nil, 8, nil, 13, 16, 18, 22, nil,
129
+ nil, 7, nil, nil, 14, 17, nil, 19, 20, 102,
130
+ 23, 24, 6, 9, 11, nil, nil, nil, nil, 21,
131
+ nil, nil, nil, nil, 8, nil, 13, 16, 18 ]
132
+
133
+ racc_action_check = [
134
+ 48, 48, 48, 48, 48, 48, 26, 26, 26, 26,
135
+ 26, 26, 64, 64, 70, 70, 70, 38, 38, 38,
136
+ 61, 61, 61, 24, 48, 48, 48, 70, 69, 69,
137
+ 26, 26, 26, 61, 8, 8, 8, 48, 56, 8,
138
+ 48, 51, 50, 26, 49, 26, 82, 82, 82, 82,
139
+ 82, 82, 80, 80, 80, 80, 80, 80, 20, 47,
140
+ 15, 15, 15, 15, 15, 15, 62, 62, 62, 21,
141
+ 82, 82, 82, 72, 72, 72, 80, 80, 80, 62,
142
+ 77, 77, 77, 82, 15, 15, 15, 57, 34, 80,
143
+ 93, 93, 93, 93, 93, 93, 71, 15, 92, 92,
144
+ 92, 92, 92, 92, 88, 88, 88, 88, 88, 88,
145
+ 35, 35, 35, 33, 93, 93, 93, 19, 67, 67,
146
+ 67, 75, 92, 92, 92, 76, 31, 93, 88, 88,
147
+ 88, 67, 36, 36, 36, 92, 65, 65, 65, 30,
148
+ 14, 88, 87, 87, 87, 87, 87, 87, 73, 65,
149
+ 11, 73, 10, 83, 73, 73, 84, 73, 73, 29,
150
+ 73, 73, 73, 73, 73, 27, 87, 87, 87, 73,
151
+ 63, 63, 63, 9, 73, 23, 73, 73, 73, 87,
152
+ 73, 4, 91, 63, 4, 25, 6, 4, 4, 3,
153
+ 4, 4, 95, 4, 4, 4, 4, 4, 37, 37,
154
+ 37, 2, 4, 22, 22, 22, 98, 4, 1, 4,
155
+ 4, 4, 94, 100, 0, 94, nil, nil, 94, 94,
156
+ nil, 94, 94, nil, 94, 94, 94, 94, 94, 39,
157
+ 39, 39, nil, 94, 59, 59, 59, nil, 94, nil,
158
+ 94, 94, 94, 96, 96, nil, 96, nil, nil, 96,
159
+ 96, nil, 96, 96, 96, 96, 96, 96, 96, 96,
160
+ 41, 41, 41, nil, 96, 40, 40, 40, nil, 96,
161
+ nil, 96, 96, 96, 81, nil, nil, 81, nil, nil,
162
+ 81, 81, nil, 81, 81, 81, 81, 81, 81, 81,
163
+ 81, 43, 43, 43, nil, 81, 44, 44, 44, nil,
164
+ 81, nil, 81, 81, 81, 99, nil, nil, 99, nil,
165
+ nil, 99, 99, nil, 99, 99, nil, 99, 99, 99,
166
+ 99, 99, 78, 78, 78, nil, 99, 85, 85, 85,
167
+ nil, 99, nil, 99, 99, 99, 46, nil, nil, 46,
168
+ nil, nil, 46, 46, nil, 46, 46, nil, 46, 46,
169
+ 46, 46, 46, 7, 7, 7, nil, 46, 86, 86,
170
+ 86, nil, 46, nil, 46, 46, 46, 32, nil, nil,
171
+ 32, 32, nil, 32, 32, nil, 32, 32, nil, 32,
172
+ 32, 32, 32, 32, 42, 42, 42, nil, 32, nil,
173
+ nil, nil, nil, 32, nil, 32, 32, 32, 101, nil,
174
+ nil, 101, nil, nil, 101, 101, nil, 101, 101, 101,
175
+ 101, 101, 101, 101, 101, nil, nil, nil, nil, 101,
176
+ nil, nil, nil, nil, 101, nil, 101, 101, 101 ]
177
+
178
+ racc_action_pointer = [
179
+ 198, 208, 161, 189, 173, nil, 150, 317, 3, 137,
180
+ 112, 114, nil, nil, 103, 58, nil, nil, nil, 75,
181
+ 18, 33, 167, 139, -13, 144, 4, 129, nil, 123,
182
+ 103, 85, 359, 88, 50, 74, 96, 162, -19, 193,
183
+ 229, 224, 348, 255, 260, nil, 328, 29, -2, 3,
184
+ 1, 0, nil, nil, nil, nil, -3, 47, nil, 198,
185
+ nil, -6, 40, 144, -15, 110, nil, 92, nil, 1,
186
+ -12, 56, 37, 140, nil, 80, 84, 44, 286, nil,
187
+ 50, 266, 44, 134, 146, 291, 322, 140, 102, nil,
188
+ nil, 142, 96, 88, 204, 152, 235, nil, 166, 297,
189
+ 173, 390, nil ]
190
+
191
+ racc_action_default = [
192
+ -46, -46, -46, -46, -46, 103, -46, -46, -46, -46,
193
+ -46, -46, -3, -32, -28, -4, -31, -12, -33, -46,
194
+ -46, -46, -46, -46, -46, -46, -6, -46, -24, -46,
195
+ -46, -46, -46, -23, -29, -46, -46, -46, -46, -46,
196
+ -46, -46, -46, -46, -46, -11, -46, -46, -45, -46,
197
+ -46, -46, -5, -26, -25, -27, -46, -46, -2, -46,
198
+ -30, -39, -38, -40, -35, -41, -36, -43, -37, -34,
199
+ -42, -46, -46, -46, -44, -46, -46, -20, -18, -1,
200
+ -22, -46, -7, -46, -46, -14, -16, -21, -19, -13,
201
+ -8, -46, -15, -17, -46, -46, -46, -9, -46, -46,
202
+ -46, -46, -10 ]
203
+
204
+ racc_goto_table = [
205
+ 10, 26, 1, 73, nil, 58, nil, nil, nil, nil,
206
+ nil, nil, nil, nil, nil, nil, 48, nil, nil, nil,
207
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, 61,
208
+ 62, 63, 64, 65, 66, 67, 68, 69, 70, nil,
209
+ nil, nil, 71, nil, nil, nil, 83, nil, nil, nil,
210
+ nil, nil, nil, 80, 58, nil, nil, nil, nil, nil,
211
+ nil, nil, nil, nil, nil, nil, 82, nil, nil, 58,
212
+ nil, 87, 88, nil, 58, nil, nil, nil, nil, 92,
213
+ 93, nil, nil, nil, nil, nil, nil, nil, nil, nil,
214
+ 95, nil, nil, nil, nil, 100 ]
215
+
216
+ racc_goto_check = [
217
+ 2, 4, 1, 5, nil, 3, nil, nil, nil, nil,
218
+ nil, nil, nil, nil, nil, nil, 4, nil, nil, nil,
219
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, 4,
220
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, nil,
221
+ nil, nil, 2, nil, nil, nil, 3, nil, nil, nil,
222
+ nil, nil, nil, 4, 3, nil, nil, nil, nil, nil,
223
+ nil, nil, nil, nil, nil, nil, 4, nil, nil, 3,
224
+ nil, 4, 4, nil, 3, nil, nil, nil, nil, 4,
225
+ 4, nil, nil, nil, nil, nil, nil, nil, nil, nil,
226
+ 2, nil, nil, nil, nil, 2 ]
227
+
228
+ racc_goto_pointer = [
229
+ nil, 2, -4, -27, -6, -45 ]
230
+
231
+ racc_goto_default = [
232
+ nil, nil, nil, 12, 15, nil ]
233
+
234
+ racc_token_table = {
235
+ false => 0,
236
+ Object.new => 1,
237
+ :SMALR_THAN => 2,
238
+ :BIGR_THAN => 3,
239
+ :NOT_SMALR_THAN => 4,
240
+ :NOT_BIGR_THAN => 5,
241
+ :LIEK => 6,
242
+ :NOT_LIEK => 7,
243
+ :IZ => 8,
244
+ :NOWAI => 9,
245
+ :YARLY => 10,
246
+ :VISIBLE => 11,
247
+ :KTHXBYE => 12,
248
+ :BYES => 13,
249
+ :DIAF => 14,
250
+ :GTFO => 15,
251
+ :HAI => 16,
252
+ :CAN_HAS_STDIO => 17,
253
+ :IM_IN_YR_LOOP => 18,
254
+ :KTHX => 19,
255
+ :UPZ => 20,
256
+ :NERFZ => 21,
257
+ :TIEMZD => 22,
258
+ :OVARZ => 23,
259
+ :I_HAS_A => 24,
260
+ :ITZ => 25,
261
+ :NERF => 26,
262
+ :TIEMZ => 27,
263
+ :OVAR => 28,
264
+ :LOL => 29,
265
+ :R => 30,
266
+ :LINE => 31,
267
+ :WORD => 32,
268
+ :LETTAR => 33,
269
+ :GIMMEH => 34,
270
+ :OUTTA => 35,
271
+ :VARIABLE => 36,
272
+ :NUMBAR => 37,
273
+ :YARN => 38,
274
+ :UP => 39,
275
+ :EOS => 40,
276
+ "!" => 41,
277
+ "?" => 42 }
278
+
279
+ racc_use_result_var = true
280
+
281
+ racc_nt_base = 43
282
+
283
+ Racc_arg = [
284
+ racc_action_table,
285
+ racc_action_check,
286
+ racc_action_default,
287
+ racc_action_pointer,
288
+ racc_goto_table,
289
+ racc_goto_check,
290
+ racc_goto_default,
291
+ racc_goto_pointer,
292
+ racc_nt_base,
293
+ racc_reduce_table,
294
+ racc_token_table,
295
+ racc_shift_n,
296
+ racc_reduce_n,
297
+ racc_use_result_var ]
298
+
299
+ Racc_token_to_s_table = [
300
+ '$end',
301
+ 'error',
302
+ 'SMALR_THAN',
303
+ 'BIGR_THAN',
304
+ 'NOT_SMALR_THAN',
305
+ 'NOT_BIGR_THAN',
306
+ 'LIEK',
307
+ 'NOT_LIEK',
308
+ 'IZ',
309
+ 'NOWAI',
310
+ 'YARLY',
311
+ 'VISIBLE',
312
+ 'KTHXBYE',
313
+ 'BYES',
314
+ 'DIAF',
315
+ 'GTFO',
316
+ 'HAI',
317
+ 'CAN_HAS_STDIO',
318
+ 'IM_IN_YR_LOOP',
319
+ 'KTHX',
320
+ 'UPZ',
321
+ 'NERFZ',
322
+ 'TIEMZD',
323
+ 'OVARZ',
324
+ 'I_HAS_A',
325
+ 'ITZ',
326
+ 'NERF',
327
+ 'TIEMZ',
328
+ 'OVAR',
329
+ 'LOL',
330
+ 'R',
331
+ 'LINE',
332
+ 'WORD',
333
+ 'LETTAR',
334
+ 'GIMMEH',
335
+ 'OUTTA',
336
+ 'VARIABLE',
337
+ 'NUMBAR',
338
+ 'YARN',
339
+ 'UP',
340
+ 'EOS',
341
+ '"!"',
342
+ '"?"',
343
+ '$start',
344
+ 'program',
345
+ 'statement_list',
346
+ 'statement',
347
+ 'expression',
348
+ 'optional_question_mark']
349
+
350
+ Racc_debug_parser = false
351
+
352
+ ##### racc system variables end #####
353
+
354
+ # reduce 0 omitted
355
+
356
+ module_eval <<'.,.,', 'parser.ry', 12
357
+ def _reduce_1( val, _values, result )
358
+ @tree = val[2]
359
+ result
360
+ end
361
+ .,.,
362
+
363
+ module_eval <<'.,.,', 'parser.ry', 16
364
+ def _reduce_2( val, _values, result )
365
+ result = val[2] ? val[0] + [val[2]] : val[0]
366
+ result
367
+ end
368
+ .,.,
369
+
370
+ module_eval <<'.,.,', 'parser.ry', 17
371
+ def _reduce_3( val, _values, result )
372
+ result = [val[0]]
373
+ result
374
+ end
375
+ .,.,
376
+
377
+ # reduce 4 omitted
378
+
379
+ module_eval <<'.,.,', 'parser.ry', 22
380
+ def _reduce_5( val, _values, result )
381
+ result = [:print, val[1]]
382
+ result
383
+ end
384
+ .,.,
385
+
386
+ module_eval <<'.,.,', 'parser.ry', 23
387
+ def _reduce_6( val, _values, result )
388
+ result = [:printline, val[1]]
389
+ result
390
+ end
391
+ .,.,
392
+
393
+ module_eval <<'.,.,', 'parser.ry', 24
394
+ def _reduce_7( val, _values, result )
395
+ result = [:assign, val[1], val[3]]
396
+ result
397
+ end
398
+ .,.,
399
+
400
+ module_eval <<'.,.,', 'parser.ry', 25
401
+ def _reduce_8( val, _values, result )
402
+ result = [:if, val[1], [val[3]]]
403
+ result
404
+ end
405
+ .,.,
406
+
407
+ module_eval <<'.,.,', 'parser.ry', 26
408
+ def _reduce_9( val, _values, result )
409
+ result = [:if, val[1], val[6]]
410
+ result
411
+ end
412
+ .,.,
413
+
414
+ module_eval <<'.,.,', 'parser.ry', 27
415
+ def _reduce_10( val, _values, result )
416
+ result = [:if, val[1], val[6], val[10]]
417
+ result
418
+ end
419
+ .,.,
420
+
421
+ module_eval <<'.,.,', 'parser.ry', 28
422
+ def _reduce_11( val, _values, result )
423
+ result = [:stdio]
424
+ result
425
+ end
426
+ .,.,
427
+
428
+ module_eval <<'.,.,', 'parser.ry', 29
429
+ def _reduce_12( val, _values, result )
430
+ result = [:break]
431
+ result
432
+ end
433
+ .,.,
434
+
435
+ module_eval <<'.,.,', 'parser.ry', 30
436
+ def _reduce_13( val, _values, result )
437
+ result = [:loop, val[2]]
438
+ result
439
+ end
440
+ .,.,
441
+
442
+ module_eval <<'.,.,', 'parser.ry', 31
443
+ def _reduce_14( val, _values, result )
444
+ result = [:"+=", val[1], 1]
445
+ result
446
+ end
447
+ .,.,
448
+
449
+ module_eval <<'.,.,', 'parser.ry', 32
450
+ def _reduce_15( val, _values, result )
451
+ result = [:"+=", val[1], val[4]]
452
+ result
453
+ end
454
+ .,.,
455
+
456
+ module_eval <<'.,.,', 'parser.ry', 33
457
+ def _reduce_16( val, _values, result )
458
+ result = [:"-=", val[1], 1]
459
+ result
460
+ end
461
+ .,.,
462
+
463
+ module_eval <<'.,.,', 'parser.ry', 34
464
+ def _reduce_17( val, _values, result )
465
+ result = [:"-=", val[1], val[4]]
466
+ result
467
+ end
468
+ .,.,
469
+
470
+ module_eval <<'.,.,', 'parser.ry', 35
471
+ def _reduce_18( val, _values, result )
472
+ result = [:"/=", val[1], 1]
473
+ result
474
+ end
475
+ .,.,
476
+
477
+ module_eval <<'.,.,', 'parser.ry', 36
478
+ def _reduce_19( val, _values, result )
479
+ result = [:"/=", val[1], val[4]]
480
+ result
481
+ end
482
+ .,.,
483
+
484
+ module_eval <<'.,.,', 'parser.ry', 37
485
+ def _reduce_20( val, _values, result )
486
+ result = [:"*=", val[1], 1]
487
+ result
488
+ end
489
+ .,.,
490
+
491
+ module_eval <<'.,.,', 'parser.ry', 38
492
+ def _reduce_21( val, _values, result )
493
+ result = [:"*=", val[1], val[4]]
494
+ result
495
+ end
496
+ .,.,
497
+
498
+ module_eval <<'.,.,', 'parser.ry', 39
499
+ def _reduce_22( val, _values, result )
500
+ result = [:define, val[1], val[3]]
501
+ result
502
+ end
503
+ .,.,
504
+
505
+ module_eval <<'.,.,', 'parser.ry', 40
506
+ def _reduce_23( val, _values, result )
507
+ result = [:declare, val[1]]
508
+ result
509
+ end
510
+ .,.,
511
+
512
+ module_eval <<'.,.,', 'parser.ry', 41
513
+ def _reduce_24( val, _values, result )
514
+ result = [:getline, val[1]]
515
+ result
516
+ end
517
+ .,.,
518
+
519
+ module_eval <<'.,.,', 'parser.ry', 42
520
+ def _reduce_25( val, _values, result )
521
+ result = [:getline, val[2]]
522
+ result
523
+ end
524
+ .,.,
525
+
526
+ module_eval <<'.,.,', 'parser.ry', 43
527
+ def _reduce_26( val, _values, result )
528
+ result = [:getchar, val[2]]
529
+ result
530
+ end
531
+ .,.,
532
+
533
+ module_eval <<'.,.,', 'parser.ry', 44
534
+ def _reduce_27( val, _values, result )
535
+ result = [:getword, val[2]]
536
+ result
537
+ end
538
+ .,.,
539
+
540
+ module_eval <<'.,.,', 'parser.ry', 45
541
+ def _reduce_28( val, _values, result )
542
+ result = [:exit, 0]
543
+ result
544
+ end
545
+ .,.,
546
+
547
+ module_eval <<'.,.,', 'parser.ry', 46
548
+ def _reduce_29( val, _values, result )
549
+ result = [:exit, val[1]]
550
+ result
551
+ end
552
+ .,.,
553
+
554
+ module_eval <<'.,.,', 'parser.ry', 47
555
+ def _reduce_30( val, _values, result )
556
+ result = [:exit, val[1], val[2]]
557
+ result
558
+ end
559
+ .,.,
560
+
561
+ # reduce 31 omitted
562
+
563
+ module_eval <<'.,.,', 'parser.ry', 52
564
+ def _reduce_32( val, _values, result )
565
+ result = [:var, val[0]]
566
+ result
567
+ end
568
+ .,.,
569
+
570
+ # reduce 33 omitted
571
+
572
+ module_eval <<'.,.,', 'parser.ry', 54
573
+ def _reduce_34( val, _values, result )
574
+ result = [:"+", val[0], val[2]]
575
+ result
576
+ end
577
+ .,.,
578
+
579
+ module_eval <<'.,.,', 'parser.ry', 55
580
+ def _reduce_35( val, _values, result )
581
+ result = [:"-", val[0], val[2]]
582
+ result
583
+ end
584
+ .,.,
585
+
586
+ module_eval <<'.,.,', 'parser.ry', 56
587
+ def _reduce_36( val, _values, result )
588
+ result = [:"*", val[0], val[2]]
589
+ result
590
+ end
591
+ .,.,
592
+
593
+ module_eval <<'.,.,', 'parser.ry', 57
594
+ def _reduce_37( val, _values, result )
595
+ result = [:"/", val[0], val[2]]
596
+ result
597
+ end
598
+ .,.,
599
+
600
+ module_eval <<'.,.,', 'parser.ry', 58
601
+ def _reduce_38( val, _values, result )
602
+ result = [:">", val[0], val[2]]
603
+ result
604
+ end
605
+ .,.,
606
+
607
+ module_eval <<'.,.,', 'parser.ry', 59
608
+ def _reduce_39( val, _values, result )
609
+ result = [:"<", val[0], val[2]]
610
+ result
611
+ end
612
+ .,.,
613
+
614
+ module_eval <<'.,.,', 'parser.ry', 60
615
+ def _reduce_40( val, _values, result )
616
+ result = [:">=", val[0], val[2]]
617
+ result
618
+ end
619
+ .,.,
620
+
621
+ module_eval <<'.,.,', 'parser.ry', 61
622
+ def _reduce_41( val, _values, result )
623
+ result = [:"<=", val[0], val[2]]
624
+ result
625
+ end
626
+ .,.,
627
+
628
+ module_eval <<'.,.,', 'parser.ry', 62
629
+ def _reduce_42( val, _values, result )
630
+ result = [:"!=", val[0], val[2]]
631
+ result
632
+ end
633
+ .,.,
634
+
635
+ module_eval <<'.,.,', 'parser.ry', 63
636
+ def _reduce_43( val, _values, result )
637
+ result = [:"==", val[0], val[2]]
638
+ result
639
+ end
640
+ .,.,
641
+
642
+ # reduce 44 omitted
643
+
644
+ # reduce 45 omitted
645
+
646
+ def _reduce_none( val, _values, result )
647
+ result
648
+ end
649
+
650
+ end # class Parser
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qoobaa-lol
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "Jakub Ku\xC5\xBAma"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-24 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: lol is a simple lolcode interpreter using Racc and StringScanner
17
+ email: qoobaa@gmail.com
18
+ executables:
19
+ - lol
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.rdoc
26
+ - VERSION.yml
27
+ - lib/lol/lexer.rb
28
+ - lib/lol.rb
29
+ - lib/lol/parser.tab.rb
30
+ - lib/lol/parser.ry
31
+ - examples/hello.lol
32
+ - examples/ifthenelse.lol
33
+ - examples/loops.lol
34
+ - bin/lol
35
+ has_rdoc: false
36
+ homepage: http://github.com/qoobaa/lol
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.2.0
58
+ signing_key:
59
+ specification_version: 2
60
+ summary: simple lolcode interpreter
61
+ test_files: []
62
+