Module: Minjs::Exp

Included in:
Compressor
Defined in:
lib/minjs/expression.rb

Instance Method Summary collapse

Instance Method Details

#additive_exp(lex, context, options) ⇒ Object

11.6



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/minjs/expression.rb', line 402

def additive_exp(lex, context, options)
  lex.eval_lit {
    a = multiplicative_exp(lex, context, options)
    next nil if !a

    t = a
    while punc = lex.match_lit(ECMA262::PUNC_ADD) || lex.match_lit(ECMA262::PUNC_SUB)
      if b = multiplicative_exp(lex, context, options)
        if punc == ECMA262::PUNC_ADD
          t = ECMA262::ExpAdd.new(t, b)
        else
          t = ECMA262::ExpSub.new(t, b)
        end
      else
        raise ParseError.new("unexpceted token", lex)
      end
    end

    t
  }
end

#arguments(lex, context, options) ⇒ Object



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/minjs/expression.rb', line 286

def arguments(lex, context, options)
  lex.eval_lit{
    return nil if lex.match_lit(ECMA262::PUNC_LPARENTHESIS).nil?
    next [] if lex.match_lit(ECMA262::PUNC_RPARENTHESIS)
    args = []
    while true
      if t = assignment_exp(lex, context, options)
        args.push(t)
      else
        return
      end
      if lex.match_lit(ECMA262::PUNC_COMMA)
        ;
      elsif lex.match_lit(ECMA262::PUNC_RPARENTHESIS)
        break
      else
        return
      end
    end
    args
  }
end

#array_literal(lex, context, options) ⇒ Object

11.1.4



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/minjs/expression.rb', line 57

def array_literal(lex, context, options)
  return nil unless lex.match_lit(ECMA262::PUNC_LSQBRAC)
  t = []
  lex.eval_lit {
    while true
      if lex.match_lit(ECMA262::PUNC_COMMA)
        t.push(nil)
      elsif lex.match_lit(ECMA262::PUNC_RSQBRAC)
        break
      elsif a = assignment_exp(lex, context, {})
        t.push(a)
        lex.match_lit(ECMA262::PUNC_COMMA)
      else
        raise ParseError.new("no `]' end of array", lex)
      end
    end
    ECMA262::ECMA262Array.new(t)
  }
end

#assignment_exp(lex, context, options) ⇒ Object

11.13



648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
# File 'lib/minjs/expression.rb', line 648

def assignment_exp(lex, context, options)
  @logger.debug "*** assignment_exp"

  left_hand = nil
  t = cond_exp(lex, context, options)
  return nil if t.nil?
  lex.eval_lit {
    left_hand = t
    punc = lex.next_lit
    if punc == ECMA262::PUNC_LET ||
       punc == ECMA262::PUNC_DIVLET ||
       punc == ECMA262::PUNC_MULLET ||
       punc == ECMA262::PUNC_MODLET ||
       punc == ECMA262::PUNC_ADDLET ||
       punc == ECMA262::PUNC_SUBLET ||
       punc == ECMA262::PUNC_LSHIFTLET ||
       punc == ECMA262::PUNC_RSHIFTLET ||
       punc == ECMA262::PUNC_URSHIFTLET ||
       punc == ECMA262::PUNC_ANDLET ||
       punc == ECMA262::PUNC_ORLET ||
       punc == ECMA262::PUNC_XORLET
      lex.fwd_lit
      if b = assignment_exp(lex, context, options)
        case punc
        when ECMA262::PUNC_LET
          ECMA262::ExpAssign.new(left_hand, b)
        when ECMA262::PUNC_DIVLET
          ECMA262::ExpDivAssign.new(left_hand, b)
        when ECMA262::PUNC_MULLET
          ECMA262::ExpMulAssign.new(left_hand, b)
        when ECMA262::PUNC_MODLET
          ECMA262::ExpModAssign.new(left_hand, b)
        when ECMA262::PUNC_ADDLET
          ECMA262::ExpAddAssign.new(left_hand, b)
        when ECMA262::PUNC_SUBLET
          ECMA262::ExpSubAssign.new(left_hand, b)
        when ECMA262::PUNC_LSHIFTLET
          ECMA262::ExpLShiftAssign.new(left_hand, b)
        when ECMA262::PUNC_RSHIFTLET
          ECMA262::ExpRShiftAssign.new(left_hand, b)
        when ECMA262::PUNC_URSHIFTLET
          ECMA262::ExpURShiftAssign.new(left_hand, b)
        when ECMA262::PUNC_ANDLET
          ECMA262::ExpAndAssign.new(left_hand, b)
        when ECMA262::PUNC_ORLET
          ECMA262::ExpOrAssign.new(left_hand, b)
        when ECMA262::PUNC_XORLET
          ECMA262::ExpXorAssign.new(left_hand, b)
        else
          raise "internal error"
        end
      else
        raise ParseError.new("unexpceted token", lex)
      end
    else
      @logger.debug {
        "*** assignment_exp => #{t ? t.to_js : t}"
      }
      t
    end
  }
end

#bitwise_and_exp(lex, context, options) ⇒ Object

11.10 a & b



526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/minjs/expression.rb', line 526

def bitwise_and_exp(lex, context, options)
  lex.eval_lit {
    a = equality_exp(lex, context, options)
    next nil if !a

    t = a
    while punc = lex.match_lit(ECMA262::PUNC_AND)
      if b = equality_exp(lex, context, options)
        t = ECMA262::ExpAnd.new(t, b)
      else
        raise ParseError.new("unexpceted token", lex)
      end
    end

    t
  }
end

#bitwise_or_exp(lex, context, options) ⇒ Object

a | b



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'lib/minjs/expression.rb', line 568

def bitwise_or_exp(lex, context, options)
  lex.eval_lit {
    a = bitwise_xor_exp(lex, context, options)
    next nil if !a

    t = a
    while punc = lex.match_lit(ECMA262::PUNC_OR)
      if b = bitwise_xor_exp(lex, context, options)
        t = ECMA262::ExpOr.new(t, b)
      else
        raise ParseError.new("unexpceted token", lex)
      end
    end

    t
  }
end

#bitwise_xor_exp(lex, context, options) ⇒ Object

a ^ b



547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/minjs/expression.rb', line 547

def bitwise_xor_exp(lex, context, options)
  lex.eval_lit {
    a = bitwise_and_exp(lex, context, options)
    next nil if !a

    t = a
    while punc = lex.match_lit(ECMA262::PUNC_XOR)
      if b = bitwise_and_exp(lex, context, options)
        t = ECMA262::ExpXor.new(t, b)
      else
        raise ParseError.new("unexpceted token", lex)
      end
    end

    t
  }
end

#call_exp(lex, context, options) ⇒ Object

call

member_exp arguments

call_exp arguments call_exp [exp] call_exp . identifier_name



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/minjs/expression.rb', line 199

def call_exp(lex, context, options)
  a = lex.eval_lit{
    if f = member_exp(lex, context, options)
      if b = arguments(lex, context, options)
        ECMA262::ExpCall.new(f, b)
      else
        f
      end
    else
      nil
    end
  }
  return nil if a.nil?

  t = a

  lex.eval_lit{
    while true
      if b=arguments(lex, context, options)
        t = ECMA262::ExpCall.new(t, b)
      elsif lex.match_lit(ECMA262::PUNC_LSQBRAC)
        if b=exp(lex, context, options) and lex.match_lit(ECMA262::PUNC_RSQBRAC)
          t = ECMA262::ExpPropBrac.new(t, b)
        else
          raise ParseError.new("unexpceted token", lex)
        end
      elsif lex.match_lit(ECMA262::PUNC_PERIOD)
        if (b=lex.fwd_lit()).kind_of?(ECMA262::IdentifierName)
          t = ECMA262::ExpProp.new(t, b)
        else
          raise ParseError.new("unexpceted token", lex)
        end
      else
        break
      end
    end
    t
  } or a
end

#cond_exp(lex, context, options) ⇒ Object

11.12 a ? b : c



628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# File 'lib/minjs/expression.rb', line 628

def cond_exp(lex, context, options)
  t = lex.eval_lit {
    a = logical_or_exp(lex, context, options)
    next nil if !a

    if lex.match_lit(ECMA262::PUNC_CONDIF)
      if b=assignment_exp(lex, context, options) and lex.match_lit(ECMA262::PUNC_CONDELSE) and c=assignment_exp(lex, context, options)
        ECMA262::ExpCond.new(a, b, c)
      else
        raise ParseError.new("unexpceted token", lex)
      end
    else
      a
    end
  }
  t
end

#equality_exp(lex, context, options) ⇒ Object

11.9 a == b a != b a === b a !== b



493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/minjs/expression.rb', line 493

def equality_exp(lex, context, options)
  lex.eval_lit {
    a = relational_exp(lex, context, options)
    next nil if !a

    t = a
    while punc = lex.match_lit(ECMA262::PUNC_EQ) ||
                 lex.match_lit(ECMA262::PUNC_NEQ) ||
                 lex.match_lit(ECMA262::PUNC_SEQ) ||
                 lex.match_lit(ECMA262::PUNC_SNEQ)
      if b = relational_exp(lex, context, options)
        if punc == ECMA262::PUNC_EQ
          t = ECMA262::ExpEq.new(t, b)
        elsif punc == ECMA262::PUNC_NEQ
          t = ECMA262::ExpNotEq.new(t, b)
        elsif punc == ECMA262::PUNC_SEQ
          t = ECMA262::ExpStrictEq.new(t, b)
        elsif punc == ECMA262::PUNC_SNEQ
          t = ECMA262::ExpStrictNotEq.new(t, b)
        end
      else
        raise ParseError.new("unexpceted token", lex)
      end
    end

    t
  }
end

#exp(lex, context, options) ⇒ Object

11.14



714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
# File 'lib/minjs/expression.rb', line 714

def exp(lex, context, options)
  @logger.debug "*** expression"
  lex.eval_lit{
    t = assignment_exp(lex, context, {:hint => :regexp}.merge(options))
    while punc = lex.match_lit(ECMA262::PUNC_COMMA)
      if b = assignment_exp(lex,context, {:hint => :regexp}.merge(options))
        t = ECMA262::ExpComma.new(t, b)
      else
        raise ParseError.new("unexpceted token", lex)
      end
    end
    @logger.debug{
      "*** expression => #{t ? t.to_js : t}"
    }
    t
  }
end

#identifier(lex, context) ⇒ Object

11.1.2



43
44
45
46
47
48
49
50
51
52
# File 'lib/minjs/expression.rb', line 43

def identifier(lex, context)
  lex.eval_lit {
    if (a = lex.fwd_lit).kind_of? ECMA262::IdentifierName and !a.reserved?
      a.context = context
      a
    else
      nil
    end
  }
end

#left_hand_side_exp(lex, context, options) ⇒ Object

11.2



159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/minjs/expression.rb', line 159

def left_hand_side_exp(lex, context, options)
  @logger.debug "*** left_hand_side_exp"

  t = lex.eval_lit{
    call_exp(lex, context, options)
  } || lex.eval_lit{
    new_exp(lex, context, options)
  }
  @logger.debug{
    "*** left_hand_side_exp => #{t ? t.to_js: t}"
  }
  t
end

#logical_and_exp(lex, context, options) ⇒ Object

11.11 a && b



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
# File 'lib/minjs/expression.rb', line 589

def logical_and_exp(lex, context, options)
  lex.eval_lit {
    a = bitwise_or_exp(lex, context, options)
    next nil if !a

    t = a
    while punc = lex.match_lit(ECMA262::PUNC_LAND)
      if b = bitwise_or_exp(lex, context, options)
        t = ECMA262::ExpLogicalAnd.new(t, b)
      else
        raise ParseError.new("unexpceted token", lex)
      end
    end

    t
  }
end

#logical_or_exp(lex, context, options) ⇒ Object



607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
# File 'lib/minjs/expression.rb', line 607

def logical_or_exp(lex, context, options)
  lex.eval_lit {
    a = logical_and_exp(lex, context, options)
    next nil if !a

    t = a
    while punc = lex.match_lit(ECMA262::PUNC_LOR)
      if b = logical_and_exp(lex, context, options)
        t = ECMA262::ExpLogicalOr.new(t, b)
      else
        raise ParseError.new("unexpceted token", lex)
      end
    end

    t
  }
end

#member_exp(lex, context, options) ⇒ Object

member_exp

primary_exp
function_exp
new member_exp arguments

member_exp[exp]
member_exp.identifier_name #prop(a,b)


248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/minjs/expression.rb', line 248

def member_exp(lex, context, options)
  a = lex.eval_lit {
    primary_exp(lex, context, options)
  } || lex.eval_lit {
    func_exp(lex, context)
  } || lex.eval_lit {
    if lex.match_lit(ECMA262::ID_NEW) and a=member_exp(lex, context, options) and b=arguments(lex, context, options)
      ECMA262::ExpNew.new(a, b)
    else
      nil
    end
  }
  return nil if a.nil?

  t = a

  lex.eval_lit {
    while true
      if lex.match_lit(ECMA262::PUNC_LSQBRAC)
        if b=exp(lex, context, options) and lex.match_lit(ECMA262::PUNC_RSQBRAC)
          t = ECMA262::ExpPropBrac.new(t, b)
        else
          raise ParseError.new("unexpceted token", lex)
        end
      elsif lex.match_lit(ECMA262::PUNC_PERIOD)
        if (b=lex.fwd_lit()).kind_of?(ECMA262::IdentifierName)
          t = ECMA262::ExpProp.new(t, b)
        else
          raise ParseError.new("unexpceted token", lex)
        end
      else
        break
      end
    end
    t
  } or a
end

#multiplicative_exp(lex, context, options) ⇒ Object

11.5



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/minjs/expression.rb', line 374

def multiplicative_exp(lex, context, options)
  lex.eval_lit {
    a = unary_exp(lex, context, options)
    next nil if !a
    t = a
    while punc = lex.match_lit(ECMA262::PUNC_MUL) ||
                 lex.match_lit(ECMA262::PUNC_DIV, :hint => :div) ||
                 lex.match_lit(ECMA262::PUNC_MOD)

      if b = unary_exp(lex, context, options)
        if punc == ECMA262::PUNC_MUL
          t = ECMA262::ExpMul.new(t, b)
        elsif punc == ECMA262::PUNC_DIV
          t = ECMA262::ExpDiv.new(t, b)
        else
          t = ECMA262::ExpMod.new(t, b)
        end
      else
        raise ParseError.new("unexpceted token", lex)
      end
    end
    t
  }
end

#new_exp(lex, context, options) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/minjs/expression.rb', line 173

def new_exp(lex, context, options)
  lex.eval_lit{
    if lex.match_lit(ECMA262::ID_NEW)
      if a=new_exp(lex, context, options)
        ECMA262::ExpNew.new(a, nil)
      else
        raise ParseError.new("unexpceted token", lex)
      end
    else
      nil
    end
  } or lex.eval_lit{
    member_exp(lex, context, options)
  }
end

#object_literal(lex, context, options) ⇒ Object

11.1.5



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/minjs/expression.rb', line 79

def object_literal(lex, context, options)
  return nil unless lex.match_lit(ECMA262::PUNC_LCURLYBRAC)
  lex.eval_lit {
    if lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
      next ECMA262::ECMA262Object.new([])
    end
    if h=property_name_and_value_list(lex, context, options)
      ECMA262::ECMA262Object.new(h)
    else
      raise ParseError.new("no `}' end of object", lex)
    end
  }
end

#postfix_exp(lex, context, options) ⇒ Object

11.3



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/minjs/expression.rb', line 311

def postfix_exp(lex, context, options)
  t = lex.eval_lit{
    a = left_hand_side_exp(lex, context, options)
    return nil if a.nil?
    if punc = (lex.match_lit(ECMA262::PUNC_INC, :nolt => true) ||
               lex.match_lit(ECMA262::PUNC_DEC, :nolt => true))
      if punc == ECMA262::PUNC_INC
        ECMA262::ExpPostInc.new(a)
      else
        ECMA262::ExpPostDec.new(a)
      end
    else
      a
    end
  }
  t
end

#primary_exp(lex, context, options) ⇒ Object

Primary Expressions 11.1



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/minjs/expression.rb', line 7

def primary_exp(lex, context, options)
  @logger.debug "*** primary_exp"

  if lex.match_lit(ECMA262::ID_THIS)
  @logger.debug "*** primary_exp => this"
    return ECMA262::ID_THIS
  end
  # (exp)
  if lex.match_lit(ECMA262::PUNC_LPARENTHESIS)
    if a=exp(lex, context, options) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS)
      @logger.debug "*** primary_exp => ()"
      return ECMA262::ExpParen.new(a)
    else
      raise ParseError.new("no `)' at end of expression", lex)
    end
  end

  # identifier || literal || array_literal || object_literal
  t = lex.eval_lit {
    identifier(lex, context)
  } || lex.eval_lit {
    literal(lex, context)
  } || lex.eval_lit {
    array_literal(lex, context, options)
  } || lex.eval_lit {
    object_literal(lex, context, options)
  }
  @logger.debug {
    "*** primary_exp => #{t ? t.to_js : t}"
  }
  t
end

#property_name(lex, context) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/minjs/expression.rb', line 130

def property_name(lex, context)
  lex.eval_lit {
    a = lex.fwd_lit
    if a.kind_of?(ECMA262::ECMA262String)
      a
    elsif a.kind_of?(ECMA262::IdentifierName)
      ECMA262::ECMA262String.new(a.to_js)
    elsif a.kind_of?(ECMA262::ECMA262Numeric)
      a
    else
      nil
    end
  }
end

#property_name_and_value_list(lex, context, options) ⇒ Object

name: exp get name()funcbody set name(args)funcbody



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/minjs/expression.rb', line 98

def property_name_and_value_list(lex, context, options)
  lex.eval_lit{
    h = []
    while !lex.eof?
      if lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
        break
      end
      lex.eval_lit{
        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)
          h.push([a, ECMA262::StFunc.new(context, ECMA262::ID_GET, [], b, :getter => true)])
        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)
          h.push([a, ECMA262::StFunc.new(context, ECMA262::ID_SET, arg, b, :setter => true)])
        else
          nil
        end
      } or lex.eval_lit{
        a=property_name(lex, context) and lex.match_lit(ECMA262::PUNC_COLON) and b=assignment_exp(lex, context, options)
        h.push([a, b])
      }

      if lex.match_lit(ECMA262::PUNC_COMMA)
        break if lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
      elsif lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
        break
      else
        raise ParseError.new("no `}' end of object", lex)
      end
    end
    h
  }
end

#property_set_parameter_list(lex, context) ⇒ Object



145
146
147
148
149
150
151
152
153
154
# File 'lib/minjs/expression.rb', line 145

def property_set_parameter_list(lex, context)
  lex.eval_lit {
    a = lex.fwd_lit
    if a.kind_of?(ECMA262::IdentifierName) and !a.reserved?
      [a]
    else
      nil
    end
  }
end

#relational_exp(lex, context, options) ⇒ Object

11.8



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/minjs/expression.rb', line 453

def relational_exp(lex, context, options)
  lex.eval_lit {
    a = shift_exp(lex, context, options)
    next nil if !a

    t = a
    while (punc = lex.match_lit(ECMA262::PUNC_LT) || lex.match_lit(ECMA262::PUNC_GT) ||
                  lex.match_lit(ECMA262::PUNC_LTEQ) || lex.match_lit(ECMA262::PUNC_GTEQ) ||
                  lex.match_lit(ECMA262::ID_INSTANCEOF) || (!options[:no_in] && lex.match_lit(ECMA262::ID_IN)))
      if b = shift_exp(lex, context, options)
        if punc == ECMA262::PUNC_LT
          t = ECMA262::ExpLt.new(t, b)
        elsif punc == ECMA262::PUNC_GT
          t = ECMA262::ExpGt.new(t, b)
        elsif punc == ECMA262::PUNC_LTEQ
          t = ECMA262::ExpLtEq.new(t, b)
        elsif punc == ECMA262::PUNC_GTEQ
          t = ECMA262::ExpGtEq.new(t, b)
        elsif punc.val == :instanceof
          t = ECMA262::ExpInstanceOf.new(t, b)
        elsif !options[:no_in] and punc.val == :in
          t = ECMA262::ExpIn.new(t, b)
        else
        end
      else
        raise ParseError.new("unexpceted token", lex)
      end
    end

    t
  }
end

#shift_exp(lex, context, options) ⇒ Object

11.7



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/minjs/expression.rb', line 425

def shift_exp(lex, context, options)
  lex.eval_lit {
    a = additive_exp(lex, context, options)
    next nil if !a

    t = a
    while punc = lex.match_lit(ECMA262::PUNC_LSHIFT) ||
                 lex.match_lit(ECMA262::PUNC_RSHIFT) ||
                 lex.match_lit(ECMA262::PUNC_URSHIFT)
      if b = additive_exp(lex, context, options)
        if punc == ECMA262::PUNC_LSHIFT
          t = ECMA262::ExpLShift.new(t, b)
        elsif punc == ECMA262::PUNC_RSHIFT
          t = ECMA262::ExpRShift.new(t, b)
        elsif punc == ECMA262::PUNC_URSHIFT
          t = ECMA262::ExpURShift.new(t, b)
        end
      else
        raise ParseError.new("unexpceted token", lex)
      end
    end
    t
  }
end

#unary_exp(lex, context, options) ⇒ Object

11.4



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/minjs/expression.rb', line 332

def unary_exp(lex, context, options)
  lex.eval_lit{
    if punc = (lex.match_lit(ECMA262::ID_DELETE) ||
               lex.match_lit(ECMA262::ID_VOID) ||
               lex.match_lit(ECMA262::ID_TYPEOF) ||
               lex.match_lit(ECMA262::PUNC_INC) ||
               lex.match_lit(ECMA262::PUNC_DEC) ||
               lex.match_lit(ECMA262::PUNC_ADD) ||
               lex.match_lit(ECMA262::PUNC_SUB) ||
               lex.match_lit(ECMA262::PUNC_NOT) ||
               lex.match_lit(ECMA262::PUNC_LNOT))
      a = unary_exp(lex, context, options)
      if a.nil?
        raise ParseError.new("unexpceted token", lex)
      elsif punc.val == :delete
        ECMA262::ExpDelete.new(a)
      elsif punc.val == :void
        ECMA262::ExpVoid.new(a)
      elsif punc.val == :typeof
        ECMA262::ExpTypeof.new(a)
      elsif punc == ECMA262::PUNC_INC
        ECMA262::ExpPreInc.new(a)
      elsif punc == ECMA262::PUNC_DEC
        ECMA262::ExpPreDec.new(a)
      elsif punc == ECMA262::PUNC_ADD
        ECMA262::ExpPositive.new(a)
      elsif punc == ECMA262::PUNC_SUB
        ECMA262::ExpNegative.new(a)
      elsif punc == ECMA262::PUNC_NOT
        ECMA262::ExpBitwiseNot.new(a)
      elsif punc == ECMA262::PUNC_LNOT
        ECMA262::ExpLogicalNot.new(a)
      end
    end
  } || lex.eval_lit{
    postfix_exp(lex, context, options)
  }
end