1 | <?php |
---|
2 | |
---|
3 | require_once('Parser.php'); |
---|
4 | require_once('JavaScriptSymbol.php'); |
---|
5 | |
---|
6 | class JavaScriptParser extends Parser { |
---|
7 | protected $symbol_class = JavaScriptSymbol; |
---|
8 | |
---|
9 | protected function build() { |
---|
10 | $this->symbol(';'); |
---|
11 | $this->symbol("\n"); |
---|
12 | $this->symbol(','); |
---|
13 | $this->symbol(')'); |
---|
14 | $this->symbol(']'); |
---|
15 | $this->symbol('}'); |
---|
16 | $this->symbol('else'); |
---|
17 | $this->symbol('case'); |
---|
18 | $this->symbol('default'); |
---|
19 | $this->symbol('catch'); |
---|
20 | $this->symbol('finally'); |
---|
21 | |
---|
22 | $symbol = $this->symbol(':'); |
---|
23 | $symbol->lbp = 'lbp_colon'; |
---|
24 | $symbol->led = 'led_colon'; |
---|
25 | |
---|
26 | $this->symbol('(end)'); |
---|
27 | $this->symbol('(name)'); |
---|
28 | |
---|
29 | $this->assignment('=')->led = 'led_equals'; |
---|
30 | $this->assignment('+='); |
---|
31 | $this->assignment('-='); |
---|
32 | $this->assignment('*='); |
---|
33 | $this->assignment('/='); |
---|
34 | $this->assignment('%='); |
---|
35 | $this->assignment('<<='); |
---|
36 | $this->assignment('>>='); |
---|
37 | $this->assignment('>>>='); |
---|
38 | $this->assignment('&='); |
---|
39 | $this->assignment('^='); |
---|
40 | $this->assignment('|='); |
---|
41 | |
---|
42 | $this->infix('?:', 20); |
---|
43 | $this->infixr('||', 21); |
---|
44 | $this->infixr('&&', 22); |
---|
45 | $this->infix('|', 23); |
---|
46 | $this->infix('^', 24); |
---|
47 | $this->infix('&', 25); |
---|
48 | |
---|
49 | $this->infix('==', 30); |
---|
50 | $this->infix('!=', 30); |
---|
51 | $this->infix('===', 30); |
---|
52 | $this->infix('!==', 30); |
---|
53 | |
---|
54 | $this->infix('<', 40); |
---|
55 | $this->infix('<=', 40); |
---|
56 | $this->infix('>', 40); |
---|
57 | $this->infix('>=', 40); |
---|
58 | $this->infix('in', 40); |
---|
59 | $this->infix('instanceof', 40); |
---|
60 | |
---|
61 | $this->infix('<<', 45); |
---|
62 | $this->infix('>>', 45); |
---|
63 | $this->infix('>>>', 45); |
---|
64 | |
---|
65 | $this->infix('+', 50); |
---|
66 | $this->infix('-', 50); |
---|
67 | |
---|
68 | $this->infix('*', 60); |
---|
69 | $this->infix('/', 60); |
---|
70 | $this->infix('%', 60); |
---|
71 | |
---|
72 | // prefix is 70 |
---|
73 | $this->prefix('!'); |
---|
74 | $this->prefix('~'); |
---|
75 | $this->prefix('+'); |
---|
76 | $this->prefix('-'); |
---|
77 | $this->prefix('typeof'); |
---|
78 | $this->prefix('void'); |
---|
79 | $this->prefix('delete'); |
---|
80 | $this->prefix('throw'); |
---|
81 | |
---|
82 | // crement is 75 |
---|
83 | $symbol = $this->symbol('++'); |
---|
84 | $symbol->lbp = 'lbp_crement'; |
---|
85 | $symbol->led = 'led_crement'; |
---|
86 | $symbol->nud = 'nud_crement'; |
---|
87 | $symbol = $this->symbol('--'); |
---|
88 | $symbol->lbp = 'lbp_crement'; |
---|
89 | $symbol->led = 'led_crement'; |
---|
90 | $symbol->nud = 'nud_crement'; |
---|
91 | |
---|
92 | $this->infix('(', 80, 'led_parenthesis')->nud = 'nud_parenthesis'; |
---|
93 | |
---|
94 | $this->infix('.', 85, 'led_period'); |
---|
95 | $this->infix('[', 85, 'led_bracket'); |
---|
96 | $this->prefix('new')->lbp = 85; |
---|
97 | |
---|
98 | // Non-defined stuff: |
---|
99 | |
---|
100 | $this->infix('?', 20, 'led_questionmark'); |
---|
101 | |
---|
102 | $this->constant('true', TRUE); |
---|
103 | $this->constant('false', FALSE); |
---|
104 | $this->constant('null', 'null'); |
---|
105 | $this->constant('undefined', NULL); |
---|
106 | $this->constant('arguments', 'arguments'); |
---|
107 | |
---|
108 | $this->symbol('(literal)')->nud = 'nud_itself'; |
---|
109 | |
---|
110 | $this->stmt('{', 'std_curly'); |
---|
111 | $this->stmt('var', 'std_var'); |
---|
112 | $this->stmt('do', 'std_do'); |
---|
113 | $this->stmt('while', 'std_while'); |
---|
114 | $this->stmt('for', 'std_for'); |
---|
115 | $this->stmt('if', 'std_if'); |
---|
116 | $this->stmt('switch', 'std_switch'); |
---|
117 | $this->stmt('try', 'std_try'); |
---|
118 | $this->stmt('break', 'std_break'); |
---|
119 | $this->stmt('return', 'std_return'); |
---|
120 | $this->stmt('function', 'nud_function'); |
---|
121 | $this->prefix('function', 'nud_function'); |
---|
122 | |
---|
123 | $symbol = $this->symbol('this'); |
---|
124 | $symbol->nud = 'nud_this'; |
---|
125 | |
---|
126 | $this->prefix('[', 'nud_bracket'); |
---|
127 | $this->prefix('{', 'nud_curly'); |
---|
128 | } |
---|
129 | } |
---|