minjs 0.2.2 → 0.3.0

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.
@@ -13,9 +13,9 @@ module Minjs
13
13
  t << super
14
14
  t << "\n"
15
15
  if @lex
16
- line, col = @lex.line_col(@lex_pos)
17
- t << "line: #{line}, col: #{col}\n"
18
- t << @lex.debug_str(@lex_pos, line, col)
16
+ row, col = @lex.row_col(@lex_pos)
17
+ t << "row: #{row}, col: #{col}\n"
18
+ t << @lex.debug_str(@lex_pos, row, col)
19
19
  end
20
20
  t
21
21
  end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  module Minjs
2
3
  module Exp
3
4
  #
@@ -7,13 +8,13 @@ module Minjs
7
8
  def primary_exp(lex, context, options)
8
9
  @logger.debug "*** primary_exp"
9
10
 
10
- if lex.match_lit(ECMA262::ID_THIS)
11
- @logger.debug "*** primary_exp => this"
12
- return ECMA262::ID_THIS
11
+ if lex.eql_lit?(ECMA262::ID_THIS)
12
+ @logger.debug "*** primary_exp => this"
13
+ return ECMA262::This.new(context)
13
14
  end
14
15
  # (exp)
15
- if lex.match_lit(ECMA262::PUNC_LPARENTHESIS)
16
- if a=exp(lex, context, options) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS)
16
+ if lex.eql_lit?(ECMA262::PUNC_LPARENTHESIS)
17
+ if a=exp(lex, context, options) and lex.eql_lit?(ECMA262::PUNC_RPARENTHESIS)
17
18
  @logger.debug "*** primary_exp => ()"
18
19
  return ECMA262::ExpParen.new(a)
19
20
  else
@@ -21,466 +22,576 @@ module Minjs
21
22
  end
22
23
  end
23
24
 
24
- # identifier || literal || array_literal || object_literal
25
- t = lex.eval_lit {
26
- identifier(lex, context)
27
- } || lex.eval_lit {
28
- literal(lex, context)
29
- } || lex.eval_lit {
30
- array_literal(lex, context, options)
31
- } || lex.eval_lit {
32
- object_literal(lex, context, options)
33
- }
25
+ t = identifier(lex, context) ||
26
+ literal(lex, context) ||
27
+ array_literal(lex, context, options) ||
28
+ object_literal(lex, context, options)
29
+
34
30
  @logger.debug {
35
31
  "*** primary_exp => #{t ? t.to_js : t}"
36
32
  }
37
33
  t
38
34
  end
39
35
 
36
+ # 7.8
37
+ # 7.8.1
38
+ # 7.8.2
39
+ #
40
+ # Literal ::
41
+ # NullLiteral
42
+ # BooleanLiteral
43
+ # NumericLiteral
44
+ # StringLiteral
45
+ # RegularExpressionLiteral
46
+ #
47
+ def literal(lex, context)
48
+ a = lex.peek_lit(:regexp)
49
+ if a.kind_of? ECMA262::ECMA262Numeric or a.kind_of? ECMA262::ECMA262String or a.kind_of? ECMA262::ECMA262RegExp
50
+ lex.fwd_after_peek
51
+ a
52
+ elsif a.eql? ECMA262::ID_NULL
53
+ lex.fwd_after_peek
54
+ ECMA262::Null.get
55
+ elsif a.eql? ECMA262::ID_TRUE
56
+ lex.fwd_after_peek
57
+ ECMA262::Boolean.get(:true)
58
+ elsif a.eql? ECMA262::ID_FALSE
59
+ lex.fwd_after_peek
60
+ ECMA262::Boolean.get(:false)
61
+ else
62
+ nil
63
+ end
64
+ end
65
+
40
66
  #
41
67
  # 11.1.2
42
68
  #
43
69
  def identifier(lex, context)
44
- lex.eval_lit {
45
- if (a = lex.fwd_lit).kind_of? ECMA262::IdentifierName and !a.reserved?
46
- a.context = context
47
- a
48
- else
49
- nil
50
- end
51
- }
70
+ a = lex.peek_lit(:regexp)
71
+ if a.kind_of? ECMA262::IdentifierName and !a.reserved?
72
+ lex.fwd_after_peek
73
+ a.context = context
74
+ a
75
+ else
76
+ nil
77
+ end
52
78
  end
53
-
54
79
  #
55
80
  # 11.1.4
56
81
  #
57
82
  def array_literal(lex, context, options)
58
- return nil unless lex.match_lit(ECMA262::PUNC_LSQBRAC)
83
+ return nil unless lex.eql_lit?(ECMA262::PUNC_LSQBRAC)
59
84
  t = []
60
- lex.eval_lit {
61
- while true
62
- if lex.match_lit(ECMA262::PUNC_COMMA)
63
- t.push(nil)
64
- elsif lex.match_lit(ECMA262::PUNC_RSQBRAC)
65
- break
66
- elsif a = assignment_exp(lex, context, {})
67
- t.push(a)
68
- lex.match_lit(ECMA262::PUNC_COMMA)
69
- else
70
- raise ParseError.new("no `]' end of array", lex)
71
- end
85
+ while true
86
+ if lex.eql_lit?(ECMA262::PUNC_COMMA)
87
+ t.push(nil)
88
+ elsif lex.eql_lit?(ECMA262::PUNC_RSQBRAC)
89
+ break
90
+ elsif a = assignment_exp(lex, context, {})
91
+ t.push(a)
92
+ lex.eql_lit?(ECMA262::PUNC_COMMA)
93
+ else
94
+ raise ParseError.new("no `]' end of array", lex)
72
95
  end
73
- ECMA262::ECMA262Array.new(t)
74
- }
96
+ end
97
+ ECMA262::ECMA262Array.new(t)
75
98
  end
76
99
  #
77
100
  # 11.1.5
78
101
  #
102
+ # ObjectLiteral :
103
+ # { }
104
+ # { PropertyNameAndValueList }
105
+ # { PropertyNameAndValueList , }
106
+ #
79
107
  def object_literal(lex, context, options)
80
- return nil unless lex.match_lit(ECMA262::PUNC_LCURLYBRAC)
81
- lex.eval_lit {
82
- if lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
83
- next ECMA262::ECMA262Object.new([])
84
- end
85
- if h=property_name_and_value_list(lex, context, options)
86
- ECMA262::ECMA262Object.new(h)
87
- else
88
- raise ParseError.new("no `}' end of object", lex)
89
- end
90
- }
108
+ return nil unless lex.eql_lit?(ECMA262::PUNC_LCURLYBRAC)
109
+ #{}
110
+ if lex.eql_lit?(ECMA262::PUNC_RCURLYBRAC)
111
+ ECMA262::ECMA262Object.new([])
112
+ else
113
+ ECMA262::ECMA262Object.new(property_name_and_value_list(lex, context, options))
114
+ end
91
115
  end
92
116
 
117
+ # 11.1.5
118
+ #
119
+ # PropertyNameAndValueList :
120
+ # PropertyAssignment
121
+ # PropertyNameAndValueList , PropertyAssignment
122
+ #
123
+ # PropertyAssignment :
124
+ # PropertyName : AssignmentExpression
125
+ # get PropertyName ( ) { FunctionBody }
126
+ # set PropertyName ( PropertySetParameterList ) { FunctionBody }
127
+ #
93
128
  #
94
129
  # name: exp
95
130
  # get name(){funcbody}
96
131
  # set name(args){funcbody}
97
132
  #
98
133
  def property_name_and_value_list(lex, context, options)
99
- lex.eval_lit{
100
- h = []
101
- while !lex.eof?
102
- if lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
103
- break
104
- end
105
- lex.eval_lit{
106
- if lex.match_lit(ECMA262::ID_GET) and a=property_name(lex, context) and lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and lex.match_lit(ECMA262::PUNC_LCURLYBRAC) and b=func_body(lex, context) and lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
107
- h.push([a, ECMA262::StFunc.new(context, ECMA262::ID_GET, [], b, :getter => true)])
108
- elsif lex.match_lit(ECMA262::ID_SET) and a=property_name(lex, context) and lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and arg=property_set_parameter_list(lex, context) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and lex.match_lit(ECMA262::PUNC_LCURLYBRAC) and b=func_body(lex, context) and lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
109
- h.push([a, ECMA262::StFunc.new(context, ECMA262::ID_SET, arg, b, :setter => true)])
134
+ h = []
135
+ while !lex.eof?
136
+ #get
137
+ if lex.match_lit? ECMA262::ID_GET
138
+ # {get : val}
139
+ if lex.eql_lit? ECMA262::PUNC_COLON
140
+ b = assignment_exp(lex, context, options)
141
+ h.push([ECMA262::ID_GET, b])
142
+ # {get name(){}}
143
+ else
144
+ new_context = ECMA262::Context.new
145
+ new_context.lex_env = context.lex_env.new_declarative_env()
146
+ new_context.var_env = context.var_env.new_declarative_env()
147
+ if(a = property_name(lex, context) and
148
+ lex.eql_lit? ECMA262::PUNC_LPARENTHESIS and
149
+ lex.eql_lit? ECMA262::PUNC_RPARENTHESIS and
150
+ lex.eql_lit? ECMA262::PUNC_LCURLYBRAC and
151
+ b = func_body(lex, new_context) and
152
+ lex.eql_lit? ECMA262::PUNC_RCURLYBRAC)
153
+ h.push([a, ECMA262::StFunc.new(new_context, ECMA262::ID_GET, [], b, :getter => true)])
110
154
  else
111
- nil
155
+ raise ParseError.new("unexpceted token", lex)
112
156
  end
113
- } or lex.eval_lit{
114
- a=property_name(lex, context) and lex.match_lit(ECMA262::PUNC_COLON) and b=assignment_exp(lex, context, options)
115
- h.push([a, b])
116
- }
117
-
118
- if lex.match_lit(ECMA262::PUNC_COMMA)
119
- break if lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
120
- elsif lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
121
- break
157
+ end
158
+ #set
159
+ elsif lex.match_lit?(ECMA262::ID_SET)
160
+ # {set : val}
161
+ if lex.eql_lit? ECMA262::PUNC_COLON
162
+ b = assignment_exp(lex, context, options)
163
+ h.push([ECMA262::ID_SET, b])
164
+ # {set name(arg){}}
122
165
  else
123
- raise ParseError.new("no `}' end of object", lex)
166
+ new_context = ECMA262::Context.new
167
+ new_context.lex_env = context.lex_env.new_declarative_env()
168
+ new_context.var_env = context.var_env.new_declarative_env()
169
+ if(a = property_name(lex, context) and
170
+ lex.eql_lit? ECMA262::PUNC_LPARENTHESIS and
171
+ arg = property_set_parameter_list(lex, new_context) and
172
+ lex.eql_lit? ECMA262::PUNC_RPARENTHESIS and
173
+ lex.eql_lit? ECMA262::PUNC_LCURLYBRAC and
174
+ b = func_body(lex, new_context) and
175
+ lex.eql_lit? ECMA262::PUNC_RCURLYBRAC)
176
+ h.push([a, ECMA262::StFunc.new(new_context, ECMA262::ID_SET, arg, b, :setter => true)])
177
+ else
178
+ raise ParseError.new("unexpceted token", lex)
179
+ end
124
180
  end
181
+ #property
182
+ elsif(a = property_name(lex, context) and
183
+ lex.eql_lit? ECMA262::PUNC_COLON and
184
+ b = assignment_exp(lex, context, options))
185
+ h.push([a, b])
186
+ else
187
+ raise ParseError.new("unexpceted token", lex)
125
188
  end
126
- h
127
- }
128
- end
129
189
 
130
- def property_name(lex, context)
131
- lex.eval_lit {
132
- a = lex.fwd_lit
133
- if a.kind_of?(ECMA262::ECMA262String)
134
- a
135
- elsif a.kind_of?(ECMA262::IdentifierName)
136
- ECMA262::ECMA262String.new(a.to_js)
137
- elsif a.kind_of?(ECMA262::ECMA262Numeric)
138
- a
190
+ if lex.eql_lit?(ECMA262::PUNC_COMMA)
191
+ break if lex.eql_lit?(ECMA262::PUNC_RCURLYBRAC)
192
+ elsif lex.eql_lit?(ECMA262::PUNC_RCURLYBRAC)
193
+ break
139
194
  else
140
- nil
195
+ raise ParseError.new("no `}' end of object", lex)
141
196
  end
142
- }
197
+ end
198
+ h
143
199
  end
144
200
 
145
- def property_set_parameter_list(lex, context)
146
- lex.eval_lit {
147
- a = lex.fwd_lit
148
- if a.kind_of?(ECMA262::IdentifierName) and !a.reserved?
149
- [a]
150
- else
151
- nil
152
- end
153
- }
201
+ # 11.1.5
202
+ #
203
+ # PropertyName :
204
+ # IdentifierName
205
+ # StringLiteral
206
+ # NumericLiteral
207
+ #
208
+ def property_name(lex, context)
209
+ a = lex.fwd_lit(nil)
210
+ if a.kind_of?(ECMA262::ECMA262String)
211
+ a
212
+ elsif a.kind_of?(ECMA262::IdentifierName)
213
+ ECMA262::ECMA262String.new(a.to_js)
214
+ elsif a.kind_of?(ECMA262::ECMA262Numeric)
215
+ a
216
+ elsif a.eql?(ECMA262::PUNC_COLON)
217
+ nil
218
+ else
219
+ raise ParseError.new("unexpceted token", lex)
220
+ end
154
221
  end
155
222
 
223
+ # 11.1.5
224
+ #
225
+ # PropertySetParameterList :
226
+ # Identifier
156
227
  #
228
+ def property_set_parameter_list(lex, context)
229
+ argName = identifier(lex, context)
230
+ context.var_env.record.create_mutable_binding(argName, nil)
231
+ context.var_env.record.set_mutable_binding(argName, :undefined, nil, {:_parameter_list => true})
232
+ context.lex_env.record.create_mutable_binding(argName, nil)
233
+ context.lex_env.record.set_mutable_binding(argName, :undefined, nil, {:_parameter_list => true})
234
+ [argName]
235
+ end
236
+
157
237
  # 11.2
158
238
  #
239
+ # LeftHandSideExpression :
240
+ # NewExpression
241
+ # CallExpression
242
+ #
159
243
  def left_hand_side_exp(lex, context, options)
160
244
  @logger.debug "*** left_hand_side_exp"
161
245
 
162
- t = lex.eval_lit{
163
- call_exp(lex, context, options)
164
- } || lex.eval_lit{
165
- new_exp(lex, context, options)
166
- }
246
+ t = call_exp(lex, context, options) || new_exp(lex, context, options)
247
+ #t = new_exp(lex, context, options) || call_exp(lex, context, options)
248
+
167
249
  @logger.debug{
168
250
  "*** left_hand_side_exp => #{t ? t.to_js: t}"
169
251
  }
170
252
  t
171
253
  end
172
254
 
255
+ # 11.2
256
+ #
257
+ # NewExpression :
258
+ # MemberExpression
259
+ # new NewExpression
260
+ #
261
+ # NOTE:
262
+ #
263
+ # The NewExpression only matchs no-arguments-constructor because
264
+ # member expression also has "new MemberExpression Arguments"
265
+ #
266
+ # For example,
267
+ #
268
+ # 1. new A;
269
+ # 2. new A[B];
270
+ # 3. new A.B;
271
+ # 4. new A.B();
272
+ # 5. new new B();
273
+ # 6. A();
274
+ #
275
+ # 1 to 3 are NewExpression.
276
+ # 4 is MemberExpression.
277
+ # 5 's first new is NewExpression and second one is MemberExpression.
278
+ # 6 is CallExpression
279
+ #
280
+ # NewExpression can be rewritten as follows:
281
+ #
282
+ # NewExpression:
283
+ # MemberExpression [lookahead ∉ {(}]
284
+ # new NewExpression [lookahead ∉ {(}]
285
+ #
173
286
  def new_exp(lex, context, options)
174
- lex.eval_lit{
175
- if lex.match_lit(ECMA262::ID_NEW)
176
- if a=new_exp(lex, context, options)
287
+ lex.eval_lit {
288
+ if lex.eql_lit?(ECMA262::ID_NEW)
289
+ if a = new_exp(lex, context, options)
290
+ if lex.eql_lit? ECMA262::PUNC_LPARENTHESIS
291
+ # minjs evaluate CallExpression first, so
292
+ # program never falls to here.
293
+ next nil # this is not NewExpression, may be MemberExpression.
294
+ end
295
+ #puts "new_exp> #{a.to_js}"
177
296
  ECMA262::ExpNew.new(a, nil)
178
297
  else
298
+ # minjs evaluate CallExpression first, so
299
+ # raise exception when program falls to here.
179
300
  raise ParseError.new("unexpceted token", lex)
301
+ #nil
180
302
  end
181
- else
182
- nil
183
303
  end
184
- } or lex.eval_lit{
185
- member_exp(lex, context, options)
186
- }
304
+ } || member_exp(lex, context, options)
305
+ # minjs evaluate CallExpression first, so
306
+ # there is no reason to check parenthesis.
307
+ #
308
+ # lex.eval_lit{
309
+ # t = member_exp(lex, context, options)
310
+ # if lex.eql_lit? ECMA262::PUNC_LPARENTHESIS
311
+ # break nil
312
+ # end
313
+ # t
314
+ # }
187
315
  end
188
-
189
- #
190
- # call
191
- #
192
- # member_exp arguments
193
- #
194
- # call_exp arguments
195
- # call_exp [exp]
196
- # call_exp . identifier_name
316
+ # 11.2
197
317
  #
318
+ # CallExpression :
319
+ # MemberExpression Arguments
320
+ # CallExpression Arguments
321
+ # CallExpression [ Expression ]
322
+ # CallExpression . IdentifierName
198
323
  #
199
324
  def call_exp(lex, context, options)
200
- a = lex.eval_lit{
201
- if f = member_exp(lex, context, options)
202
- if b = arguments(lex, context, options)
203
- ECMA262::ExpCall.new(f, b)
204
- else
205
- f
206
- end
325
+ if a = member_exp(lex, context, options)
326
+ if b = arguments(lex, context, options)
327
+ t = ECMA262::ExpCall.new(a, b)
328
+ # if b is nil, this may be MemberExpression of NewExpression
207
329
  else
208
- nil
330
+ return a
209
331
  end
210
- }
211
- return nil if a.nil?
212
-
213
- t = a
332
+ else
333
+ return nil
334
+ end
214
335
 
215
- lex.eval_lit{
216
- while true
217
- if b=arguments(lex, context, options)
218
- t = ECMA262::ExpCall.new(t, b)
219
- elsif lex.match_lit(ECMA262::PUNC_LSQBRAC)
220
- if b=exp(lex, context, options) and lex.match_lit(ECMA262::PUNC_RSQBRAC)
221
- t = ECMA262::ExpPropBrac.new(t, b)
222
- else
223
- raise ParseError.new("unexpceted token", lex)
224
- end
225
- elsif lex.match_lit(ECMA262::PUNC_PERIOD)
226
- if (b=lex.fwd_lit()).kind_of?(ECMA262::IdentifierName)
227
- t = ECMA262::ExpProp.new(t, b)
228
- else
229
- raise ParseError.new("unexpceted token", lex)
230
- end
336
+ while true
337
+ if b = arguments(lex, context, options)
338
+ t = ECMA262::ExpCall.new(t, b)
339
+ elsif lex.eql_lit?(ECMA262::PUNC_LSQBRAC)
340
+ if b=exp(lex, context, options) and lex.eql_lit?(ECMA262::PUNC_RSQBRAC)
341
+ t = ECMA262::ExpPropBrac.new(t, b)
231
342
  else
232
- break
343
+ raise ParseError.new("unexpceted token", lex)
233
344
  end
345
+ elsif lex.eql_lit?(ECMA262::PUNC_PERIOD)
346
+ if (b=lex.fwd_lit(nil)).kind_of?(ECMA262::IdentifierName)
347
+ t = ECMA262::ExpProp.new(t, b)
348
+ else
349
+ raise ParseError.new("unexpceted token", lex)
350
+ end
351
+ else
352
+ break
234
353
  end
235
- t
236
- } or a
354
+ end
355
+ t
237
356
  end
238
357
 
358
+ # 11.2
239
359
  #
240
- # member_exp
241
- # primary_exp
242
- # function_exp
243
- # new member_exp arguments
244
- #
245
- # member_exp[exp]
246
- # member_exp.identifier_name #prop(a,b)
360
+ # MemberExpression :
361
+ # PrimaryExpression
362
+ # FunctionExpression
363
+ # MemberExpression [ Expression ]
364
+ # MemberExpression . IdentifierName
365
+ # new MemberExpression Arguments
247
366
  #
248
367
  def member_exp(lex, context, options)
249
- a = lex.eval_lit {
250
- primary_exp(lex, context, options)
251
- } || lex.eval_lit {
252
- func_exp(lex, context)
253
- } || lex.eval_lit {
254
- if lex.match_lit(ECMA262::ID_NEW) and a=member_exp(lex, context, options) and b=arguments(lex, context, options)
255
- ECMA262::ExpNew.new(a, b)
256
- else
257
- nil
368
+ t = lex.eval_lit{
369
+ if lex.eql_lit? ECMA262::ID_NEW
370
+ if a = member_exp(lex, context, options)
371
+ b = arguments(lex, context, options)
372
+ # if b is nil, this may be NewExpression
373
+ if b
374
+ s = b.collect{|x| x.to_js}.join(',');
375
+ #puts "member_exp> [new] #{a.to_js} (#{s})"
376
+ next ECMA262::ExpNew.new(a, b)
377
+ else
378
+ return nil
379
+ end
380
+ else
381
+ return nil
382
+ end
258
383
  end
259
- }
260
- return nil if a.nil?
261
-
262
- t = a
384
+ } || primary_exp(lex, context, options) || func_exp(lex, context)
385
+ return nil if t.nil?
263
386
 
264
- lex.eval_lit {
265
- while true
266
- if lex.match_lit(ECMA262::PUNC_LSQBRAC)
267
- if b=exp(lex, context, options) and lex.match_lit(ECMA262::PUNC_RSQBRAC)
268
- t = ECMA262::ExpPropBrac.new(t, b)
269
- else
270
- raise ParseError.new("unexpceted token", lex)
271
- end
272
- elsif lex.match_lit(ECMA262::PUNC_PERIOD)
273
- if (b=lex.fwd_lit()).kind_of?(ECMA262::IdentifierName)
274
- t = ECMA262::ExpProp.new(t, b)
275
- else
276
- raise ParseError.new("unexpceted token", lex)
277
- end
387
+ while true
388
+ if lex.eql_lit?(ECMA262::PUNC_LSQBRAC)
389
+ if b=exp(lex, context, options) and lex.eql_lit?(ECMA262::PUNC_RSQBRAC)
390
+ t = ECMA262::ExpPropBrac.new(t, b)
278
391
  else
279
- break
392
+ raise ParseError.new("unexpceted token", lex)
280
393
  end
394
+ elsif lex.eql_lit?(ECMA262::PUNC_PERIOD)
395
+ if (b=lex.fwd_lit(nil)).kind_of?(ECMA262::IdentifierName)
396
+ t = ECMA262::ExpProp.new(t, b)
397
+ else
398
+ raise ParseError.new("unexpceted token", lex)
399
+ end
400
+ else
401
+ break
281
402
  end
282
- t
283
- } or a
403
+ end
404
+ t
284
405
  end
285
-
406
+ # 11.2
407
+ # Arguments :
408
+ # ( )
409
+ # ( ArgumentList )
410
+ #
286
411
  def arguments(lex, context, options)
287
- lex.eval_lit{
288
- return nil if lex.match_lit(ECMA262::PUNC_LPARENTHESIS).nil?
289
- next [] if lex.match_lit(ECMA262::PUNC_RPARENTHESIS)
290
- args = []
291
- while true
292
- if t = assignment_exp(lex, context, options)
293
- args.push(t)
294
- else
295
- return
296
- end
297
- if lex.match_lit(ECMA262::PUNC_COMMA)
298
- ;
299
- elsif lex.match_lit(ECMA262::PUNC_RPARENTHESIS)
300
- break
301
- else
302
- return
303
- end
412
+ return nil if lex.eql_lit?(ECMA262::PUNC_LPARENTHESIS).nil?
413
+ return [] if lex.eql_lit?(ECMA262::PUNC_RPARENTHESIS)
414
+
415
+ args = []
416
+ while true
417
+ if t = assignment_exp(lex, context, options)
418
+ args.push(t)
419
+ else
420
+ raise ParseError.new("unexpected token", lex)
304
421
  end
305
- args
306
- }
422
+ if lex.eql_lit?(ECMA262::PUNC_COMMA)
423
+ ;
424
+ elsif lex.eql_lit?(ECMA262::PUNC_RPARENTHESIS)
425
+ break
426
+ else
427
+ raise ParseError.new("unexpected token", lex)
428
+ end
429
+ end
430
+ args
307
431
  end
308
432
  #
309
433
  # 11.3
310
434
  #
311
435
  def postfix_exp(lex, context, options)
312
- t = lex.eval_lit{
313
- a = left_hand_side_exp(lex, context, options)
314
- return nil if a.nil?
315
- if punc = (lex.match_lit(ECMA262::PUNC_INC, :nolt => true) ||
316
- lex.match_lit(ECMA262::PUNC_DEC, :nolt => true))
317
- if punc == ECMA262::PUNC_INC
318
- ECMA262::ExpPostInc.new(a)
319
- else
320
- ECMA262::ExpPostDec.new(a)
321
- end
436
+ exp = left_hand_side_exp(lex, context, options)
437
+ return nil if exp.nil?
438
+ if punc = (lex.eql_lit_nolt?(ECMA262::PUNC_INC) ||
439
+ lex.eql_lit_nolt?(ECMA262::PUNC_DEC))
440
+ if punc == ECMA262::PUNC_INC
441
+ ECMA262::ExpPostInc.new(exp)
322
442
  else
323
- a
443
+ ECMA262::ExpPostDec.new(exp)
324
444
  end
325
- }
326
- t
445
+ else
446
+ exp
447
+ end
327
448
  end
328
449
 
329
450
  #
330
451
  # 11.4
331
452
  #
332
453
  def unary_exp(lex, context, options)
333
- lex.eval_lit{
334
- if punc = (lex.match_lit(ECMA262::ID_DELETE) ||
335
- lex.match_lit(ECMA262::ID_VOID) ||
336
- lex.match_lit(ECMA262::ID_TYPEOF) ||
337
- lex.match_lit(ECMA262::PUNC_INC) ||
338
- lex.match_lit(ECMA262::PUNC_DEC) ||
339
- lex.match_lit(ECMA262::PUNC_ADD) ||
340
- lex.match_lit(ECMA262::PUNC_SUB) ||
341
- lex.match_lit(ECMA262::PUNC_NOT) ||
342
- lex.match_lit(ECMA262::PUNC_LNOT))
343
- a = unary_exp(lex, context, options)
344
- if a.nil?
345
- raise ParseError.new("unexpceted token", lex)
346
- elsif punc.val == :delete
347
- ECMA262::ExpDelete.new(a)
348
- elsif punc.val == :void
349
- ECMA262::ExpVoid.new(a)
350
- elsif punc.val == :typeof
351
- ECMA262::ExpTypeof.new(a)
352
- elsif punc == ECMA262::PUNC_INC
353
- ECMA262::ExpPreInc.new(a)
354
- elsif punc == ECMA262::PUNC_DEC
355
- ECMA262::ExpPreDec.new(a)
356
- elsif punc == ECMA262::PUNC_ADD
357
- ECMA262::ExpPositive.new(a)
358
- elsif punc == ECMA262::PUNC_SUB
359
- ECMA262::ExpNegative.new(a)
360
- elsif punc == ECMA262::PUNC_NOT
361
- ECMA262::ExpBitwiseNot.new(a)
362
- elsif punc == ECMA262::PUNC_LNOT
363
- ECMA262::ExpLogicalNot.new(a)
364
- end
454
+ if punc = (lex.eql_lit?(ECMA262::ID_DELETE) ||
455
+ lex.eql_lit?(ECMA262::ID_VOID) ||
456
+ lex.eql_lit?(ECMA262::ID_TYPEOF) ||
457
+ lex.eql_lit?(ECMA262::PUNC_INC) ||
458
+ lex.eql_lit?(ECMA262::PUNC_DEC) ||
459
+ lex.eql_lit?(ECMA262::PUNC_ADD) ||
460
+ lex.eql_lit?(ECMA262::PUNC_SUB) ||
461
+ lex.eql_lit?(ECMA262::PUNC_NOT) ||
462
+ lex.eql_lit?(ECMA262::PUNC_LNOT))
463
+ exp = unary_exp(lex, context, options)
464
+ if exp.nil?
465
+ raise ParseError.new("unexpceted token", lex)
466
+ elsif punc == ECMA262::PUNC_INC
467
+ ECMA262::ExpPreInc.new(exp)
468
+ elsif punc == ECMA262::PUNC_DEC
469
+ ECMA262::ExpPreDec.new(exp)
470
+ elsif punc == ECMA262::PUNC_ADD
471
+ ECMA262::ExpPositive.new(exp)
472
+ elsif punc == ECMA262::PUNC_SUB
473
+ ECMA262::ExpNegative.new(exp)
474
+ elsif punc == ECMA262::PUNC_NOT
475
+ ECMA262::ExpBitwiseNot.new(exp)
476
+ elsif punc == ECMA262::PUNC_LNOT
477
+ ECMA262::ExpLogicalNot.new(exp)
478
+ elsif punc.respond_to?(:val)
479
+ if punc.val == :delete
480
+ ECMA262::ExpDelete.new(exp)
481
+ elsif punc.val == :void
482
+ ECMA262::ExpVoid.new(exp)
483
+ elsif punc.val == :typeof
484
+ ECMA262::ExpTypeof.new(exp)
485
+ end
365
486
  end
366
- } || lex.eval_lit{
487
+ else
367
488
  postfix_exp(lex, context, options)
368
- }
489
+ end
369
490
  end
370
491
 
371
492
  #
372
493
  # 11.5
373
494
  #
374
495
  def multiplicative_exp(lex, context, options)
375
- lex.eval_lit {
376
- a = unary_exp(lex, context, options)
377
- next nil if !a
378
- t = a
379
- while punc = lex.match_lit(ECMA262::PUNC_MUL) ||
380
- lex.match_lit(ECMA262::PUNC_DIV, :hint => :div) ||
381
- lex.match_lit(ECMA262::PUNC_MOD)
382
-
383
- if b = unary_exp(lex, context, options)
384
- if punc == ECMA262::PUNC_MUL
385
- t = ECMA262::ExpMul.new(t, b)
386
- elsif punc == ECMA262::PUNC_DIV
387
- t = ECMA262::ExpDiv.new(t, b)
388
- else
389
- t = ECMA262::ExpMod.new(t, b)
390
- end
496
+ a = unary_exp(lex, context, options)
497
+ return nil if !a
498
+ t = a
499
+ while punc = lex.eql_lit?(ECMA262::PUNC_MUL) ||
500
+ lex.eql_lit?(ECMA262::PUNC_DIV, :div) ||
501
+ lex.eql_lit?(ECMA262::PUNC_MOD)
502
+
503
+ if b = unary_exp(lex, context, options)
504
+ if punc == ECMA262::PUNC_MUL
505
+ t = ECMA262::ExpMul.new(t, b)
506
+ elsif punc == ECMA262::PUNC_DIV
507
+ t = ECMA262::ExpDiv.new(t, b)
391
508
  else
392
- raise ParseError.new("unexpceted token", lex)
509
+ t = ECMA262::ExpMod.new(t, b)
393
510
  end
511
+ else
512
+ raise ParseError.new("unexpceted token", lex)
394
513
  end
395
- t
396
- }
514
+ end
515
+ t
397
516
  end
398
517
 
399
518
  #
400
519
  # 11.6
401
520
  #
402
521
  def additive_exp(lex, context, options)
403
- lex.eval_lit {
404
- a = multiplicative_exp(lex, context, options)
405
- next nil if !a
406
-
407
- t = a
408
- while punc = lex.match_lit(ECMA262::PUNC_ADD) || lex.match_lit(ECMA262::PUNC_SUB)
409
- if b = multiplicative_exp(lex, context, options)
410
- if punc == ECMA262::PUNC_ADD
411
- t = ECMA262::ExpAdd.new(t, b)
412
- else
413
- t = ECMA262::ExpSub.new(t, b)
414
- end
522
+ a = multiplicative_exp(lex, context, options)
523
+ return nil if !a
524
+
525
+ t = a
526
+ while punc = lex.eql_lit?(ECMA262::PUNC_ADD) || lex.eql_lit?(ECMA262::PUNC_SUB)
527
+ if b = multiplicative_exp(lex, context, options)
528
+ if punc == ECMA262::PUNC_ADD
529
+ t = ECMA262::ExpAdd.new(t, b)
415
530
  else
416
- raise ParseError.new("unexpceted token", lex)
531
+ t = ECMA262::ExpSub.new(t, b)
417
532
  end
533
+ else
534
+ raise ParseError.new("unexpceted token", lex)
418
535
  end
419
-
420
- t
421
- }
536
+ end
537
+ t
422
538
  end
423
539
  #
424
540
  # 11.7
425
541
  def shift_exp(lex, context, options)
426
- lex.eval_lit {
427
- a = additive_exp(lex, context, options)
428
- next nil if !a
429
-
430
- t = a
431
- while punc = lex.match_lit(ECMA262::PUNC_LSHIFT) ||
432
- lex.match_lit(ECMA262::PUNC_RSHIFT) ||
433
- lex.match_lit(ECMA262::PUNC_URSHIFT)
434
- if b = additive_exp(lex, context, options)
435
- if punc == ECMA262::PUNC_LSHIFT
436
- t = ECMA262::ExpLShift.new(t, b)
437
- elsif punc == ECMA262::PUNC_RSHIFT
438
- t = ECMA262::ExpRShift.new(t, b)
439
- elsif punc == ECMA262::PUNC_URSHIFT
440
- t = ECMA262::ExpURShift.new(t, b)
441
- end
442
- else
443
- raise ParseError.new("unexpceted token", lex)
542
+ a = additive_exp(lex, context, options)
543
+ return nil if !a
544
+
545
+ t = a
546
+ while punc = lex.eql_lit?(ECMA262::PUNC_LSHIFT) ||
547
+ lex.eql_lit?(ECMA262::PUNC_RSHIFT) ||
548
+ lex.eql_lit?(ECMA262::PUNC_URSHIFT)
549
+ if b = additive_exp(lex, context, options)
550
+ if punc == ECMA262::PUNC_LSHIFT
551
+ t = ECMA262::ExpLShift.new(t, b)
552
+ elsif punc == ECMA262::PUNC_RSHIFT
553
+ t = ECMA262::ExpRShift.new(t, b)
554
+ elsif punc == ECMA262::PUNC_URSHIFT
555
+ t = ECMA262::ExpURShift.new(t, b)
444
556
  end
557
+ else
558
+ raise ParseError.new("unexpceted token", lex)
445
559
  end
446
- t
447
- }
560
+ end
561
+ t
448
562
  end
449
563
  #
450
564
  #
451
565
  # 11.8
452
566
  #
453
567
  def relational_exp(lex, context, options)
454
- lex.eval_lit {
455
- a = shift_exp(lex, context, options)
456
- next nil if !a
457
-
458
- t = a
459
- while (punc = lex.match_lit(ECMA262::PUNC_LT) || lex.match_lit(ECMA262::PUNC_GT) ||
460
- lex.match_lit(ECMA262::PUNC_LTEQ) || lex.match_lit(ECMA262::PUNC_GTEQ) ||
461
- lex.match_lit(ECMA262::ID_INSTANCEOF) || (!options[:no_in] && lex.match_lit(ECMA262::ID_IN)))
462
- if b = shift_exp(lex, context, options)
463
- if punc == ECMA262::PUNC_LT
464
- t = ECMA262::ExpLt.new(t, b)
465
- elsif punc == ECMA262::PUNC_GT
466
- t = ECMA262::ExpGt.new(t, b)
467
- elsif punc == ECMA262::PUNC_LTEQ
468
- t = ECMA262::ExpLtEq.new(t, b)
469
- elsif punc == ECMA262::PUNC_GTEQ
470
- t = ECMA262::ExpGtEq.new(t, b)
471
- elsif punc.val == :instanceof
472
- t = ECMA262::ExpInstanceOf.new(t, b)
473
- elsif !options[:no_in] and punc.val == :in
474
- t = ECMA262::ExpIn.new(t, b)
475
- else
476
- end
568
+ a = shift_exp(lex, context, options)
569
+ return nil if !a
570
+
571
+ t = a
572
+ while (punc = lex.eql_lit?(ECMA262::PUNC_LT) || lex.eql_lit?(ECMA262::PUNC_GT) ||
573
+ lex.eql_lit?(ECMA262::PUNC_LTEQ) || lex.eql_lit?(ECMA262::PUNC_GTEQ) ||
574
+ lex.eql_lit?(ECMA262::ID_INSTANCEOF) || (!options[:no_in] && lex.eql_lit?(ECMA262::ID_IN)))
575
+ if b = shift_exp(lex, context, options)
576
+ if punc == ECMA262::PUNC_LT
577
+ t = ECMA262::ExpLt.new(t, b)
578
+ elsif punc == ECMA262::PUNC_GT
579
+ t = ECMA262::ExpGt.new(t, b)
580
+ elsif punc == ECMA262::PUNC_LTEQ
581
+ t = ECMA262::ExpLtEq.new(t, b)
582
+ elsif punc == ECMA262::PUNC_GTEQ
583
+ t = ECMA262::ExpGtEq.new(t, b)
584
+ elsif punc.val == :instanceof
585
+ t = ECMA262::ExpInstanceOf.new(t, b)
586
+ elsif !options[:no_in] and punc.val == :in
587
+ t = ECMA262::ExpIn.new(t, b)
477
588
  else
478
- raise ParseError.new("unexpceted token", lex)
479
589
  end
590
+ else
591
+ raise ParseError.new("unexpceted token", lex)
480
592
  end
481
-
482
- t
483
- }
593
+ end
594
+ t
484
595
  end
485
596
  #
486
597
  #
@@ -491,32 +602,29 @@ module Minjs
491
602
  # a !== b
492
603
  #
493
604
  def equality_exp(lex, context, options)
494
- lex.eval_lit {
495
- a = relational_exp(lex, context, options)
496
- next nil if !a
497
-
498
- t = a
499
- while punc = lex.match_lit(ECMA262::PUNC_EQ) ||
500
- lex.match_lit(ECMA262::PUNC_NEQ) ||
501
- lex.match_lit(ECMA262::PUNC_SEQ) ||
502
- lex.match_lit(ECMA262::PUNC_SNEQ)
503
- if b = relational_exp(lex, context, options)
504
- if punc == ECMA262::PUNC_EQ
505
- t = ECMA262::ExpEq.new(t, b)
506
- elsif punc == ECMA262::PUNC_NEQ
507
- t = ECMA262::ExpNotEq.new(t, b)
508
- elsif punc == ECMA262::PUNC_SEQ
509
- t = ECMA262::ExpStrictEq.new(t, b)
510
- elsif punc == ECMA262::PUNC_SNEQ
511
- t = ECMA262::ExpStrictNotEq.new(t, b)
512
- end
513
- else
514
- raise ParseError.new("unexpceted token", lex)
605
+ a = relational_exp(lex, context, options)
606
+ return nil if !a
607
+
608
+ t = a
609
+ while punc = lex.eql_lit?(ECMA262::PUNC_EQ) ||
610
+ lex.eql_lit?(ECMA262::PUNC_NEQ) ||
611
+ lex.eql_lit?(ECMA262::PUNC_SEQ) ||
612
+ lex.eql_lit?(ECMA262::PUNC_SNEQ)
613
+ if b = relational_exp(lex, context, options)
614
+ if punc == ECMA262::PUNC_EQ
615
+ t = ECMA262::ExpEq.new(t, b)
616
+ elsif punc == ECMA262::PUNC_NEQ
617
+ t = ECMA262::ExpNotEq.new(t, b)
618
+ elsif punc == ECMA262::PUNC_SEQ
619
+ t = ECMA262::ExpStrictEq.new(t, b)
620
+ elsif punc == ECMA262::PUNC_SNEQ
621
+ t = ECMA262::ExpStrictNotEq.new(t, b)
515
622
  end
623
+ else
624
+ raise ParseError.new("unexpceted token", lex)
516
625
  end
517
-
518
- t
519
- }
626
+ end
627
+ t
520
628
  end
521
629
 
522
630
  #
@@ -524,209 +632,202 @@ module Minjs
524
632
  # a & b
525
633
  #
526
634
  def bitwise_and_exp(lex, context, options)
527
- lex.eval_lit {
528
- a = equality_exp(lex, context, options)
529
- next nil if !a
635
+ a = equality_exp(lex, context, options)
636
+ return nil if !a
530
637
 
531
- t = a
532
- while punc = lex.match_lit(ECMA262::PUNC_AND)
533
- if b = equality_exp(lex, context, options)
534
- t = ECMA262::ExpAnd.new(t, b)
535
- else
536
- raise ParseError.new("unexpceted token", lex)
537
- end
638
+ t = a
639
+ while punc = lex.eql_lit?(ECMA262::PUNC_AND)
640
+ if b = equality_exp(lex, context, options)
641
+ t = ECMA262::ExpAnd.new(t, b)
642
+ else
643
+ raise ParseError.new("unexpceted token", lex)
538
644
  end
539
-
540
- t
541
- }
645
+ end
646
+ t
542
647
  end
543
648
 
544
649
  #
545
650
  # a ^ b
546
651
  #
547
652
  def bitwise_xor_exp(lex, context, options)
548
- lex.eval_lit {
549
- a = bitwise_and_exp(lex, context, options)
550
- next nil if !a
653
+ a = bitwise_and_exp(lex, context, options)
654
+ return nil if !a
551
655
 
552
- t = a
553
- while punc = lex.match_lit(ECMA262::PUNC_XOR)
554
- if b = bitwise_and_exp(lex, context, options)
555
- t = ECMA262::ExpXor.new(t, b)
556
- else
557
- raise ParseError.new("unexpceted token", lex)
558
- end
656
+ t = a
657
+ while punc = lex.eql_lit?(ECMA262::PUNC_XOR)
658
+ if b = bitwise_and_exp(lex, context, options)
659
+ t = ECMA262::ExpXor.new(t, b)
660
+ else
661
+ raise ParseError.new("unexpceted token", lex)
559
662
  end
663
+ end
560
664
 
561
- t
562
- }
665
+ t
563
666
  end
564
667
 
565
668
  #
566
669
  # a | b
567
670
  #
568
671
  def bitwise_or_exp(lex, context, options)
569
- lex.eval_lit {
570
- a = bitwise_xor_exp(lex, context, options)
571
- next nil if !a
672
+ a = bitwise_xor_exp(lex, context, options)
673
+ return nil if !a
572
674
 
573
- t = a
574
- while punc = lex.match_lit(ECMA262::PUNC_OR)
575
- if b = bitwise_xor_exp(lex, context, options)
576
- t = ECMA262::ExpOr.new(t, b)
577
- else
578
- raise ParseError.new("unexpceted token", lex)
579
- end
675
+ t = a
676
+ while punc = lex.eql_lit?(ECMA262::PUNC_OR)
677
+ if b = bitwise_xor_exp(lex, context, options)
678
+ t = ECMA262::ExpOr.new(t, b)
679
+ else
680
+ raise ParseError.new("unexpceted token", lex)
580
681
  end
581
-
582
- t
583
- }
682
+ end
683
+ t
584
684
  end
585
685
  #
586
686
  # 11.11
587
687
  # a && b
588
688
  #
589
689
  def logical_and_exp(lex, context, options)
590
- lex.eval_lit {
591
- a = bitwise_or_exp(lex, context, options)
592
- next nil if !a
690
+ a = bitwise_or_exp(lex, context, options)
691
+ return nil if !a
593
692
 
594
- t = a
595
- while punc = lex.match_lit(ECMA262::PUNC_LAND)
596
- if b = bitwise_or_exp(lex, context, options)
597
- t = ECMA262::ExpLogicalAnd.new(t, b)
598
- else
599
- raise ParseError.new("unexpceted token", lex)
600
- end
693
+ t = a
694
+ while punc = lex.eql_lit?(ECMA262::PUNC_LAND)
695
+ if b = bitwise_or_exp(lex, context, options)
696
+ t = ECMA262::ExpLogicalAnd.new(t, b)
697
+ else
698
+ raise ParseError.new("unexpceted token", lex)
601
699
  end
700
+ end
602
701
 
603
- t
604
- }
702
+ t
605
703
  end
606
704
 
607
705
  def logical_or_exp(lex, context, options)
608
- lex.eval_lit {
609
- a = logical_and_exp(lex, context, options)
610
- next nil if !a
706
+ a = logical_and_exp(lex, context, options)
707
+ return nil if !a
611
708
 
612
- t = a
613
- while punc = lex.match_lit(ECMA262::PUNC_LOR)
614
- if b = logical_and_exp(lex, context, options)
615
- t = ECMA262::ExpLogicalOr.new(t, b)
616
- else
617
- raise ParseError.new("unexpceted token", lex)
618
- end
709
+ t = a
710
+ while punc = lex.eql_lit?(ECMA262::PUNC_LOR)
711
+ if b = logical_and_exp(lex, context, options)
712
+ t = ECMA262::ExpLogicalOr.new(t, b)
713
+ else
714
+ raise ParseError.new("unexpceted token", lex)
619
715
  end
716
+ end
620
717
 
621
- t
622
- }
718
+ t
623
719
  end
624
720
  #
625
721
  # 11.12
626
722
  # a ? b : c
627
723
  #
628
724
  def cond_exp(lex, context, options)
629
- t = lex.eval_lit {
630
- a = logical_or_exp(lex, context, options)
631
- next nil if !a
725
+ a = logical_or_exp(lex, context, options)
726
+ return nil if !a
632
727
 
633
- if lex.match_lit(ECMA262::PUNC_CONDIF)
634
- if b=assignment_exp(lex, context, options) and lex.match_lit(ECMA262::PUNC_CONDELSE) and c=assignment_exp(lex, context, options)
635
- ECMA262::ExpCond.new(a, b, c)
636
- else
637
- raise ParseError.new("unexpceted token", lex)
638
- end
728
+ if lex.eql_lit?(ECMA262::PUNC_CONDIF)
729
+ if b=assignment_exp(lex, context, options) and lex.eql_lit?(ECMA262::PUNC_COLON) and c=assignment_exp(lex, context, options)
730
+ ECMA262::ExpCond.new(a, b, c)
639
731
  else
640
- a
732
+ raise ParseError.new("unexpceted token", lex)
641
733
  end
642
- }
643
- t
734
+ else
735
+ a
736
+ end
644
737
  end
645
738
  #
646
739
  #11.13
740
+ # AssignmentExpression :
741
+ # ConditionalExpression
742
+ # LeftHandSideExpression = AssignmentExpression
743
+ # LeftHandSideExpression AssignmentOperator AssignmentExpression
647
744
  #
648
745
  def assignment_exp(lex, context, options)
649
746
  @logger.debug "*** assignment_exp"
650
747
 
651
- left_hand = nil
652
748
  t = cond_exp(lex, context, options)
653
749
  return nil if t.nil?
654
- lex.eval_lit {
655
- left_hand = t
656
- punc = lex.next_lit
657
- if punc == ECMA262::PUNC_LET ||
658
- punc == ECMA262::PUNC_DIVLET ||
659
- punc == ECMA262::PUNC_MULLET ||
660
- punc == ECMA262::PUNC_MODLET ||
661
- punc == ECMA262::PUNC_ADDLET ||
662
- punc == ECMA262::PUNC_SUBLET ||
663
- punc == ECMA262::PUNC_LSHIFTLET ||
664
- punc == ECMA262::PUNC_RSHIFTLET ||
665
- punc == ECMA262::PUNC_URSHIFTLET ||
666
- punc == ECMA262::PUNC_ANDLET ||
667
- punc == ECMA262::PUNC_ORLET ||
668
- punc == ECMA262::PUNC_XORLET
669
- lex.fwd_lit
670
- if b = assignment_exp(lex, context, options)
671
- case punc
672
- when ECMA262::PUNC_LET
673
- ECMA262::ExpAssign.new(left_hand, b)
674
- when ECMA262::PUNC_DIVLET
675
- ECMA262::ExpDivAssign.new(left_hand, b)
676
- when ECMA262::PUNC_MULLET
677
- ECMA262::ExpMulAssign.new(left_hand, b)
678
- when ECMA262::PUNC_MODLET
679
- ECMA262::ExpModAssign.new(left_hand, b)
680
- when ECMA262::PUNC_ADDLET
681
- ECMA262::ExpAddAssign.new(left_hand, b)
682
- when ECMA262::PUNC_SUBLET
683
- ECMA262::ExpSubAssign.new(left_hand, b)
684
- when ECMA262::PUNC_LSHIFTLET
685
- ECMA262::ExpLShiftAssign.new(left_hand, b)
686
- when ECMA262::PUNC_RSHIFTLET
687
- ECMA262::ExpRShiftAssign.new(left_hand, b)
688
- when ECMA262::PUNC_URSHIFTLET
689
- ECMA262::ExpURShiftAssign.new(left_hand, b)
690
- when ECMA262::PUNC_ANDLET
691
- ECMA262::ExpAndAssign.new(left_hand, b)
692
- when ECMA262::PUNC_ORLET
693
- ECMA262::ExpOrAssign.new(left_hand, b)
694
- when ECMA262::PUNC_XORLET
695
- ECMA262::ExpXorAssign.new(left_hand, b)
696
- else
697
- raise "internal error"
698
- end
750
+
751
+ if !t.left_hand_side_exp?
752
+ return t
753
+ end
754
+ left_hand = t
755
+ punc = lex.peek_lit(:div)
756
+ if punc == ECMA262::PUNC_LET ||
757
+ punc == ECMA262::PUNC_DIVLET ||
758
+ punc == ECMA262::PUNC_MULLET ||
759
+ punc == ECMA262::PUNC_MODLET ||
760
+ punc == ECMA262::PUNC_ADDLET ||
761
+ punc == ECMA262::PUNC_SUBLET ||
762
+ punc == ECMA262::PUNC_LSHIFTLET ||
763
+ punc == ECMA262::PUNC_RSHIFTLET ||
764
+ punc == ECMA262::PUNC_URSHIFTLET ||
765
+ punc == ECMA262::PUNC_ANDLET ||
766
+ punc == ECMA262::PUNC_ORLET ||
767
+ punc == ECMA262::PUNC_XORLET
768
+ lex.fwd_after_peek
769
+ if b = assignment_exp(lex, context, options)
770
+ case punc
771
+ when ECMA262::PUNC_LET
772
+ ECMA262::ExpAssign.new(left_hand, b)
773
+ when ECMA262::PUNC_DIVLET
774
+ ECMA262::ExpDivAssign.new(left_hand, b)
775
+ when ECMA262::PUNC_MULLET
776
+ ECMA262::ExpMulAssign.new(left_hand, b)
777
+ when ECMA262::PUNC_MODLET
778
+ ECMA262::ExpModAssign.new(left_hand, b)
779
+ when ECMA262::PUNC_ADDLET
780
+ ECMA262::ExpAddAssign.new(left_hand, b)
781
+ when ECMA262::PUNC_SUBLET
782
+ ECMA262::ExpSubAssign.new(left_hand, b)
783
+ when ECMA262::PUNC_LSHIFTLET
784
+ ECMA262::ExpLShiftAssign.new(left_hand, b)
785
+ when ECMA262::PUNC_RSHIFTLET
786
+ ECMA262::ExpRShiftAssign.new(left_hand, b)
787
+ when ECMA262::PUNC_URSHIFTLET
788
+ ECMA262::ExpURShiftAssign.new(left_hand, b)
789
+ when ECMA262::PUNC_ANDLET
790
+ ECMA262::ExpAndAssign.new(left_hand, b)
791
+ when ECMA262::PUNC_ORLET
792
+ ECMA262::ExpOrAssign.new(left_hand, b)
793
+ when ECMA262::PUNC_XORLET
794
+ ECMA262::ExpXorAssign.new(left_hand, b)
699
795
  else
700
- raise ParseError.new("unexpceted token", lex)
796
+ raise "internal error"
701
797
  end
702
798
  else
703
- @logger.debug {
704
- "*** assignment_exp => #{t ? t.to_js : t}"
705
- }
706
- t
799
+ raise ParseError.new("unexpceted token", lex)
707
800
  end
708
- }
801
+ else
802
+ @logger.debug {
803
+ "*** assignment_exp => #{t ? t.to_js : t}"
804
+ }
805
+ t
806
+ end
709
807
  end
710
808
 
711
809
  #
712
810
  # 11.14
811
+ # Expression :
812
+ # AssignmentExpression
813
+ # Expression , AssignmentExpression
713
814
  #
714
815
  def exp(lex, context, options)
715
816
  @logger.debug "*** expression"
716
- lex.eval_lit{
717
- t = assignment_exp(lex, context, {:hint => :regexp}.merge(options))
718
- while punc = lex.match_lit(ECMA262::PUNC_COMMA)
719
- if b = assignment_exp(lex,context, {:hint => :regexp}.merge(options))
720
- t = ECMA262::ExpComma.new(t, b)
721
- else
722
- raise ParseError.new("unexpceted token", lex)
723
- end
817
+
818
+ t = assignment_exp(lex, context, options)
819
+ return nil if t.nil?
820
+ while punc = lex.eql_lit?(ECMA262::PUNC_COMMA)
821
+ if b = assignment_exp(lex,context, options)
822
+ t = ECMA262::ExpComma.new(t, b)
823
+ else
824
+ raise ParseError.new("unexpceted token", lex)
724
825
  end
725
- @logger.debug{
726
- "*** expression => #{t ? t.to_js : t}"
727
- }
728
- t
826
+ end
827
+ @logger.debug{
828
+ "*** expression => #{t ? t.to_js : t}"
729
829
  }
830
+ t
730
831
  end
731
832
  end
732
833
  end