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