]> git.saurik.com Git - cycript.git/blame - Parser.hpp
Avoid error caused by passing -pthread to libtool.
[cycript.git] / Parser.hpp
CommitLineData
b3378a02 1/* Cycript - Optimizing JavaScript Compiler/Runtime
f95d2598 2 * Copyright (C) 2009-2014 Jay Freeman (saurik)
b4aa79af
JF
3*/
4
f95d2598 5/* GNU Affero General Public License, Version 3 {{{ */
b4aa79af 6/*
f95d2598
JF
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c15969fd 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f95d2598
JF
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b3378a02 19**/
b4aa79af
JF
20/* }}} */
21
c5fa2867
JF
22#ifndef CYCRIPT_PARSER_HPP
23#define CYCRIPT_PARSER_HPP
63b4c5a8 24
4de0686f
JF
25#include <iostream>
26
5999c315 27#include <string>
c3c20102 28#include <vector>
029bc65b
JF
29#include <map>
30#include <set>
cf7d4c69 31
a4dbf05b 32#include <cstdio>
4de0686f
JF
33#include <cstdlib>
34
da2af935 35#include "List.hpp"
00b4cb83 36#include "Location.hpp"
5999c315 37#include "Pooling.hpp"
029bc65b
JF
38#include "Options.hpp"
39
01d0f64d 40struct CYContext;
924f67b2 41
5999c315 42struct CYThing {
7c6c5b0a
JF
43 virtual ~CYThing() {
44 }
45
652ec1ba 46 virtual void Output(struct CYOutput &out) const = 0;
5999c315
JF
47};
48
652ec1ba
JF
49struct CYOutput {
50 std::ostream &out_;
029bc65b 51 CYOptions &options_;
11c1cc16
JF
52 bool pretty_;
53 unsigned indent_;
320ce753 54 bool right_;
652ec1ba 55
96a7e5c2
JF
56 enum {
57 NoMode,
58 NoLetter,
c0bc320e 59 NoPlus,
96a7e5c2
JF
60 NoHyphen,
61 Terminated
62 } mode_;
63
029bc65b 64 CYOutput(std::ostream &out, CYOptions &options) :
11c1cc16 65 out_(out),
029bc65b 66 options_(options),
11c1cc16 67 pretty_(false),
96a7e5c2 68 indent_(0),
320ce753 69 right_(false),
96a7e5c2 70 mode_(NoMode)
652ec1ba
JF
71 {
72 }
73
96a7e5c2 74 void Check(char value);
1fdca2fa 75 void Terminate();
652ec1ba 76
96a7e5c2
JF
77 CYOutput &operator <<(char rhs);
78 CYOutput &operator <<(const char *rhs);
79
80 _finline CYOutput &operator <<(const CYThing *rhs) {
81 if (rhs != NULL)
82 rhs->Output(*this);
652ec1ba
JF
83 return *this;
84 }
85
86 _finline CYOutput &operator <<(const CYThing &rhs) {
87 rhs.Output(*this);
88 return *this;
89 }
90};
5999c315 91
e5bc40db 92struct CYPropertyName {
652ec1ba 93 virtual void PropertyName(CYOutput &out) const = 0;
7c6c5b0a
JF
94
95 virtual ~CYPropertyName() {
96 }
e5bc40db
JF
97};
98
3b52fd1a 99struct CYExpression;
ae65d594 100struct CYAssignment;
3b52fd1a
JF
101
102enum CYNeeded {
103 CYNever = -1,
104 CYSometimes = 0,
105 CYAlways = 1,
106};
107
108enum CYFlags {
109 CYNoFlags = 0,
110 CYNoBrace = (1 << 0),
111 CYNoFunction = (1 << 1),
112 CYNoIn = (1 << 2),
113 CYNoCall = (1 << 3),
114 CYNoRightHand = (1 << 4),
115 CYNoDangle = (1 << 5),
9561f209 116 CYNoInteger = (1 << 6),
3b52fd1a
JF
117 CYNoBF = (CYNoBrace | CYNoFunction),
118};
119
5a6d4d25
JF
120_finline CYFlags operator ~(CYFlags rhs) {
121 return static_cast<CYFlags>(~static_cast<unsigned>(rhs));
122}
123
124_finline CYFlags operator &(CYFlags lhs, CYFlags rhs) {
125 return static_cast<CYFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs));
126}
127
128_finline CYFlags operator |(CYFlags lhs, CYFlags rhs) {
129 return static_cast<CYFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs));
130}
131
132_finline CYFlags &operator |=(CYFlags &lhs, CYFlags rhs) {
133 return lhs = lhs | rhs;
134}
135
136_finline CYFlags CYLeft(CYFlags flags) {
137 return flags & ~(CYNoDangle | CYNoInteger);
138}
139
140_finline CYFlags CYRight(CYFlags flags) {
141 return flags & ~CYNoBF;
142}
143
144_finline CYFlags CYCenter(CYFlags flags) {
145 return CYLeft(CYRight(flags));
146}
147
3b52fd1a
JF
148struct CYStatement :
149 CYNext<CYStatement>
150{
7c6c5b0a
JF
151 virtual ~CYStatement() {
152 }
153
3b52fd1a
JF
154 void Single(CYOutput &out, CYFlags flags) const;
155 void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
156
3b52fd1a
JF
157 virtual CYStatement *Replace(CYContext &context) = 0;
158
159 private:
160 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
161};
162
163struct CYStatements {
164 CYStatement *first_;
165 CYStatement *last_;
166
167 CYStatements() :
168 first_(NULL),
169 last_(NULL)
170 {
171 }
172
173 operator CYStatement *() const {
174 return first_;
175 }
176
177 CYStatements &operator ->*(CYStatement *next) {
178 if (next != NULL)
179 if (first_ == NULL) {
180 first_ = next;
181 last_ = next;
182 } else for (;; last_ = last_->next_)
183 if (last_->next_ == NULL) {
184 last_->next_ = next;
185 last_ = next;
186 break;
187 }
188 return *this;
189 }
190};
191
e5bc40db 192struct CYClassName {
7c6c5b0a
JF
193 virtual ~CYClassName() {
194 }
195
3b52fd1a 196 virtual CYExpression *ClassName(CYContext &context, bool object) = 0;
652ec1ba 197 virtual void ClassName(CYOutput &out, bool object) const = 0;
63b4c5a8
JF
198};
199
cf7d4c69 200struct CYWord :
e5bc40db
JF
201 CYThing,
202 CYPropertyName,
203 CYClassName
63b4c5a8 204{
cf7d4c69
JF
205 const char *word_;
206
207 CYWord(const char *word) :
208 word_(word)
209 {
210 }
211
029bc65b
JF
212 void Set(const char *value) {
213 word_ = value;
cf7d4c69
JF
214 }
215
029bc65b 216 virtual const char *Word() const;
652ec1ba 217 virtual void Output(CYOutput &out) const;
e5bc40db 218
3b52fd1a 219 virtual CYExpression *ClassName(CYContext &context, bool object);
652ec1ba
JF
220 virtual void ClassName(CYOutput &out, bool object) const;
221 virtual void PropertyName(CYOutput &out) const;
63b4c5a8
JF
222};
223
652ec1ba 224_finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) {
029bc65b
JF
225 lhs << &rhs << '=';
226 return lhs << rhs.Word();
652ec1ba
JF
227}
228
cf7d4c69 229struct CYIdentifier :
14ec9e00 230 CYNext<CYIdentifier>,
cf7d4c69 231 CYWord
63b4c5a8 232{
029bc65b 233 CYIdentifier *replace_;
6a981250 234 size_t offset_;
e013809d 235 size_t usage_;
029bc65b 236
5999c315 237 CYIdentifier(const char *word) :
029bc65b 238 CYWord(word),
6a981250 239 replace_(NULL),
e013809d
JF
240 offset_(0),
241 usage_(0)
5999c315 242 {
cf7d4c69 243 }
029bc65b
JF
244
245 virtual const char *Word() const;
246 CYIdentifier *Replace(CYContext &context);
63b4c5a8
JF
247};
248
320ce753
JF
249struct CYComment :
250 CYStatement
251{
252 const char *value_;
253
254 CYComment(const char *value) :
255 value_(value)
256 {
257 }
258
259 virtual CYStatement *Replace(CYContext &context);
260 virtual void Output(CYOutput &out, CYFlags flags) const;
261};
262
62014ea9 263struct CYLabel :
3b52fd1a 264 CYStatement
62014ea9 265{
9e562cfc 266 CYIdentifier *name_;
3b52fd1a 267 CYStatement *statement_;
cf7d4c69 268
3b52fd1a
JF
269 CYLabel(CYIdentifier *name, CYStatement *statement) :
270 name_(name),
271 statement_(statement)
cf7d4c69
JF
272 {
273 }
fb98ac0c 274
3b52fd1a
JF
275 virtual CYStatement *Replace(CYContext &context);
276 virtual void Output(CYOutput &out, CYFlags flags) const;
fb98ac0c
JF
277};
278
14ec9e00 279struct CYCStringLess :
029bc65b
JF
280 std::binary_function<const char *, const char *, bool>
281{
282 _finline bool operator ()(const char *lhs, const char *rhs) const {
283 return strcmp(lhs, rhs) < 0;
284 }
285};
286
287struct CYIdentifierValueLess :
288 std::binary_function<CYIdentifier *, CYIdentifier *, bool>
289{
290 _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const {
14ec9e00 291 return CYCStringLess()(lhs->Word(), rhs->Word());
029bc65b
JF
292 }
293};
294
295enum CYIdentifierFlags {
296 CYIdentifierArgument,
14ec9e00
JF
297 CYIdentifierVariable,
298 CYIdentifierOther,
299 CYIdentifierMagic,
daf22a65 300 CYIdentifierCatch,
029bc65b
JF
301};
302
14ec9e00 303typedef std::set<const char *, CYCStringLess> CYCStringSet;
029bc65b 304typedef std::set<CYIdentifier *, CYIdentifierValueLess> CYIdentifierValueSet;
029bc65b
JF
305typedef std::map<CYIdentifier *, CYIdentifierFlags> CYIdentifierAddressFlagsMap;
306
e013809d
JF
307struct CYIdentifierUsage {
308 CYIdentifier *identifier_;
309 size_t usage_;
310};
311
312typedef std::vector<CYIdentifierUsage> CYIdentifierUsageVector;
313
029bc65b 314struct CYScope {
61fe0c53 315 bool transparent_;
daf22a65
JF
316
317 CYContext &context_;
318 CYStatement *&statements_;
319
029bc65b 320 CYScope *parent_;
a86e34d0 321
a846a8cd 322 CYIdentifierAddressFlagsMap internal_;
a86e34d0 323 CYIdentifierValueSet identifiers_;
029bc65b 324
61fe0c53 325 CYScope(bool transparent, CYContext &context, CYStatement *&statements);
e4676127 326 virtual ~CYScope();
029bc65b 327
daf22a65 328 void Close();
0a356474 329
a86e34d0
JF
330 void Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags);
331 virtual CYIdentifier *Lookup(CYContext &context, CYIdentifier *identifier);
6a981250 332 void Merge(CYContext &context, CYIdentifier *identifier);
029bc65b
JF
333 void Scope(CYContext &context, CYStatement *&statements);
334};
335
3b52fd1a
JF
336struct CYProgram :
337 CYThing
63b4c5a8 338{
3b52fd1a 339 CYStatement *statements_;
9e562cfc 340
3b52fd1a
JF
341 CYProgram(CYStatement *statements) :
342 statements_(statements)
9e562cfc
JF
343 {
344 }
cf7d4c69 345
3b52fd1a 346 virtual void Replace(CYContext &context);
3b52fd1a 347 virtual void Output(CYOutput &out) const;
9e562cfc
JF
348};
349
ab2aa221 350struct CYNonLocal;
a0be43fc 351struct CYThisScope;
ab2aa221 352
2c81c6df 353struct CYContext {
6a981250 354 CYOptions &options_;
ab2aa221 355
6a981250 356 CYScope *scope_;
a0be43fc
JF
357 CYThisScope *this_;
358
a846a8cd 359 CYIdentifierUsageVector rename_;
6a981250 360
ab2aa221 361 CYNonLocal *nonlocal_;
06293152 362 CYNonLocal *nextlocal_;
ab2aa221
JF
363 unsigned unique_;
364
2eb8215d 365 CYContext(CYOptions &options) :
6a981250 366 options_(options),
ab2aa221 367 scope_(NULL),
a0be43fc 368 this_(NULL),
ab2aa221 369 nonlocal_(NULL),
06293152 370 nextlocal_(NULL),
ab2aa221 371 unique_(0)
6a981250
JF
372 {
373 }
374
0a356474
JF
375 virtual ~CYContext() {
376 }
377
cde20a5a
JF
378 template <typename Type_>
379 void ReplaceAll(Type_ *&values) {
380 Type_ **last(&values);
c2c9f509 381 CYForEach (next, values) {
0c0d1955 382 Replace(*last = next);
9cd63688
JF
383 if (*last != NULL)
384 last = &(*last)->next_;
cde20a5a
JF
385 }
386 }
387
6a981250
JF
388 template <typename Type_>
389 void Replace(Type_ *&value) {
390 for (;;) if (value == NULL)
391 break;
392 else {
393 Type_ *replace(value->Replace(*this));
394 if (replace != value)
395 value = replace;
396 else break;
397 }
398 }
ab2aa221
JF
399
400 void NonLocal(CYStatement *&statements);
401 CYIdentifier *Unique();
402};
403
404struct CYNonLocal {
405 CYIdentifier *identifier_;
406
407 CYNonLocal() :
408 identifier_(NULL)
409 {
410 }
411
412 CYIdentifier *Target(CYContext &context) {
413 if (identifier_ == NULL)
414 identifier_ = context.Unique();
415 return identifier_;
416 }
6a981250
JF
417};
418
a0be43fc
JF
419struct CYThisScope :
420 CYNext<CYThisScope>
421{
422 CYIdentifier *identifier_;
423
424 CYThisScope() :
425 identifier_(NULL)
426 {
427 }
428
429 CYIdentifier *Identifier(CYContext &context) {
430 if (next_ != NULL)
431 return next_->Identifier(context);
432 if (identifier_ == NULL)
433 identifier_ = context.Unique();
434 return identifier_;
435 }
436};
437
9e562cfc 438struct CYBlock :
3b52fd1a
JF
439 CYStatement,
440 CYThing
9e562cfc
JF
441{
442 CYStatement *statements_;
443
a846a8cd
JF
444 CYBlock(CYStatement *statements) :
445 statements_(statements)
9e562cfc 446 {
cf7d4c69 447 }
9e562cfc 448
4644480a
JF
449 operator CYStatement *() const {
450 return statements_;
451 }
452
029bc65b 453 void AddPrev(CYStatement *statement) {
bf45251b 454 CYSetLast(statement) = statements_;
029bc65b
JF
455 statements_ = statement;
456 }
457
3b52fd1a
JF
458 virtual CYStatement *Replace(CYContext &context);
459
460 virtual void Output(CYOutput &out) const;
fb98ac0c 461 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
462};
463
cac61857 464struct CYForInitialiser {
7c6c5b0a
JF
465 virtual ~CYForInitialiser() {
466 }
467
029bc65b 468 virtual CYExpression *Replace(CYContext &context) = 0;
15b88a33 469 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
dea834b0
JF
470};
471
cac61857 472struct CYForInInitialiser {
7c6c5b0a
JF
473 virtual ~CYForInInitialiser() {
474 }
475
652ec1ba 476 virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
ad3b38bb 477 virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value) = 0;
b158281e 478
029bc65b 479 virtual CYExpression *Replace(CYContext &context) = 0;
ae65d594 480 virtual CYAssignment *Assignment(CYContext &context) = 0;
c8a0500b
JF
481
482 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
b09da87b
JF
483};
484
4644480a
JF
485struct CYNumber;
486struct CYString;
487
cf7d4c69 488struct CYExpression :
cf7d4c69 489 CYForInitialiser,
e5bc40db 490 CYForInInitialiser,
96a7e5c2
JF
491 CYClassName,
492 CYThing
63b4c5a8 493{
9a39f705 494 virtual int Precedence() const = 0;
75b0a457 495
fb98ac0c
JF
496 virtual bool RightHand() const {
497 return true;
498 }
499
652ec1ba 500 virtual void ForIn(CYOutput &out, CYFlags flags) const;
ad3b38bb 501 virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value);
75b0a457 502
6c093cce
JF
503 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
504
96a7e5c2 505 virtual void Output(CYOutput &out) const;
652ec1ba 506 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
9a39f705 507 void Output(CYOutput &out, int precedence, CYFlags flags) const;
dea834b0 508
3b52fd1a 509 virtual CYExpression *ClassName(CYContext &context, bool object);
652ec1ba 510 virtual void ClassName(CYOutput &out, bool object) const;
e5bc40db 511
3b52fd1a 512 virtual CYExpression *Replace(CYContext &context) = 0;
ae65d594 513 virtual CYAssignment *Assignment(CYContext &context);
3b52fd1a 514
4644480a 515 virtual CYExpression *Primitive(CYContext &context) {
fd5cdf97 516 return NULL;
4644480a
JF
517 }
518
519 virtual CYNumber *Number(CYContext &context) {
520 return NULL;
521 }
522
523 virtual CYString *String(CYContext &context) {
524 return NULL;
525 }
526
dea834b0
JF
527 virtual const char *Word() const {
528 return NULL;
529 }
63b4c5a8
JF
530};
531
b09da87b
JF
532#define CYAlphabetic(value) \
533 virtual bool Alphabetic() const { \
534 return value; \
535 }
536
d35a3b07 537#define CYPrecedence(value) \
9a39f705
JF
538 static const int Precedence_ = value; \
539 virtual int Precedence() const { \
8351aa30 540 return Precedence_; \
d35a3b07
JF
541 }
542
fb98ac0c
JF
543#define CYRightHand(value) \
544 virtual bool RightHand() const { \
545 return value; \
546 }
547
d35a3b07
JF
548struct CYCompound :
549 CYExpression
550{
fd5cdf97
JF
551 CYExpression *expression_;
552 CYExpression *next_;
d35a3b07 553
fd5cdf97
JF
554 CYCompound(CYExpression *expression, CYExpression *next = NULL) :
555 expression_(expression),
556 next_(next)
d35a3b07 557 {
fd5cdf97
JF
558 if (expression_ == NULL)
559 throw;
560 _assert(expression_ != NULL);
d35a3b07
JF
561 }
562
563 CYPrecedence(17)
564
3b52fd1a 565 virtual CYExpression *Replace(CYContext &context);
652ec1ba 566 void Output(CYOutput &out, CYFlags flags) const;
e06e5ee1
JF
567
568 virtual CYExpression *Primitive(CYContext &context);
d35a3b07 569};
5999c315 570
c8a0500b
JF
571struct CYDeclaration;
572
3b52fd1a
JF
573struct CYFunctionParameter :
574 CYNext<CYFunctionParameter>,
575 CYThing
576{
c8a0500b 577 CYForInInitialiser *initialiser_;
3b52fd1a 578
c8a0500b 579 CYFunctionParameter(CYForInInitialiser *initialiser, CYFunctionParameter *next = NULL) :
3b52fd1a 580 CYNext<CYFunctionParameter>(next),
c8a0500b 581 initialiser_(initialiser)
4e11a430
JF
582 {
583 }
584
c8a0500b
JF
585 void Replace(CYContext &context, CYBlock &code);
586 void Output(CYOutput &out) const;
3b52fd1a
JF
587};
588
75b0a457 589struct CYComprehension :
96a7e5c2
JF
590 CYNext<CYComprehension>,
591 CYThing
75b0a457 592{
c2529502
JF
593 CYComprehension(CYComprehension *next = NULL) :
594 CYNext<CYComprehension>(next)
595 {
596 }
597
b3aa25d8
JF
598 CYComprehension *Modify(CYComprehension *next) {
599 next_ = next;
600 return this;
601 }
602
75b0a457
JF
603 virtual const char *Name() const = 0;
604
3b52fd1a
JF
605 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
606 CYFunctionParameter *Parameters(CYContext &context) const;
607 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 608 virtual void Output(CYOutput &out) const = 0;
75b0a457
JF
609};
610
611struct CYForInComprehension :
612 CYComprehension
613{
614 CYIdentifier *name_;
615 CYExpression *set_;
616
c2529502
JF
617 CYForInComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) :
618 CYComprehension(next),
75b0a457
JF
619 name_(name),
620 set_(set)
621 {
622 }
623
624 virtual const char *Name() const {
029bc65b 625 return name_->Word();
75b0a457
JF
626 }
627
3b52fd1a
JF
628 virtual CYFunctionParameter *Parameter(CYContext &context) const;
629 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 630 virtual void Output(CYOutput &out) const;
75b0a457
JF
631};
632
d5618df7 633struct CYForOfComprehension :
75b0a457
JF
634 CYComprehension
635{
636 CYIdentifier *name_;
637 CYExpression *set_;
638
c2529502
JF
639 CYForOfComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) :
640 CYComprehension(next),
75b0a457
JF
641 name_(name),
642 set_(set)
643 {
644 }
645
646 virtual const char *Name() const {
029bc65b 647 return name_->Word();
75b0a457
JF
648 }
649
3b52fd1a
JF
650 virtual CYFunctionParameter *Parameter(CYContext &context) const;
651 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 652 virtual void Output(CYOutput &out) const;
75b0a457
JF
653};
654
655struct CYIfComprehension :
656 CYComprehension
657{
658 CYExpression *test_;
659
b3aa25d8
JF
660 CYIfComprehension(CYExpression *test, CYComprehension *next = NULL) :
661 CYComprehension(next),
75b0a457
JF
662 test_(test)
663 {
664 }
665
666 virtual const char *Name() const {
667 return NULL;
668 }
669
3b52fd1a
JF
670 virtual CYFunctionParameter *Parameter(CYContext &context) const;
671 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 672 virtual void Output(CYOutput &out) const;
75b0a457
JF
673};
674
675struct CYArrayComprehension :
676 CYExpression
677{
678 CYExpression *expression_;
679 CYComprehension *comprehensions_;
680
681 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
682 expression_(expression),
683 comprehensions_(comprehensions)
684 {
685 }
686
687 CYPrecedence(0)
688
3b52fd1a 689 virtual CYExpression *Replace(CYContext &context);
652ec1ba 690 virtual void Output(CYOutput &out, CYFlags flags) const;
75b0a457
JF
691};
692
cf7d4c69
JF
693struct CYLiteral :
694 CYExpression
63b4c5a8 695{
d35a3b07 696 CYPrecedence(0)
fb98ac0c 697 CYRightHand(false)
fd5cdf97
JF
698
699 virtual CYExpression *Primitive(CYContext &context) {
700 return this;
701 }
cf7d4c69 702};
63b4c5a8 703
3b52fd1a
JF
704struct CYTrivial :
705 CYLiteral
706{
707 virtual CYExpression *Replace(CYContext &context);
708};
709
478d4ed0
JF
710struct CYMagic :
711 CYExpression
712{
713 CYPrecedence(0)
fb98ac0c 714 CYRightHand(false)
478d4ed0
JF
715};
716
dea834b0
JF
717struct CYRange {
718 uint64_t lo_;
719 uint64_t hi_;
720
721 CYRange(uint64_t lo, uint64_t hi) :
722 lo_(lo), hi_(hi)
723 {
724 }
725
726 bool operator [](uint8_t value) const {
727 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
728 }
729
730 void operator()(uint8_t value) {
731 if (value >> 7)
732 return;
733 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
734 }
735};
736
283e7e33 737extern CYRange DigitRange_;
dea834b0
JF
738extern CYRange WordStartRange_;
739extern CYRange WordEndRange_;
740
cf7d4c69 741struct CYString :
3b52fd1a 742 CYTrivial,
e5bc40db 743 CYPropertyName
cf7d4c69
JF
744{
745 const char *value_;
5999c315 746 size_t size_;
cf7d4c69 747
3b52fd1a
JF
748 CYString() :
749 value_(NULL),
750 size_(0)
751 {
752 }
753
754 CYString(const char *value) :
755 value_(value),
756 size_(strlen(value))
757 {
758 }
759
5999c315
JF
760 CYString(const char *value, size_t size) :
761 value_(value),
762 size_(size)
cf7d4c69
JF
763 {
764 }
765
3b52fd1a 766 CYString(const CYWord *word) :
029bc65b 767 value_(word->Word()),
5999c315 768 size_(strlen(value_))
cf7d4c69
JF
769 {
770 }
771
5999c315 772 const char *Value() const {
cf7d4c69
JF
773 return value_;
774 }
775
11c1cc16 776 virtual const char *Word() const;
dea834b0 777
4644480a
JF
778 virtual CYNumber *Number(CYContext &context);
779 virtual CYString *String(CYContext &context);
780
5db9a7f5 781 CYString *Concat(CYContext &out, CYString *rhs) const;
652ec1ba
JF
782 virtual void Output(CYOutput &out, CYFlags flags) const;
783 virtual void PropertyName(CYOutput &out) const;
63b4c5a8
JF
784};
785
cf7d4c69 786struct CYNumber :
3b52fd1a 787 CYTrivial,
e5bc40db 788 CYPropertyName
cf7d4c69 789{
5999c315
JF
790 double value_;
791
792 CYNumber(double value) :
793 value_(value)
794 {
795 }
796
797 double Value() const {
798 return value_;
cf7d4c69
JF
799 }
800
4644480a
JF
801 virtual CYNumber *Number(CYContext &context);
802 virtual CYString *String(CYContext &context);
803
652ec1ba
JF
804 virtual void Output(CYOutput &out, CYFlags flags) const;
805 virtual void PropertyName(CYOutput &out) const;
cf7d4c69
JF
806};
807
63cd45c9 808struct CYRegEx :
3b52fd1a 809 CYTrivial
63cd45c9
JF
810{
811 const char *value_;
812
813 CYRegEx(const char *value) :
814 value_(value)
815 {
816 }
817
818 const char *Value() const {
819 return value_;
820 }
821
822 virtual void Output(CYOutput &out, CYFlags flags) const;
823};
824
cf7d4c69
JF
825struct CYNull :
826 CYWord,
3b52fd1a 827 CYTrivial
cf7d4c69
JF
828{
829 CYNull() :
830 CYWord("null")
831 {
832 }
5999c315 833
4644480a
JF
834 virtual CYNumber *Number(CYContext &context);
835 virtual CYString *String(CYContext &context);
836
652ec1ba 837 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
838};
839
840struct CYThis :
841 CYWord,
478d4ed0 842 CYMagic
cf7d4c69
JF
843{
844 CYThis() :
845 CYWord("this")
846 {
847 }
5999c315 848
3b52fd1a 849 virtual CYExpression *Replace(CYContext &context);
652ec1ba 850 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
851};
852
853struct CYBoolean :
3b52fd1a 854 CYTrivial
cf7d4c69 855{
5999c315 856 virtual bool Value() const = 0;
652ec1ba 857 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
858};
859
860struct CYFalse :
861 CYWord,
862 CYBoolean
863{
864 CYFalse() :
865 CYWord("false")
866 {
867 }
5999c315 868
11c1cc16
JF
869 virtual bool Value() const {
870 return false;
871 }
4644480a
JF
872
873 virtual CYNumber *Number(CYContext &context);
874 virtual CYString *String(CYContext &context);
cf7d4c69
JF
875};
876
877struct CYTrue :
878 CYWord,
879 CYBoolean
880{
881 CYTrue() :
882 CYWord("true")
883 {
884 }
5999c315 885
11c1cc16
JF
886 virtual bool Value() const {
887 return true;
888 }
4644480a
JF
889
890 virtual CYNumber *Number(CYContext &context);
891 virtual CYString *String(CYContext &context);
cf7d4c69
JF
892};
893
894struct CYVariable :
895 CYExpression
896{
897 CYIdentifier *name_;
898
899 CYVariable(CYIdentifier *name) :
900 name_(name)
901 {
902 }
5999c315 903
2eb8215d
JF
904 CYVariable(const char *name) :
905 name_(new($pool) CYIdentifier(name))
906 {
907 }
908
d35a3b07 909 CYPrecedence(0)
fb98ac0c 910 CYRightHand(false)
d35a3b07 911
3b52fd1a 912 virtual CYExpression *Replace(CYContext &context);
652ec1ba 913 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
914};
915
916struct CYPrefix :
63b4c5a8
JF
917 CYExpression
918{
919 CYExpression *rhs_;
920
cf7d4c69 921 CYPrefix(CYExpression *rhs) :
63b4c5a8
JF
922 rhs_(rhs)
923 {
924 }
5999c315 925
b09da87b 926 virtual bool Alphabetic() const = 0;
5999c315
JF
927 virtual const char *Operator() const = 0;
928
3b52fd1a
JF
929 CYPrecedence(4)
930
931 virtual CYExpression *Replace(CYContext &context);
652ec1ba 932 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
933};
934
cf7d4c69 935struct CYInfix :
63b4c5a8
JF
936 CYExpression
937{
938 CYExpression *lhs_;
939 CYExpression *rhs_;
940
cf7d4c69 941 CYInfix(CYExpression *lhs, CYExpression *rhs) :
63b4c5a8
JF
942 lhs_(lhs),
943 rhs_(rhs)
944 {
945 }
5999c315 946
0ff9f149
JF
947 void SetLeft(CYExpression *lhs) {
948 lhs_ = lhs;
949 }
950
b09da87b 951 virtual bool Alphabetic() const = 0;
5999c315
JF
952 virtual const char *Operator() const = 0;
953
3b52fd1a 954 virtual CYExpression *Replace(CYContext &context);
652ec1ba 955 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
956};
957
cf7d4c69 958struct CYPostfix :
63b4c5a8
JF
959 CYExpression
960{
961 CYExpression *lhs_;
962
cf7d4c69 963 CYPostfix(CYExpression *lhs) :
63b4c5a8
JF
964 lhs_(lhs)
965 {
966 }
5999c315
JF
967
968 virtual const char *Operator() const = 0;
969
3b52fd1a
JF
970 CYPrecedence(3)
971
972 virtual CYExpression *Replace(CYContext &context);
652ec1ba 973 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
974};
975
cf7d4c69 976struct CYAssignment :
d35a3b07 977 CYExpression
cf7d4c69 978{
d35a3b07
JF
979 CYExpression *lhs_;
980 CYExpression *rhs_;
981
cf7d4c69 982 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
d35a3b07
JF
983 lhs_(lhs),
984 rhs_(rhs)
cf7d4c69
JF
985 {
986 }
5999c315 987
0ff9f149
JF
988 void SetLeft(CYExpression *lhs) {
989 lhs_ = lhs;
990 }
991
5999c315 992 virtual const char *Operator() const = 0;
d35a3b07 993
4de0686f
JF
994 CYPrecedence(16)
995
3b52fd1a 996 virtual CYExpression *Replace(CYContext &context);
652ec1ba 997 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
998};
999
62014ea9 1000struct CYArgument :
96a7e5c2
JF
1001 CYNext<CYArgument>,
1002 CYThing
62014ea9 1003{
cf7d4c69
JF
1004 CYWord *name_;
1005 CYExpression *value_;
cf7d4c69 1006
3b52fd1a
JF
1007 CYArgument(CYExpression *value, CYArgument *next = NULL) :
1008 CYNext<CYArgument>(next),
1009 name_(NULL),
1010 value_(value)
1011 {
1012 }
1013
cf7d4c69 1014 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
62014ea9 1015 CYNext<CYArgument>(next),
cf7d4c69 1016 name_(name),
62014ea9 1017 value_(value)
cf7d4c69
JF
1018 {
1019 }
5999c315 1020
5192746c 1021 CYArgument *Replace(CYContext &context);
652ec1ba 1022 void Output(CYOutput &out) const;
cf7d4c69
JF
1023};
1024
1025struct CYBlank :
1026 public CYWord
1027{
1028 CYBlank() :
1029 CYWord("")
1030 {
1031 }
1032};
1033
5999c315
JF
1034struct CYClause :
1035 CYThing,
1036 CYNext<CYClause>
1037{
cf7d4c69 1038 CYExpression *case_;
3b52fd1a 1039 CYStatement *statements_;
cf7d4c69 1040
3b52fd1a 1041 CYClause(CYExpression *_case, CYStatement *statements) :
cf7d4c69 1042 case_(_case),
3b52fd1a 1043 statements_(statements)
cf7d4c69
JF
1044 {
1045 }
1046
fa389b0f 1047 void Replace(CYContext &context);
652ec1ba 1048 virtual void Output(CYOutput &out) const;
cf7d4c69
JF
1049};
1050
62014ea9 1051struct CYElement :
96a7e5c2
JF
1052 CYNext<CYElement>,
1053 CYThing
62014ea9 1054{
cf7d4c69 1055 CYExpression *value_;
cf7d4c69
JF
1056
1057 CYElement(CYExpression *value, CYElement *next) :
62014ea9
JF
1058 CYNext<CYElement>(next),
1059 value_(value)
cf7d4c69
JF
1060 {
1061 }
5999c315 1062
3b52fd1a 1063 void Replace(CYContext &context);
652ec1ba 1064 void Output(CYOutput &out) const;
5befe15e
JF
1065};
1066
1067struct CYArray :
1068 CYLiteral
1069{
1070 CYElement *elements_;
1071
3b52fd1a 1072 CYArray(CYElement *elements = NULL) :
5befe15e
JF
1073 elements_(elements)
1074 {
1075 }
1076
3b52fd1a 1077 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1078 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1079};
1080
550ee46a
JF
1081struct CYProperty :
1082 CYNext<CYProperty>,
1083 CYThing
1084{
1085 CYPropertyName *name_;
1086 CYExpression *value_;
1087
1088 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1089 CYNext<CYProperty>(next),
1090 name_(name),
1091 value_(value)
1092 {
1093 }
1094
1095 void Replace(CYContext &context);
1096 virtual void Output(CYOutput &out) const;
1097};
1098
cf7d4c69
JF
1099struct CYDeclaration :
1100 CYForInInitialiser
1101{
1102 CYIdentifier *identifier_;
1103 CYExpression *initialiser_;
1104
550ee46a 1105 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
cf7d4c69
JF
1106 identifier_(identifier),
1107 initialiser_(initialiser)
1108 {
1109 }
5999c315 1110
652ec1ba 1111 virtual void ForIn(CYOutput &out, CYFlags flags) const;
ad3b38bb 1112 virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value);
3b52fd1a 1113
029bc65b 1114 virtual CYExpression *Replace(CYContext &context);
15b88a33 1115
029bc65b 1116 virtual CYAssignment *Assignment(CYContext &context);
15b88a33 1117 CYVariable *Variable(CYContext &context);
75b0a457 1118
652ec1ba 1119 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1120};
1121
1122struct CYDeclarations :
cac61857 1123 CYNext<CYDeclarations>,
15b88a33 1124 CYThing
cf7d4c69
JF
1125{
1126 CYDeclaration *declaration_;
cf7d4c69 1127
cacd1a88 1128 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
cac61857
JF
1129 CYNext<CYDeclarations>(next),
1130 declaration_(declaration)
1131 {
1132 }
1133
15b88a33 1134 void Replace(CYContext &context);
96a7e5c2 1135
15b88a33 1136 CYCompound *Compound(CYContext &context);
550ee46a 1137 CYProperty *Property(CYContext &context);
15b88a33
JF
1138 CYArgument *Argument(CYContext &context);
1139 CYFunctionParameter *Parameter(CYContext &context);
3b52fd1a 1140
96a7e5c2 1141 virtual void Output(CYOutput &out) const;
652ec1ba 1142 virtual void Output(CYOutput &out, CYFlags flags) const;
cac61857
JF
1143};
1144
15b88a33
JF
1145struct CYForDeclarations :
1146 CYForInitialiser
1147{
1148 CYDeclarations *declarations_;
1149
1150 CYForDeclarations(CYDeclarations *declarations) :
1151 declarations_(declarations)
1152 {
1153 }
1154
1155 virtual CYCompound *Replace(CYContext &context);
1156 virtual void Output(CYOutput &out, CYFlags flags) const;
1157};
1158
cac61857
JF
1159struct CYVar :
1160 CYStatement
1161{
1162 CYDeclarations *declarations_;
1163
1164 CYVar(CYDeclarations *declarations) :
1165 declarations_(declarations)
1166 {
1167 }
1168
3b52fd1a 1169 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1170 virtual void Output(CYOutput &out, CYFlags flags) const;
cac61857
JF
1171};
1172
c8a0500b 1173struct CYLetStatement :
cac61857
JF
1174 CYStatement
1175{
1176 CYDeclarations *declarations_;
15b88a33 1177 CYStatement *code_;
cac61857 1178
c8a0500b 1179 CYLetStatement(CYDeclarations *declarations, CYStatement *code) :
cac61857 1180 declarations_(declarations),
15b88a33 1181 code_(code)
cf7d4c69
JF
1182 {
1183 }
5999c315 1184
3b52fd1a 1185 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1186 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1187};
1188
cf7d4c69
JF
1189struct CYFor :
1190 CYStatement
1191{
1192 CYForInitialiser *initialiser_;
1193 CYExpression *test_;
1194 CYExpression *increment_;
1195 CYStatement *code_;
1196
1197 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
1198 initialiser_(initialiser),
1199 test_(test),
1200 increment_(increment),
1201 code_(code)
1202 {
1203 }
5999c315 1204
3b52fd1a 1205 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1206 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1207};
1208
1209struct CYForIn :
1210 CYStatement
1211{
1212 CYForInInitialiser *initialiser_;
1213 CYExpression *set_;
1214 CYStatement *code_;
1215
1216 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1217 initialiser_(initialiser),
1218 set_(set),
1219 code_(code)
1220 {
1221 }
5999c315 1222
3b52fd1a 1223 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1224 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1225};
1226
d5618df7 1227struct CYForOf :
75b0a457
JF
1228 CYStatement
1229{
1230 CYForInInitialiser *initialiser_;
1231 CYExpression *set_;
1232 CYStatement *code_;
1233
d5618df7 1234 CYForOf(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
75b0a457
JF
1235 initialiser_(initialiser),
1236 set_(set),
1237 code_(code)
1238 {
1239 }
1240
3b52fd1a 1241 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1242 virtual void Output(CYOutput &out, CYFlags flags) const;
75b0a457
JF
1243};
1244
693d501b
JF
1245struct CYObject :
1246 CYLiteral
1247{
3b52fd1a 1248 CYProperty *properties_;
693d501b 1249
ab2aa221 1250 CYObject(CYProperty *properties = NULL) :
3b52fd1a 1251 properties_(properties)
693d501b
JF
1252 {
1253 }
1254
3b52fd1a 1255 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1256 void Output(CYOutput &out, CYFlags flags) const;
693d501b
JF
1257};
1258
cf7d4c69
JF
1259struct CYMember :
1260 CYExpression
1261{
1262 CYExpression *object_;
1263 CYExpression *property_;
1264
1265 CYMember(CYExpression *object, CYExpression *property) :
1266 object_(object),
1267 property_(property)
1268 {
1269 }
5999c315 1270
9b5527f0
JF
1271 void SetLeft(CYExpression *object) {
1272 object_ = object;
1273 }
1274};
1275
1276struct CYDirectMember :
1277 CYMember
1278{
1279 CYDirectMember(CYExpression *object, CYExpression *property) :
1280 CYMember(object, property)
1281 {
1282 }
1283
1284 CYPrecedence(1)
fb98ac0c 1285 CYRightHand(false)
9b5527f0 1286
3b52fd1a 1287 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1288 virtual void Output(CYOutput &out, CYFlags flags) const;
9b5527f0
JF
1289};
1290
1291struct CYIndirectMember :
1292 CYMember
1293{
1294 CYIndirectMember(CYExpression *object, CYExpression *property) :
1295 CYMember(object, property)
1296 {
1297 }
1298
d35a3b07 1299 CYPrecedence(1)
fb98ac0c 1300 CYRightHand(false)
d35a3b07 1301
3b52fd1a 1302 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1303 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1304};
1305
2eb8215d
JF
1306namespace cy {
1307namespace Syntax {
1308
1309struct New :
cf7d4c69
JF
1310 CYExpression
1311{
1312 CYExpression *constructor_;
1313 CYArgument *arguments_;
1314
2eb8215d 1315 New(CYExpression *constructor, CYArgument *arguments) :
cf7d4c69
JF
1316 constructor_(constructor),
1317 arguments_(arguments)
1318 {
1319 }
5999c315 1320
9a39f705 1321 virtual int Precedence() const {
fb98ac0c
JF
1322 return arguments_ == NULL ? 2 : 1;
1323 }
1324
1325 CYRightHand(false)
d35a3b07 1326
3b52fd1a 1327 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1328 virtual void Output(CYOutput &out, CYFlags flags) const;
6c093cce
JF
1329
1330 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
cf7d4c69
JF
1331};
1332
2eb8215d
JF
1333} }
1334
cf7d4c69
JF
1335struct CYCall :
1336 CYExpression
1337{
1338 CYExpression *function_;
1339 CYArgument *arguments_;
1340
3b52fd1a 1341 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
cf7d4c69
JF
1342 function_(function),
1343 arguments_(arguments)
1344 {
1345 }
5999c315 1346
fb98ac0c
JF
1347 CYPrecedence(1)
1348 CYRightHand(false)
d35a3b07 1349
3b52fd1a 1350 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1351 virtual void Output(CYOutput &out, CYFlags flags) const;
6c093cce
JF
1352
1353 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1354};
1355
1356struct CYRubyProc;
1357
1358struct CYRubyBlock :
1359 CYExpression
1360{
1361 CYExpression *call_;
1362 CYRubyProc *proc_;
1363
1364 CYRubyBlock(CYExpression *call, CYRubyProc *proc) :
1365 call_(call),
1366 proc_(proc)
1367 {
1368 }
1369
1370 CYPrecedence(1)
1371 CYRightHand(false)
1372
1373 virtual CYExpression *Replace(CYContext &context);
1374 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1375};
1376
1377struct CYIf :
1378 CYStatement
1379{
1380 CYExpression *test_;
1381 CYStatement *true_;
1382 CYStatement *false_;
1383
3b52fd1a 1384 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
cf7d4c69
JF
1385 test_(test),
1386 true_(_true),
1387 false_(_false)
1388 {
1389 }
5999c315 1390
3b52fd1a 1391 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1392 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1393};
1394
1395struct CYDoWhile :
1396 CYStatement
1397{
1398 CYExpression *test_;
1399 CYStatement *code_;
1400
1401 CYDoWhile(CYExpression *test, CYStatement *code) :
1402 test_(test),
1403 code_(code)
1404 {
1405 }
5999c315 1406
3b52fd1a 1407 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1408 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1409};
1410
1411struct CYWhile :
1412 CYStatement
1413{
1414 CYExpression *test_;
1415 CYStatement *code_;
1416
1417 CYWhile(CYExpression *test, CYStatement *code) :
1418 test_(test),
1419 code_(code)
1420 {
1421 }
5999c315 1422
3b52fd1a 1423 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1424 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1425};
1426
6c093cce 1427// XXX: this should be split up into CYAnonymousFunction and CYNamedFunction (subclass)
a846a8cd 1428struct CYFunction {
cf7d4c69 1429 CYIdentifier *name_;
b09da87b 1430 CYFunctionParameter *parameters_;
3b52fd1a 1431 CYBlock code_;
a0be43fc 1432
ab2aa221 1433 CYNonLocal *nonlocal_;
a0be43fc 1434 CYThisScope this_;
cf7d4c69 1435
3b52fd1a 1436 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
cf7d4c69
JF
1437 name_(name),
1438 parameters_(parameters),
ab2aa221
JF
1439 code_(statements),
1440 nonlocal_(NULL)
cf7d4c69
JF
1441 {
1442 }
5999c315 1443
7c6c5b0a
JF
1444 virtual ~CYFunction() {
1445 }
1446
14ec9e00
JF
1447 void Inject(CYContext &context);
1448 virtual void Replace_(CYContext &context, bool outer);
fb98ac0c
JF
1449 virtual void Output(CYOutput &out, CYFlags flags) const;
1450};
1451
6c093cce 1452// XXX: this should be split up into CYAnonymousFunctionExpression and CYNamedFunctionExpression
fb98ac0c
JF
1453struct CYFunctionExpression :
1454 CYFunction,
1455 CYExpression
1456{
3b52fd1a
JF
1457 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1458 CYFunction(name, parameters, statements)
fb98ac0c
JF
1459 {
1460 }
1461
a0be43fc
JF
1462 CYPrecedence(0)
1463 CYRightHand(false)
1464
1465 virtual CYExpression *Replace(CYContext &context);
1466 virtual void Output(CYOutput &out, CYFlags flags) const;
1467};
1468
1469// XXX: this should derive from CYAnonymousFunction
1470struct CYFatArrow :
1471 CYFunction,
1472 CYExpression
1473{
1474 CYFatArrow(CYFunctionParameter *parameters, CYStatement *statements) :
1475 CYFunction(NULL, parameters, statements)
1476 {
1477 }
1478
d35a3b07 1479 CYPrecedence(0)
fb98ac0c 1480 CYRightHand(false)
d35a3b07 1481
3b52fd1a 1482 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1483 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1484};
1485
6c093cce
JF
1486// XXX: this should derive from CYAnonymousFunctionExpression
1487struct CYRubyProc :
1488 CYFunctionExpression
1489{
1490 CYRubyProc(CYFunctionParameter *parameters, CYStatement *statements) :
1491 CYFunctionExpression(NULL, parameters, statements)
1492 {
1493 }
1494
1495 virtual CYExpression *Replace(CYContext &context);
1496 virtual void Output(CYOutput &out, CYFlags flags) const;
1497};
1498
1499// XXX: this should derive from CYNamedFunction
fb98ac0c
JF
1500struct CYFunctionStatement :
1501 CYFunction,
b10bd496 1502 CYStatement
cf7d4c69 1503{
3b52fd1a
JF
1504 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1505 CYFunction(name, parameters, statements)
cf7d4c69
JF
1506 {
1507 }
5999c315 1508
3b52fd1a 1509 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1510 virtual void Output(CYOutput &out, CYFlags flags) const;
5999c315
JF
1511};
1512
1513struct CYExpress :
1514 CYStatement
1515{
1516 CYExpression *expression_;
1517
1518 CYExpress(CYExpression *expression) :
1519 expression_(expression)
1520 {
fd5cdf97 1521 if (expression_ == NULL)
029bc65b 1522 throw;
5999c315
JF
1523 }
1524
3b52fd1a 1525 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1526 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1527};
1528
1529struct CYContinue :
1530 CYStatement
1531{
1532 CYIdentifier *label_;
1533
1534 CYContinue(CYIdentifier *label) :
1535 label_(label)
1536 {
1537 }
5999c315 1538
3b52fd1a 1539 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1540 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1541};
1542
1543struct CYBreak :
1544 CYStatement
1545{
1546 CYIdentifier *label_;
1547
1548 CYBreak(CYIdentifier *label) :
1549 label_(label)
1550 {
1551 }
5999c315 1552
3b52fd1a 1553 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1554 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1555};
1556
1557struct CYReturn :
1558 CYStatement
1559{
1560 CYExpression *value_;
1561
1562 CYReturn(CYExpression *value) :
1563 value_(value)
1564 {
1565 }
5999c315 1566
3b52fd1a 1567 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1568 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1569};
1570
1571struct CYEmpty :
1572 CYStatement
1573{
3b52fd1a 1574 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1575 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1576};
1577
96a7e5c2
JF
1578struct CYFinally :
1579 CYThing
1580{
3b52fd1a 1581 CYBlock code_;
b10bd496 1582
3b52fd1a
JF
1583 CYFinally(CYStatement *statements) :
1584 code_(statements)
b10bd496
JF
1585 {
1586 }
1587
3b52fd1a 1588 void Replace(CYContext &context);
b10bd496
JF
1589 virtual void Output(CYOutput &out) const;
1590};
1591
3fe283c5
JF
1592struct CYTypeSpecifier :
1593 CYThing
1594{
1595 virtual CYExpression *Replace(CYContext &context) = 0;
1596};
1597
03db6a67
JF
1598struct CYTypeError :
1599 CYTypeSpecifier
1600{
1601 CYTypeError() {
1602 }
1603
1604 virtual CYExpression *Replace(CYContext &context);
1605 virtual void Output(CYOutput &out) const;
1606};
1607
3fe283c5
JF
1608struct CYTypeVoid :
1609 CYTypeSpecifier
1610{
1611 CYTypeVoid() {
1612 }
1613
1614 virtual CYExpression *Replace(CYContext &context);
1615 virtual void Output(CYOutput &out) const;
1616};
1617
1618struct CYTypeVariable :
1619 CYTypeSpecifier
1620{
1621 CYIdentifier *name_;
1622
1623 CYTypeVariable(CYIdentifier *name) :
1624 name_(name)
1625 {
1626 }
1627
1628 CYTypeVariable(const char *name) :
1629 name_(new($pool) CYIdentifier(name))
1630 {
1631 }
1632
1633 virtual CYExpression *Replace(CYContext &context);
1634 virtual void Output(CYOutput &out) const;
1635};
1636
1637struct CYTypeUnsigned :
1638 CYTypeSpecifier
1639{
1640 CYTypeSpecifier *specifier_;
1641
1642 CYTypeUnsigned(CYTypeSpecifier *specifier) :
1643 specifier_(specifier)
1644 {
1645 }
1646
1647 virtual CYExpression *Replace(CYContext &context);
1648 virtual void Output(CYOutput &out) const;
1649};
1650
1651struct CYTypeSigned :
1652 CYTypeSpecifier
1653{
1654 CYTypeSpecifier *specifier_;
1655
1656 CYTypeSigned(CYTypeSpecifier *specifier) :
1657 specifier_(specifier)
1658 {
1659 }
1660
1661 virtual CYExpression *Replace(CYContext &context);
1662 virtual void Output(CYOutput &out) const;
1663};
1664
1665struct CYTypeLong :
1666 CYTypeSpecifier
1667{
1668 CYTypeSpecifier *specifier_;
1669
1670 CYTypeLong(CYTypeSpecifier *specifier) :
1671 specifier_(specifier)
1672 {
1673 }
1674
1675 virtual CYExpression *Replace(CYContext &context);
1676 virtual void Output(CYOutput &out) const;
1677};
1678
1679struct CYTypeShort :
1680 CYTypeSpecifier
1681{
1682 CYTypeSpecifier *specifier_;
1683
1684 CYTypeShort(CYTypeSpecifier *specifier) :
1685 specifier_(specifier)
1686 {
1687 }
1688
1689 virtual CYExpression *Replace(CYContext &context);
1690 virtual void Output(CYOutput &out) const;
1691};
1692
00b4cb83
JF
1693struct CYTypeFunctionWith;
1694
690cf1a8
JF
1695struct CYTypeModifier :
1696 CYNext<CYTypeModifier>
1697{
1698 CYTypeModifier(CYTypeModifier *next) :
1699 CYNext<CYTypeModifier>(next)
1700 {
1701 }
1702
9a39f705
JF
1703 virtual int Precedence() const = 0;
1704
1705 virtual CYExpression *Replace_(CYContext &context, CYExpression *type) = 0;
1706 CYExpression *Replace(CYContext &context, CYExpression *type);
1707
1708 virtual void Output(CYOutput &out, CYIdentifier *identifier) const = 0;
1709 void Output(CYOutput &out, int precedence, CYIdentifier *identifier) const;
00b4cb83
JF
1710
1711 virtual CYTypeFunctionWith *Function() { return NULL; }
690cf1a8
JF
1712};
1713
1714struct CYTypeArrayOf :
1715 CYTypeModifier
1716{
1717 CYExpression *size_;
1718
1719 CYTypeArrayOf(CYExpression *size, CYTypeModifier *next = NULL) :
1720 CYTypeModifier(next),
1721 size_(size)
1722 {
1723 }
1724
9a39f705 1725 CYPrecedence(1)
690cf1a8 1726
9a39f705
JF
1727 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1728 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
690cf1a8
JF
1729};
1730
1731struct CYTypeConstant :
1732 CYTypeModifier
1733{
1734 CYTypeConstant(CYTypeModifier *next = NULL) :
1735 CYTypeModifier(next)
1736 {
1737 }
1738
9a39f705 1739 CYPrecedence(0)
690cf1a8 1740
9a39f705
JF
1741 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1742 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
690cf1a8
JF
1743};
1744
1745struct CYTypePointerTo :
1746 CYTypeModifier
1747{
1748 CYTypePointerTo(CYTypeModifier *next = NULL) :
1749 CYTypeModifier(next)
1750 {
1751 }
1752
9a39f705 1753 CYPrecedence(0)
690cf1a8 1754
9a39f705
JF
1755 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1756 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
690cf1a8
JF
1757};
1758
9a39f705 1759struct CYTypeVolatile :
690cf1a8
JF
1760 CYTypeModifier
1761{
9a39f705
JF
1762 CYTypeVolatile(CYTypeModifier *next = NULL) :
1763 CYTypeModifier(next)
690cf1a8
JF
1764 {
1765 }
1766
9a39f705 1767 CYPrecedence(0)
690cf1a8 1768
9a39f705
JF
1769 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1770 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
690cf1a8
JF
1771};
1772
1773struct CYTypedIdentifier :
60097023
JF
1774 CYNext<CYTypedIdentifier>,
1775 CYThing
690cf1a8 1776{
00b4cb83 1777 CYLocation location_;
690cf1a8 1778 CYIdentifier *identifier_;
3fe283c5 1779 CYTypeSpecifier *specifier_;
9a39f705 1780 CYTypeModifier *modifier_;
690cf1a8 1781
00b4cb83
JF
1782 CYTypedIdentifier(const CYLocation &location, CYIdentifier *identifier = NULL) :
1783 location_(location),
690cf1a8 1784 identifier_(identifier),
3fe283c5 1785 specifier_(NULL),
9a39f705 1786 modifier_(NULL)
690cf1a8
JF
1787 {
1788 }
60097023 1789
3fe283c5 1790 CYTypedIdentifier(CYTypeSpecifier *specifier, CYTypeModifier *modifier = NULL) :
9a39f705 1791 identifier_(NULL),
3fe283c5 1792 specifier_(specifier),
9a39f705
JF
1793 modifier_(modifier)
1794 {
1795 }
1796
1797 inline CYTypedIdentifier *Modify(CYTypeModifier *modifier) {
1798 CYSetLast(modifier_) = modifier;
1799 return this;
1800 }
1801
1802 virtual CYExpression *Replace(CYContext &context);
60097023 1803 virtual void Output(CYOutput &out) const;
00b4cb83
JF
1804
1805 CYTypeFunctionWith *Function();
690cf1a8
JF
1806};
1807
9a39f705
JF
1808struct CYEncodedType :
1809 CYExpression
1810{
1811 CYTypedIdentifier *typed_;
1812
1813 CYEncodedType(CYTypedIdentifier *typed) :
1814 typed_(typed)
1815 {
1816 }
1817
1818 CYPrecedence(1)
1819
1820 virtual CYExpression *Replace(CYContext &context);
1821 virtual void Output(CYOutput &out, CYFlags flags) const;
1822};
1823
690cf1a8 1824struct CYTypedParameter :
9a39f705
JF
1825 CYNext<CYTypedParameter>,
1826 CYThing
690cf1a8
JF
1827{
1828 CYTypedIdentifier *typed_;
1829
1830 CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next) :
1831 CYNext<CYTypedParameter>(next),
1832 typed_(typed)
1833 {
1834 }
1835
663c538f 1836 CYArgument *Argument(CYContext &context);
690cf1a8
JF
1837 CYFunctionParameter *Parameters(CYContext &context);
1838 CYExpression *TypeSignature(CYContext &context, CYExpression *prefix);
9a39f705
JF
1839
1840 virtual void Output(CYOutput &out) const;
690cf1a8
JF
1841};
1842
1843struct CYLambda :
1844 CYExpression
1845{
9a39f705 1846 CYTypedIdentifier *typed_;
690cf1a8
JF
1847 CYTypedParameter *parameters_;
1848 CYStatement *statements_;
1849
9a39f705
JF
1850 CYLambda(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *statements) :
1851 typed_(typed),
690cf1a8
JF
1852 parameters_(parameters),
1853 statements_(statements)
1854 {
1855 }
1856
1857 CYPrecedence(1)
1858
1859 virtual CYExpression *Replace(CYContext &context);
1860 virtual void Output(CYOutput &out, CYFlags flags) const;
1861};
1862
7b750785
JF
1863struct CYModule :
1864 CYNext<CYModule>,
1865 CYThing
1866{
1867 CYWord *part_;
1868
1869 CYModule(CYWord *part, CYModule *next = NULL) :
1870 CYNext<CYModule>(next),
1871 part_(part)
1872 {
1873 }
1874
1875 CYString *Replace(CYContext &context, const char *separator) const;
1876 void Output(CYOutput &out) const;
1877};
1878
1879struct CYImport :
1880 CYStatement
1881{
1882 CYModule *module_;
1883
1884 CYImport(CYModule *module) :
1885 module_(module)
1886 {
1887 }
1888
1889 virtual CYStatement *Replace(CYContext &context);
1890 virtual void Output(CYOutput &out, CYFlags flags) const;
1891};
1892
c5587ed7
JF
1893struct CYExternal :
1894 CYStatement
1895{
1896 CYString *abi_;
1897 CYTypedIdentifier *typed_;
1898
1899 CYExternal(CYString *abi, CYTypedIdentifier *typed) :
1900 abi_(abi),
1901 typed_(typed)
1902 {
1903 }
1904
1905 virtual CYStatement *Replace(CYContext &context);
1906 virtual void Output(CYOutput &out, CYFlags flags) const;
1907};
1908
60097023
JF
1909struct CYTypeDefinition :
1910 CYStatement
1911{
1912 CYTypedIdentifier *typed_;
1913
1914 CYTypeDefinition(CYTypedIdentifier *typed) :
1915 typed_(typed)
1916 {
1917 }
1918
1919 virtual CYStatement *Replace(CYContext &context);
1920 virtual void Output(CYOutput &out, CYFlags flags) const;
1921};
1922
3fe16be7
JF
1923struct CYTypeBlockWith :
1924 CYTypeModifier
1925{
1926 CYTypedParameter *parameters_;
1927
1928 CYTypeBlockWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
1929 CYTypeModifier(next),
1930 parameters_(parameters)
1931 {
1932 }
1933
1934 CYPrecedence(0)
1935
1936 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1937 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
1938};
1939
663c538f
JF
1940struct CYTypeFunctionWith :
1941 CYTypeModifier
1942{
1943 CYTypedParameter *parameters_;
1944
1945 CYTypeFunctionWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
1946 CYTypeModifier(next),
1947 parameters_(parameters)
1948 {
1949 }
1950
9a39f705 1951 CYPrecedence(1)
663c538f 1952
9a39f705
JF
1953 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1954 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
00b4cb83
JF
1955
1956 virtual CYTypeFunctionWith *Function() { return this; }
663c538f
JF
1957};
1958
37954781
JF
1959namespace cy {
1960namespace Syntax {
1961
1962struct Catch :
1963 CYThing
1964{
1965 CYIdentifier *name_;
1966 CYBlock code_;
1967
1968 Catch(CYIdentifier *name, CYStatement *statements) :
1969 name_(name),
1970 code_(statements)
1971 {
1972 }
1973
1974 void Replace(CYContext &context);
1975 virtual void Output(CYOutput &out) const;
1976};
1977
1978struct Try :
cf7d4c69
JF
1979 CYStatement
1980{
3b52fd1a 1981 CYBlock code_;
37954781 1982 Catch *catch_;
b10bd496 1983 CYFinally *finally_;
cf7d4c69 1984
37954781 1985 Try(CYStatement *statements, Catch *_catch, CYFinally *finally) :
3b52fd1a 1986 code_(statements),
cf7d4c69
JF
1987 catch_(_catch),
1988 finally_(finally)
1989 {
1990 }
5999c315 1991
3b52fd1a 1992 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1993 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1994};
1995
37954781 1996struct Throw :
cf7d4c69
JF
1997 CYStatement
1998{
1999 CYExpression *value_;
2000
ab2aa221 2001 Throw(CYExpression *value = NULL) :
cf7d4c69
JF
2002 value_(value)
2003 {
2004 }
5999c315 2005
3b52fd1a 2006 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 2007 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2008};
2009
37954781
JF
2010} }
2011
cf7d4c69
JF
2012struct CYWith :
2013 CYStatement
2014{
2015 CYExpression *scope_;
2016 CYStatement *code_;
2017
2018 CYWith(CYExpression *scope, CYStatement *code) :
2019 scope_(scope),
2020 code_(code)
2021 {
2022 }
5999c315 2023
3b52fd1a 2024 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 2025 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2026};
2027
2028struct CYSwitch :
2029 CYStatement
2030{
2031 CYExpression *value_;
2032 CYClause *clauses_;
2033
2034 CYSwitch(CYExpression *value, CYClause *clauses) :
2035 value_(value),
2036 clauses_(clauses)
2037 {
2038 }
5999c315 2039
3b52fd1a 2040 virtual CYStatement *Replace(CYContext &context);
c8a0500b
JF
2041 virtual void Output(CYOutput &out, CYFlags flags) const;
2042};
2043
2044struct CYDebugger :
2045 CYStatement
2046{
2047 CYDebugger()
2048 {
2049 }
2050
2051 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 2052 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2053};
2054
2055struct CYCondition :
2056 CYExpression
2057{
2058 CYExpression *test_;
2059 CYExpression *true_;
2060 CYExpression *false_;
2061
2062 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
91a416e4 2063 test_(test),
cf7d4c69
JF
2064 true_(_true),
2065 false_(_false)
2066 {
2067 }
5999c315 2068
d35a3b07
JF
2069 CYPrecedence(15)
2070
3b52fd1a 2071 virtual CYExpression *Replace(CYContext &context);
652ec1ba 2072 virtual void Output(CYOutput &out, CYFlags flags) const;
5999c315
JF
2073};
2074
2075struct CYAddressOf :
2076 CYPrefix
2077{
2078 CYAddressOf(CYExpression *rhs) :
2079 CYPrefix(rhs)
2080 {
2081 }
2082
2083 virtual const char *Operator() const {
2084 return "&";
2085 }
2086
b09da87b 2087 CYAlphabetic(false)
d35a3b07 2088
3b52fd1a 2089 virtual CYExpression *Replace(CYContext &context);
5999c315
JF
2090};
2091
2092struct CYIndirect :
2093 CYPrefix
2094{
2095 CYIndirect(CYExpression *rhs) :
2096 CYPrefix(rhs)
2097 {
2098 }
2099
2100 virtual const char *Operator() const {
561ac418 2101 return "*";
5999c315
JF
2102 }
2103
b09da87b 2104 CYAlphabetic(false)
d35a3b07 2105
3b52fd1a 2106 virtual CYExpression *Replace(CYContext &context);
cf7d4c69
JF
2107};
2108
4644480a
JF
2109#define CYReplace \
2110 virtual CYExpression *Replace(CYContext &context);
2111
2112#define CYPostfix_(op, name, args...) \
cf7d4c69
JF
2113 struct CY ## name : \
2114 CYPostfix \
4644480a 2115 { args \
cf7d4c69
JF
2116 CY ## name(CYExpression *lhs) : \
2117 CYPostfix(lhs) \
2118 { \
2119 } \
5999c315
JF
2120 \
2121 virtual const char *Operator() const { \
2122 return op; \
2123 } \
cf7d4c69
JF
2124 };
2125
4644480a 2126#define CYPrefix_(alphabetic, op, name, args...) \
cf7d4c69
JF
2127 struct CY ## name : \
2128 CYPrefix \
4644480a 2129 { args \
cf7d4c69
JF
2130 CY ## name(CYExpression *rhs) : \
2131 CYPrefix(rhs) \
2132 { \
2133 } \
d35a3b07 2134 \
b09da87b 2135 CYAlphabetic(alphabetic) \
5999c315
JF
2136 \
2137 virtual const char *Operator() const { \
2138 return op; \
2139 } \
cf7d4c69
JF
2140 };
2141
4644480a 2142#define CYInfix_(alphabetic, precedence, op, name, args...) \
cf7d4c69
JF
2143 struct CY ## name : \
2144 CYInfix \
4644480a 2145 { args \
cf7d4c69
JF
2146 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
2147 CYInfix(lhs, rhs) \
2148 { \
2149 } \
d35a3b07 2150 \
b09da87b 2151 CYAlphabetic(alphabetic) \
d35a3b07 2152 CYPrecedence(precedence) \
5999c315
JF
2153 \
2154 virtual const char *Operator() const { \
2155 return op; \
2156 } \
cf7d4c69
JF
2157 };
2158
4644480a 2159#define CYAssignment_(op, name, args...) \
cf7d4c69
JF
2160 struct CY ## name ## Assign : \
2161 CYAssignment \
4644480a 2162 { args \
cf7d4c69
JF
2163 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
2164 CYAssignment(lhs, rhs) \
2165 { \
2166 } \
5999c315
JF
2167 \
2168 virtual const char *Operator() const { \
2169 return op; \
2170 } \
cf7d4c69
JF
2171 };
2172
2173CYPostfix_("++", PostIncrement)
2174CYPostfix_("--", PostDecrement)
2175
b09da87b
JF
2176CYPrefix_(true, "delete", Delete)
2177CYPrefix_(true, "void", Void)
2178CYPrefix_(true, "typeof", TypeOf)
2179CYPrefix_(false, "++", PreIncrement)
2180CYPrefix_(false, "--", PreDecrement)
c0bc320e 2181CYPrefix_(false, "+", Affirm)
b09da87b
JF
2182CYPrefix_(false, "-", Negate)
2183CYPrefix_(false, "~", BitwiseNot)
2184CYPrefix_(false, "!", LogicalNot)
2185
62f398e4 2186CYInfix_(false, 5, "*", Multiply, CYReplace)
b09da87b
JF
2187CYInfix_(false, 5, "/", Divide)
2188CYInfix_(false, 5, "%", Modulus)
4644480a 2189CYInfix_(false, 6, "+", Add, CYReplace)
b09da87b
JF
2190CYInfix_(false, 6, "-", Subtract)
2191CYInfix_(false, 7, "<<", ShiftLeft)
2192CYInfix_(false, 7, ">>", ShiftRightSigned)
2193CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
2194CYInfix_(false, 8, "<", Less)
2195CYInfix_(false, 8, ">", Greater)
2196CYInfix_(false, 8, "<=", LessOrEqual)
2197CYInfix_(false, 8, ">=", GreaterOrEqual)
2198CYInfix_(true, 8, "instanceof", InstanceOf)
2199CYInfix_(true, 8, "in", In)
2200CYInfix_(false, 9, "==", Equal)
2201CYInfix_(false, 9, "!=", NotEqual)
2202CYInfix_(false, 9, "===", Identical)
2203CYInfix_(false, 9, "!==", NotIdentical)
2204CYInfix_(false, 10, "&", BitwiseAnd)
2205CYInfix_(false, 11, "^", BitwiseXOr)
2206CYInfix_(false, 12, "|", BitwiseOr)
2207CYInfix_(false, 13, "&&", LogicalAnd)
2208CYInfix_(false, 14, "||", LogicalOr)
cf7d4c69
JF
2209
2210CYAssignment_("=", )
2211CYAssignment_("*=", Multiply)
2212CYAssignment_("/=", Divide)
2213CYAssignment_("%=", Modulus)
2214CYAssignment_("+=", Add)
2215CYAssignment_("-=", Subtract)
2216CYAssignment_("<<=", ShiftLeft)
2217CYAssignment_(">>=", ShiftRightSigned)
2218CYAssignment_(">>>=", ShiftRightUnsigned)
2219CYAssignment_("&=", BitwiseAnd)
2220CYAssignment_("^=", BitwiseXOr)
2221CYAssignment_("|=", BitwiseOr)
2222
c5fa2867 2223#endif/*CYCRIPT_PARSER_HPP*/