]> git.saurik.com Git - cycript.git/blame - Parser.hpp
Tab-completer accidentally overwrote name variable.
[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 :
5999c315 509 CYNext<CYExpression>,
cf7d4c69 510 CYForInitialiser,
e5bc40db 511 CYForInInitialiser,
96a7e5c2
JF
512 CYClassName,
513 CYThing
63b4c5a8 514{
9a39f705 515 virtual int Precedence() const = 0;
75b0a457 516
fb98ac0c
JF
517 virtual bool RightHand() const {
518 return true;
519 }
520
652ec1ba 521 virtual void ForIn(CYOutput &out, CYFlags flags) const;
ad3b38bb 522 virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value);
75b0a457 523
6c093cce
JF
524 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
525
96a7e5c2 526 virtual void Output(CYOutput &out) const;
652ec1ba 527 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
9a39f705 528 void Output(CYOutput &out, int precedence, CYFlags flags) const;
dea834b0 529
3b52fd1a 530 virtual CYExpression *ClassName(CYContext &context, bool object);
652ec1ba 531 virtual void ClassName(CYOutput &out, bool object) const;
e5bc40db 532
3b52fd1a 533 virtual CYExpression *Replace(CYContext &context) = 0;
ae65d594 534 virtual CYAssignment *Assignment(CYContext &context);
3b52fd1a 535
4644480a
JF
536 virtual CYExpression *Primitive(CYContext &context) {
537 return this;
538 }
539
540 virtual CYNumber *Number(CYContext &context) {
541 return NULL;
542 }
543
544 virtual CYString *String(CYContext &context) {
545 return NULL;
546 }
547
dea834b0
JF
548 virtual const char *Word() const {
549 return NULL;
550 }
63b4c5a8
JF
551};
552
b09da87b
JF
553#define CYAlphabetic(value) \
554 virtual bool Alphabetic() const { \
555 return value; \
556 }
557
d35a3b07 558#define CYPrecedence(value) \
9a39f705
JF
559 static const int Precedence_ = value; \
560 virtual int Precedence() const { \
8351aa30 561 return Precedence_; \
d35a3b07
JF
562 }
563
fb98ac0c
JF
564#define CYRightHand(value) \
565 virtual bool RightHand() const { \
566 return value; \
567 }
568
d35a3b07
JF
569struct CYCompound :
570 CYExpression
571{
572 CYExpression *expressions_;
573
029bc65b 574 CYCompound(CYExpression *expressions = NULL) :
d35a3b07
JF
575 expressions_(expressions)
576 {
577 }
578
579 void AddPrev(CYExpression *expression) {
bf45251b 580 CYSetLast(expression) = expressions_;
d35a3b07
JF
581 expressions_ = expression;
582 }
583
584 CYPrecedence(17)
585
3b52fd1a 586 virtual CYExpression *Replace(CYContext &context);
652ec1ba 587 void Output(CYOutput &out, CYFlags flags) const;
e06e5ee1
JF
588
589 virtual CYExpression *Primitive(CYContext &context);
d35a3b07 590};
5999c315 591
c8a0500b
JF
592struct CYDeclaration;
593
3b52fd1a
JF
594struct CYFunctionParameter :
595 CYNext<CYFunctionParameter>,
596 CYThing
597{
c8a0500b 598 CYForInInitialiser *initialiser_;
3b52fd1a 599
c8a0500b 600 CYFunctionParameter(CYForInInitialiser *initialiser, CYFunctionParameter *next = NULL) :
3b52fd1a 601 CYNext<CYFunctionParameter>(next),
c8a0500b 602 initialiser_(initialiser)
4e11a430
JF
603 {
604 }
605
c8a0500b
JF
606 void Replace(CYContext &context, CYBlock &code);
607 void Output(CYOutput &out) const;
3b52fd1a
JF
608};
609
75b0a457 610struct CYComprehension :
96a7e5c2
JF
611 CYNext<CYComprehension>,
612 CYThing
75b0a457 613{
c2529502
JF
614 CYComprehension(CYComprehension *next = NULL) :
615 CYNext<CYComprehension>(next)
616 {
617 }
618
b3aa25d8
JF
619 CYComprehension *Modify(CYComprehension *next) {
620 next_ = next;
621 return this;
622 }
623
75b0a457
JF
624 virtual const char *Name() const = 0;
625
3b52fd1a
JF
626 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
627 CYFunctionParameter *Parameters(CYContext &context) const;
628 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 629 virtual void Output(CYOutput &out) const = 0;
75b0a457
JF
630};
631
632struct CYForInComprehension :
633 CYComprehension
634{
635 CYIdentifier *name_;
636 CYExpression *set_;
637
c2529502
JF
638 CYForInComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) :
639 CYComprehension(next),
75b0a457
JF
640 name_(name),
641 set_(set)
642 {
643 }
644
645 virtual const char *Name() const {
029bc65b 646 return name_->Word();
75b0a457
JF
647 }
648
3b52fd1a
JF
649 virtual CYFunctionParameter *Parameter(CYContext &context) const;
650 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 651 virtual void Output(CYOutput &out) const;
75b0a457
JF
652};
653
d5618df7 654struct CYForOfComprehension :
75b0a457
JF
655 CYComprehension
656{
657 CYIdentifier *name_;
658 CYExpression *set_;
659
c2529502
JF
660 CYForOfComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) :
661 CYComprehension(next),
75b0a457
JF
662 name_(name),
663 set_(set)
664 {
665 }
666
667 virtual const char *Name() const {
029bc65b 668 return name_->Word();
75b0a457
JF
669 }
670
3b52fd1a
JF
671 virtual CYFunctionParameter *Parameter(CYContext &context) const;
672 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 673 virtual void Output(CYOutput &out) const;
75b0a457
JF
674};
675
676struct CYIfComprehension :
677 CYComprehension
678{
679 CYExpression *test_;
680
b3aa25d8
JF
681 CYIfComprehension(CYExpression *test, CYComprehension *next = NULL) :
682 CYComprehension(next),
75b0a457
JF
683 test_(test)
684 {
685 }
686
687 virtual const char *Name() const {
688 return NULL;
689 }
690
3b52fd1a
JF
691 virtual CYFunctionParameter *Parameter(CYContext &context) const;
692 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 693 virtual void Output(CYOutput &out) const;
75b0a457
JF
694};
695
696struct CYArrayComprehension :
697 CYExpression
698{
699 CYExpression *expression_;
700 CYComprehension *comprehensions_;
701
702 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
703 expression_(expression),
704 comprehensions_(comprehensions)
705 {
706 }
707
708 CYPrecedence(0)
709
3b52fd1a 710 virtual CYExpression *Replace(CYContext &context);
652ec1ba 711 virtual void Output(CYOutput &out, CYFlags flags) const;
75b0a457
JF
712};
713
cf7d4c69
JF
714struct CYLiteral :
715 CYExpression
63b4c5a8 716{
d35a3b07 717 CYPrecedence(0)
fb98ac0c 718 CYRightHand(false)
cf7d4c69 719};
63b4c5a8 720
3b52fd1a
JF
721struct CYTrivial :
722 CYLiteral
723{
724 virtual CYExpression *Replace(CYContext &context);
725};
726
478d4ed0
JF
727struct CYMagic :
728 CYExpression
729{
730 CYPrecedence(0)
fb98ac0c 731 CYRightHand(false)
478d4ed0
JF
732};
733
dea834b0
JF
734struct CYRange {
735 uint64_t lo_;
736 uint64_t hi_;
737
738 CYRange(uint64_t lo, uint64_t hi) :
739 lo_(lo), hi_(hi)
740 {
741 }
742
743 bool operator [](uint8_t value) const {
744 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
745 }
746
747 void operator()(uint8_t value) {
748 if (value >> 7)
749 return;
750 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
751 }
752};
753
283e7e33 754extern CYRange DigitRange_;
dea834b0
JF
755extern CYRange WordStartRange_;
756extern CYRange WordEndRange_;
757
cf7d4c69 758struct CYString :
3b52fd1a 759 CYTrivial,
e5bc40db 760 CYPropertyName
cf7d4c69
JF
761{
762 const char *value_;
5999c315 763 size_t size_;
cf7d4c69 764
3b52fd1a
JF
765 CYString() :
766 value_(NULL),
767 size_(0)
768 {
769 }
770
771 CYString(const char *value) :
772 value_(value),
773 size_(strlen(value))
774 {
775 }
776
5999c315
JF
777 CYString(const char *value, size_t size) :
778 value_(value),
779 size_(size)
cf7d4c69
JF
780 {
781 }
782
3b52fd1a 783 CYString(const CYWord *word) :
029bc65b 784 value_(word->Word()),
5999c315 785 size_(strlen(value_))
cf7d4c69
JF
786 {
787 }
788
5999c315 789 const char *Value() const {
cf7d4c69
JF
790 return value_;
791 }
792
11c1cc16 793 virtual const char *Word() const;
dea834b0 794
4644480a
JF
795 virtual CYNumber *Number(CYContext &context);
796 virtual CYString *String(CYContext &context);
797
5db9a7f5 798 CYString *Concat(CYContext &out, CYString *rhs) const;
652ec1ba
JF
799 virtual void Output(CYOutput &out, CYFlags flags) const;
800 virtual void PropertyName(CYOutput &out) const;
63b4c5a8
JF
801};
802
cf7d4c69 803struct CYNumber :
3b52fd1a 804 CYTrivial,
e5bc40db 805 CYPropertyName
cf7d4c69 806{
5999c315
JF
807 double value_;
808
809 CYNumber(double value) :
810 value_(value)
811 {
812 }
813
814 double Value() const {
815 return value_;
cf7d4c69
JF
816 }
817
4644480a
JF
818 virtual CYNumber *Number(CYContext &context);
819 virtual CYString *String(CYContext &context);
820
652ec1ba
JF
821 virtual void Output(CYOutput &out, CYFlags flags) const;
822 virtual void PropertyName(CYOutput &out) const;
cf7d4c69
JF
823};
824
63cd45c9 825struct CYRegEx :
3b52fd1a 826 CYTrivial
63cd45c9
JF
827{
828 const char *value_;
829
830 CYRegEx(const char *value) :
831 value_(value)
832 {
833 }
834
835 const char *Value() const {
836 return value_;
837 }
838
839 virtual void Output(CYOutput &out, CYFlags flags) const;
840};
841
cf7d4c69
JF
842struct CYNull :
843 CYWord,
3b52fd1a 844 CYTrivial
cf7d4c69
JF
845{
846 CYNull() :
847 CYWord("null")
848 {
849 }
5999c315 850
4644480a
JF
851 virtual CYNumber *Number(CYContext &context);
852 virtual CYString *String(CYContext &context);
853
652ec1ba 854 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
855};
856
857struct CYThis :
858 CYWord,
478d4ed0 859 CYMagic
cf7d4c69
JF
860{
861 CYThis() :
862 CYWord("this")
863 {
864 }
5999c315 865
3b52fd1a 866 virtual CYExpression *Replace(CYContext &context);
652ec1ba 867 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
868};
869
870struct CYBoolean :
3b52fd1a 871 CYTrivial
cf7d4c69 872{
5999c315 873 virtual bool Value() const = 0;
652ec1ba 874 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
875};
876
877struct CYFalse :
878 CYWord,
879 CYBoolean
880{
881 CYFalse() :
882 CYWord("false")
883 {
884 }
5999c315 885
11c1cc16
JF
886 virtual bool Value() const {
887 return false;
888 }
4644480a
JF
889
890 virtual CYNumber *Number(CYContext &context);
891 virtual CYString *String(CYContext &context);
cf7d4c69
JF
892};
893
894struct CYTrue :
895 CYWord,
896 CYBoolean
897{
898 CYTrue() :
899 CYWord("true")
900 {
901 }
5999c315 902
11c1cc16
JF
903 virtual bool Value() const {
904 return true;
905 }
4644480a
JF
906
907 virtual CYNumber *Number(CYContext &context);
908 virtual CYString *String(CYContext &context);
cf7d4c69
JF
909};
910
911struct CYVariable :
912 CYExpression
913{
914 CYIdentifier *name_;
915
916 CYVariable(CYIdentifier *name) :
917 name_(name)
918 {
919 }
5999c315 920
2eb8215d
JF
921 CYVariable(const char *name) :
922 name_(new($pool) CYIdentifier(name))
923 {
924 }
925
d35a3b07 926 CYPrecedence(0)
fb98ac0c 927 CYRightHand(false)
d35a3b07 928
3b52fd1a 929 virtual CYExpression *Replace(CYContext &context);
652ec1ba 930 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
931};
932
933struct CYPrefix :
63b4c5a8
JF
934 CYExpression
935{
936 CYExpression *rhs_;
937
cf7d4c69 938 CYPrefix(CYExpression *rhs) :
63b4c5a8
JF
939 rhs_(rhs)
940 {
941 }
5999c315 942
b09da87b 943 virtual bool Alphabetic() const = 0;
5999c315
JF
944 virtual const char *Operator() const = 0;
945
3b52fd1a
JF
946 CYPrecedence(4)
947
948 virtual CYExpression *Replace(CYContext &context);
652ec1ba 949 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
950};
951
cf7d4c69 952struct CYInfix :
63b4c5a8
JF
953 CYExpression
954{
955 CYExpression *lhs_;
956 CYExpression *rhs_;
957
cf7d4c69 958 CYInfix(CYExpression *lhs, CYExpression *rhs) :
63b4c5a8
JF
959 lhs_(lhs),
960 rhs_(rhs)
961 {
962 }
5999c315 963
0ff9f149
JF
964 void SetLeft(CYExpression *lhs) {
965 lhs_ = lhs;
966 }
967
b09da87b 968 virtual bool Alphabetic() const = 0;
5999c315
JF
969 virtual const char *Operator() const = 0;
970
3b52fd1a 971 virtual CYExpression *Replace(CYContext &context);
652ec1ba 972 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
973};
974
cf7d4c69 975struct CYPostfix :
63b4c5a8
JF
976 CYExpression
977{
978 CYExpression *lhs_;
979
cf7d4c69 980 CYPostfix(CYExpression *lhs) :
63b4c5a8
JF
981 lhs_(lhs)
982 {
983 }
5999c315
JF
984
985 virtual const char *Operator() const = 0;
986
3b52fd1a
JF
987 CYPrecedence(3)
988
989 virtual CYExpression *Replace(CYContext &context);
652ec1ba 990 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
991};
992
cf7d4c69 993struct CYAssignment :
d35a3b07 994 CYExpression
cf7d4c69 995{
d35a3b07
JF
996 CYExpression *lhs_;
997 CYExpression *rhs_;
998
cf7d4c69 999 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
d35a3b07
JF
1000 lhs_(lhs),
1001 rhs_(rhs)
cf7d4c69
JF
1002 {
1003 }
5999c315 1004
0ff9f149
JF
1005 void SetLeft(CYExpression *lhs) {
1006 lhs_ = lhs;
1007 }
1008
5999c315 1009 virtual const char *Operator() const = 0;
d35a3b07 1010
4de0686f
JF
1011 CYPrecedence(16)
1012
3b52fd1a 1013 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1014 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1015};
1016
62014ea9 1017struct CYArgument :
96a7e5c2
JF
1018 CYNext<CYArgument>,
1019 CYThing
62014ea9 1020{
cf7d4c69
JF
1021 CYWord *name_;
1022 CYExpression *value_;
cf7d4c69 1023
3b52fd1a
JF
1024 CYArgument(CYExpression *value, CYArgument *next = NULL) :
1025 CYNext<CYArgument>(next),
1026 name_(NULL),
1027 value_(value)
1028 {
1029 }
1030
cf7d4c69 1031 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
62014ea9 1032 CYNext<CYArgument>(next),
cf7d4c69 1033 name_(name),
62014ea9 1034 value_(value)
cf7d4c69
JF
1035 {
1036 }
5999c315 1037
5192746c 1038 CYArgument *Replace(CYContext &context);
652ec1ba 1039 void Output(CYOutput &out) const;
cf7d4c69
JF
1040};
1041
1042struct CYBlank :
1043 public CYWord
1044{
1045 CYBlank() :
1046 CYWord("")
1047 {
1048 }
1049};
1050
5999c315
JF
1051struct CYClause :
1052 CYThing,
1053 CYNext<CYClause>
1054{
cf7d4c69 1055 CYExpression *case_;
3b52fd1a 1056 CYStatement *statements_;
cf7d4c69 1057
3b52fd1a 1058 CYClause(CYExpression *_case, CYStatement *statements) :
cf7d4c69 1059 case_(_case),
3b52fd1a 1060 statements_(statements)
cf7d4c69
JF
1061 {
1062 }
1063
fa389b0f 1064 void Replace(CYContext &context);
652ec1ba 1065 virtual void Output(CYOutput &out) const;
cf7d4c69
JF
1066};
1067
62014ea9 1068struct CYElement :
96a7e5c2
JF
1069 CYNext<CYElement>,
1070 CYThing
62014ea9 1071{
cf7d4c69 1072 CYExpression *value_;
cf7d4c69
JF
1073
1074 CYElement(CYExpression *value, CYElement *next) :
62014ea9
JF
1075 CYNext<CYElement>(next),
1076 value_(value)
cf7d4c69
JF
1077 {
1078 }
5999c315 1079
3b52fd1a 1080 void Replace(CYContext &context);
652ec1ba 1081 void Output(CYOutput &out) const;
5befe15e
JF
1082};
1083
1084struct CYArray :
1085 CYLiteral
1086{
1087 CYElement *elements_;
1088
3b52fd1a 1089 CYArray(CYElement *elements = NULL) :
5befe15e
JF
1090 elements_(elements)
1091 {
1092 }
1093
3b52fd1a 1094 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1095 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1096};
1097
550ee46a
JF
1098struct CYProperty :
1099 CYNext<CYProperty>,
1100 CYThing
1101{
1102 CYPropertyName *name_;
1103 CYExpression *value_;
1104
1105 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1106 CYNext<CYProperty>(next),
1107 name_(name),
1108 value_(value)
1109 {
1110 }
1111
1112 void Replace(CYContext &context);
1113 virtual void Output(CYOutput &out) const;
1114};
1115
cf7d4c69
JF
1116struct CYDeclaration :
1117 CYForInInitialiser
1118{
1119 CYIdentifier *identifier_;
1120 CYExpression *initialiser_;
1121
550ee46a 1122 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
cf7d4c69
JF
1123 identifier_(identifier),
1124 initialiser_(initialiser)
1125 {
1126 }
5999c315 1127
652ec1ba 1128 virtual void ForIn(CYOutput &out, CYFlags flags) const;
ad3b38bb 1129 virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value);
3b52fd1a 1130
029bc65b 1131 virtual CYExpression *Replace(CYContext &context);
15b88a33 1132
029bc65b 1133 virtual CYAssignment *Assignment(CYContext &context);
15b88a33 1134 CYVariable *Variable(CYContext &context);
75b0a457 1135
652ec1ba 1136 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1137};
1138
1139struct CYDeclarations :
cac61857 1140 CYNext<CYDeclarations>,
15b88a33 1141 CYThing
cf7d4c69
JF
1142{
1143 CYDeclaration *declaration_;
cf7d4c69 1144
cacd1a88 1145 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
cac61857
JF
1146 CYNext<CYDeclarations>(next),
1147 declaration_(declaration)
1148 {
1149 }
1150
15b88a33 1151 void Replace(CYContext &context);
96a7e5c2 1152
15b88a33 1153 CYCompound *Compound(CYContext &context);
550ee46a 1154 CYProperty *Property(CYContext &context);
15b88a33
JF
1155 CYArgument *Argument(CYContext &context);
1156 CYFunctionParameter *Parameter(CYContext &context);
3b52fd1a 1157
96a7e5c2 1158 virtual void Output(CYOutput &out) const;
652ec1ba 1159 virtual void Output(CYOutput &out, CYFlags flags) const;
cac61857
JF
1160};
1161
15b88a33
JF
1162struct CYForDeclarations :
1163 CYForInitialiser
1164{
1165 CYDeclarations *declarations_;
1166
1167 CYForDeclarations(CYDeclarations *declarations) :
1168 declarations_(declarations)
1169 {
1170 }
1171
1172 virtual CYCompound *Replace(CYContext &context);
1173 virtual void Output(CYOutput &out, CYFlags flags) const;
1174};
1175
cac61857
JF
1176struct CYVar :
1177 CYStatement
1178{
1179 CYDeclarations *declarations_;
1180
1181 CYVar(CYDeclarations *declarations) :
1182 declarations_(declarations)
1183 {
1184 }
1185
3b52fd1a 1186 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1187 virtual void Output(CYOutput &out, CYFlags flags) const;
cac61857
JF
1188};
1189
c8a0500b 1190struct CYLetStatement :
cac61857
JF
1191 CYStatement
1192{
1193 CYDeclarations *declarations_;
15b88a33 1194 CYStatement *code_;
cac61857 1195
c8a0500b 1196 CYLetStatement(CYDeclarations *declarations, CYStatement *code) :
cac61857 1197 declarations_(declarations),
15b88a33 1198 code_(code)
cf7d4c69
JF
1199 {
1200 }
5999c315 1201
3b52fd1a 1202 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1203 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1204};
1205
cf7d4c69
JF
1206struct CYFor :
1207 CYStatement
1208{
1209 CYForInitialiser *initialiser_;
1210 CYExpression *test_;
1211 CYExpression *increment_;
1212 CYStatement *code_;
1213
1214 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
1215 initialiser_(initialiser),
1216 test_(test),
1217 increment_(increment),
1218 code_(code)
1219 {
1220 }
5999c315 1221
3b52fd1a 1222 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1223 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1224};
1225
1226struct CYForIn :
1227 CYStatement
1228{
1229 CYForInInitialiser *initialiser_;
1230 CYExpression *set_;
1231 CYStatement *code_;
1232
1233 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1234 initialiser_(initialiser),
1235 set_(set),
1236 code_(code)
1237 {
1238 }
5999c315 1239
3b52fd1a 1240 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1241 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1242};
1243
d5618df7 1244struct CYForOf :
75b0a457
JF
1245 CYStatement
1246{
1247 CYForInInitialiser *initialiser_;
1248 CYExpression *set_;
1249 CYStatement *code_;
1250
d5618df7 1251 CYForOf(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
75b0a457
JF
1252 initialiser_(initialiser),
1253 set_(set),
1254 code_(code)
1255 {
1256 }
1257
3b52fd1a 1258 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1259 virtual void Output(CYOutput &out, CYFlags flags) const;
75b0a457
JF
1260};
1261
693d501b
JF
1262struct CYObject :
1263 CYLiteral
1264{
3b52fd1a 1265 CYProperty *properties_;
693d501b 1266
ab2aa221 1267 CYObject(CYProperty *properties = NULL) :
3b52fd1a 1268 properties_(properties)
693d501b
JF
1269 {
1270 }
1271
3b52fd1a 1272 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1273 void Output(CYOutput &out, CYFlags flags) const;
693d501b
JF
1274};
1275
cf7d4c69
JF
1276struct CYMember :
1277 CYExpression
1278{
1279 CYExpression *object_;
1280 CYExpression *property_;
1281
1282 CYMember(CYExpression *object, CYExpression *property) :
1283 object_(object),
1284 property_(property)
1285 {
1286 }
5999c315 1287
9b5527f0
JF
1288 void SetLeft(CYExpression *object) {
1289 object_ = object;
1290 }
1291};
1292
1293struct CYDirectMember :
1294 CYMember
1295{
1296 CYDirectMember(CYExpression *object, CYExpression *property) :
1297 CYMember(object, property)
1298 {
1299 }
1300
1301 CYPrecedence(1)
fb98ac0c 1302 CYRightHand(false)
9b5527f0 1303
3b52fd1a 1304 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1305 virtual void Output(CYOutput &out, CYFlags flags) const;
9b5527f0
JF
1306};
1307
1308struct CYIndirectMember :
1309 CYMember
1310{
1311 CYIndirectMember(CYExpression *object, CYExpression *property) :
1312 CYMember(object, property)
1313 {
1314 }
1315
d35a3b07 1316 CYPrecedence(1)
fb98ac0c 1317 CYRightHand(false)
d35a3b07 1318
3b52fd1a 1319 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1320 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1321};
1322
2eb8215d
JF
1323namespace cy {
1324namespace Syntax {
1325
1326struct New :
cf7d4c69
JF
1327 CYExpression
1328{
1329 CYExpression *constructor_;
1330 CYArgument *arguments_;
1331
2eb8215d 1332 New(CYExpression *constructor, CYArgument *arguments) :
cf7d4c69
JF
1333 constructor_(constructor),
1334 arguments_(arguments)
1335 {
1336 }
5999c315 1337
9a39f705 1338 virtual int Precedence() const {
fb98ac0c
JF
1339 return arguments_ == NULL ? 2 : 1;
1340 }
1341
1342 CYRightHand(false)
d35a3b07 1343
3b52fd1a 1344 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1345 virtual void Output(CYOutput &out, CYFlags flags) const;
6c093cce
JF
1346
1347 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
cf7d4c69
JF
1348};
1349
2eb8215d
JF
1350} }
1351
cf7d4c69
JF
1352struct CYCall :
1353 CYExpression
1354{
1355 CYExpression *function_;
1356 CYArgument *arguments_;
1357
3b52fd1a 1358 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
cf7d4c69
JF
1359 function_(function),
1360 arguments_(arguments)
1361 {
1362 }
5999c315 1363
fb98ac0c
JF
1364 CYPrecedence(1)
1365 CYRightHand(false)
d35a3b07 1366
3b52fd1a 1367 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1368 virtual void Output(CYOutput &out, CYFlags flags) const;
6c093cce
JF
1369
1370 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1371};
1372
1373struct CYRubyProc;
1374
1375struct CYRubyBlock :
1376 CYExpression
1377{
1378 CYExpression *call_;
1379 CYRubyProc *proc_;
1380
1381 CYRubyBlock(CYExpression *call, CYRubyProc *proc) :
1382 call_(call),
1383 proc_(proc)
1384 {
1385 }
1386
1387 CYPrecedence(1)
1388 CYRightHand(false)
1389
1390 virtual CYExpression *Replace(CYContext &context);
1391 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1392};
1393
1394struct CYIf :
1395 CYStatement
1396{
1397 CYExpression *test_;
1398 CYStatement *true_;
1399 CYStatement *false_;
1400
3b52fd1a 1401 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
cf7d4c69
JF
1402 test_(test),
1403 true_(_true),
1404 false_(_false)
1405 {
1406 }
5999c315 1407
3b52fd1a 1408 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1409 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1410};
1411
1412struct CYDoWhile :
1413 CYStatement
1414{
1415 CYExpression *test_;
1416 CYStatement *code_;
1417
1418 CYDoWhile(CYExpression *test, CYStatement *code) :
1419 test_(test),
1420 code_(code)
1421 {
1422 }
5999c315 1423
3b52fd1a 1424 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1425 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1426};
1427
1428struct CYWhile :
1429 CYStatement
1430{
1431 CYExpression *test_;
1432 CYStatement *code_;
1433
1434 CYWhile(CYExpression *test, CYStatement *code) :
1435 test_(test),
1436 code_(code)
1437 {
1438 }
5999c315 1439
3b52fd1a 1440 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1441 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1442};
1443
6c093cce 1444// XXX: this should be split up into CYAnonymousFunction and CYNamedFunction (subclass)
a846a8cd 1445struct CYFunction {
cf7d4c69 1446 CYIdentifier *name_;
b09da87b 1447 CYFunctionParameter *parameters_;
3b52fd1a 1448 CYBlock code_;
a0be43fc 1449
ab2aa221 1450 CYNonLocal *nonlocal_;
a0be43fc 1451 CYThisScope this_;
cf7d4c69 1452
3b52fd1a 1453 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
cf7d4c69
JF
1454 name_(name),
1455 parameters_(parameters),
ab2aa221
JF
1456 code_(statements),
1457 nonlocal_(NULL)
cf7d4c69
JF
1458 {
1459 }
5999c315 1460
7c6c5b0a
JF
1461 virtual ~CYFunction() {
1462 }
1463
14ec9e00
JF
1464 void Inject(CYContext &context);
1465 virtual void Replace_(CYContext &context, bool outer);
fb98ac0c
JF
1466 virtual void Output(CYOutput &out, CYFlags flags) const;
1467};
1468
6c093cce 1469// XXX: this should be split up into CYAnonymousFunctionExpression and CYNamedFunctionExpression
fb98ac0c
JF
1470struct CYFunctionExpression :
1471 CYFunction,
1472 CYExpression
1473{
3b52fd1a
JF
1474 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1475 CYFunction(name, parameters, statements)
fb98ac0c
JF
1476 {
1477 }
1478
a0be43fc
JF
1479 CYPrecedence(0)
1480 CYRightHand(false)
1481
1482 virtual CYExpression *Replace(CYContext &context);
1483 virtual void Output(CYOutput &out, CYFlags flags) const;
1484};
1485
1486// XXX: this should derive from CYAnonymousFunction
1487struct CYFatArrow :
1488 CYFunction,
1489 CYExpression
1490{
1491 CYFatArrow(CYFunctionParameter *parameters, CYStatement *statements) :
1492 CYFunction(NULL, parameters, statements)
1493 {
1494 }
1495
d35a3b07 1496 CYPrecedence(0)
fb98ac0c 1497 CYRightHand(false)
d35a3b07 1498
3b52fd1a 1499 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1500 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1501};
1502
6c093cce
JF
1503// XXX: this should derive from CYAnonymousFunctionExpression
1504struct CYRubyProc :
1505 CYFunctionExpression
1506{
1507 CYRubyProc(CYFunctionParameter *parameters, CYStatement *statements) :
1508 CYFunctionExpression(NULL, parameters, statements)
1509 {
1510 }
1511
1512 virtual CYExpression *Replace(CYContext &context);
1513 virtual void Output(CYOutput &out, CYFlags flags) const;
1514};
1515
1516// XXX: this should derive from CYNamedFunction
fb98ac0c
JF
1517struct CYFunctionStatement :
1518 CYFunction,
b10bd496 1519 CYStatement
cf7d4c69 1520{
3b52fd1a
JF
1521 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1522 CYFunction(name, parameters, statements)
cf7d4c69
JF
1523 {
1524 }
5999c315 1525
3b52fd1a 1526 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1527 virtual void Output(CYOutput &out, CYFlags flags) const;
5999c315
JF
1528};
1529
1530struct CYExpress :
1531 CYStatement
1532{
1533 CYExpression *expression_;
1534
1535 CYExpress(CYExpression *expression) :
1536 expression_(expression)
1537 {
029bc65b
JF
1538 if (expression == NULL)
1539 throw;
5999c315
JF
1540 }
1541
3b52fd1a 1542 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1543 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1544};
1545
1546struct CYContinue :
1547 CYStatement
1548{
1549 CYIdentifier *label_;
1550
1551 CYContinue(CYIdentifier *label) :
1552 label_(label)
1553 {
1554 }
5999c315 1555
3b52fd1a 1556 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1557 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1558};
1559
1560struct CYBreak :
1561 CYStatement
1562{
1563 CYIdentifier *label_;
1564
1565 CYBreak(CYIdentifier *label) :
1566 label_(label)
1567 {
1568 }
5999c315 1569
3b52fd1a 1570 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1571 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1572};
1573
1574struct CYReturn :
1575 CYStatement
1576{
1577 CYExpression *value_;
1578
1579 CYReturn(CYExpression *value) :
1580 value_(value)
1581 {
1582 }
5999c315 1583
3b52fd1a 1584 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1585 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1586};
1587
1588struct CYEmpty :
1589 CYStatement
1590{
3b52fd1a 1591 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1592 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1593};
1594
96a7e5c2
JF
1595struct CYFinally :
1596 CYThing
1597{
3b52fd1a 1598 CYBlock code_;
b10bd496 1599
3b52fd1a
JF
1600 CYFinally(CYStatement *statements) :
1601 code_(statements)
b10bd496
JF
1602 {
1603 }
1604
3b52fd1a 1605 void Replace(CYContext &context);
b10bd496
JF
1606 virtual void Output(CYOutput &out) const;
1607};
1608
3fe283c5
JF
1609struct CYTypeSpecifier :
1610 CYThing
1611{
1612 virtual CYExpression *Replace(CYContext &context) = 0;
1613};
1614
03db6a67
JF
1615struct CYTypeError :
1616 CYTypeSpecifier
1617{
1618 CYTypeError() {
1619 }
1620
1621 virtual CYExpression *Replace(CYContext &context);
1622 virtual void Output(CYOutput &out) const;
1623};
1624
3fe283c5
JF
1625struct CYTypeVoid :
1626 CYTypeSpecifier
1627{
1628 CYTypeVoid() {
1629 }
1630
1631 virtual CYExpression *Replace(CYContext &context);
1632 virtual void Output(CYOutput &out) const;
1633};
1634
1635struct CYTypeVariable :
1636 CYTypeSpecifier
1637{
1638 CYIdentifier *name_;
1639
1640 CYTypeVariable(CYIdentifier *name) :
1641 name_(name)
1642 {
1643 }
1644
1645 CYTypeVariable(const char *name) :
1646 name_(new($pool) CYIdentifier(name))
1647 {
1648 }
1649
1650 virtual CYExpression *Replace(CYContext &context);
1651 virtual void Output(CYOutput &out) const;
1652};
1653
1654struct CYTypeUnsigned :
1655 CYTypeSpecifier
1656{
1657 CYTypeSpecifier *specifier_;
1658
1659 CYTypeUnsigned(CYTypeSpecifier *specifier) :
1660 specifier_(specifier)
1661 {
1662 }
1663
1664 virtual CYExpression *Replace(CYContext &context);
1665 virtual void Output(CYOutput &out) const;
1666};
1667
1668struct CYTypeSigned :
1669 CYTypeSpecifier
1670{
1671 CYTypeSpecifier *specifier_;
1672
1673 CYTypeSigned(CYTypeSpecifier *specifier) :
1674 specifier_(specifier)
1675 {
1676 }
1677
1678 virtual CYExpression *Replace(CYContext &context);
1679 virtual void Output(CYOutput &out) const;
1680};
1681
1682struct CYTypeLong :
1683 CYTypeSpecifier
1684{
1685 CYTypeSpecifier *specifier_;
1686
1687 CYTypeLong(CYTypeSpecifier *specifier) :
1688 specifier_(specifier)
1689 {
1690 }
1691
1692 virtual CYExpression *Replace(CYContext &context);
1693 virtual void Output(CYOutput &out) const;
1694};
1695
1696struct CYTypeShort :
1697 CYTypeSpecifier
1698{
1699 CYTypeSpecifier *specifier_;
1700
1701 CYTypeShort(CYTypeSpecifier *specifier) :
1702 specifier_(specifier)
1703 {
1704 }
1705
1706 virtual CYExpression *Replace(CYContext &context);
1707 virtual void Output(CYOutput &out) const;
1708};
1709
690cf1a8
JF
1710struct CYTypeModifier :
1711 CYNext<CYTypeModifier>
1712{
1713 CYTypeModifier(CYTypeModifier *next) :
1714 CYNext<CYTypeModifier>(next)
1715 {
1716 }
1717
9a39f705
JF
1718 virtual int Precedence() const = 0;
1719
1720 virtual CYExpression *Replace_(CYContext &context, CYExpression *type) = 0;
1721 CYExpression *Replace(CYContext &context, CYExpression *type);
1722
1723 virtual void Output(CYOutput &out, CYIdentifier *identifier) const = 0;
1724 void Output(CYOutput &out, int precedence, CYIdentifier *identifier) const;
690cf1a8
JF
1725};
1726
1727struct CYTypeArrayOf :
1728 CYTypeModifier
1729{
1730 CYExpression *size_;
1731
1732 CYTypeArrayOf(CYExpression *size, CYTypeModifier *next = NULL) :
1733 CYTypeModifier(next),
1734 size_(size)
1735 {
1736 }
1737
9a39f705 1738 CYPrecedence(1)
690cf1a8 1739
9a39f705
JF
1740 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1741 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
690cf1a8
JF
1742};
1743
1744struct CYTypeConstant :
1745 CYTypeModifier
1746{
1747 CYTypeConstant(CYTypeModifier *next = NULL) :
1748 CYTypeModifier(next)
1749 {
1750 }
1751
9a39f705 1752 CYPrecedence(0)
690cf1a8 1753
9a39f705
JF
1754 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1755 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
690cf1a8
JF
1756};
1757
1758struct CYTypePointerTo :
1759 CYTypeModifier
1760{
1761 CYTypePointerTo(CYTypeModifier *next = NULL) :
1762 CYTypeModifier(next)
1763 {
1764 }
1765
9a39f705 1766 CYPrecedence(0)
690cf1a8 1767
9a39f705
JF
1768 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1769 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
690cf1a8
JF
1770};
1771
9a39f705 1772struct CYTypeVolatile :
690cf1a8
JF
1773 CYTypeModifier
1774{
9a39f705
JF
1775 CYTypeVolatile(CYTypeModifier *next = NULL) :
1776 CYTypeModifier(next)
690cf1a8
JF
1777 {
1778 }
1779
9a39f705 1780 CYPrecedence(0)
690cf1a8 1781
9a39f705
JF
1782 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1783 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
690cf1a8
JF
1784};
1785
1786struct CYTypedIdentifier :
60097023
JF
1787 CYNext<CYTypedIdentifier>,
1788 CYThing
690cf1a8
JF
1789{
1790 CYIdentifier *identifier_;
3fe283c5 1791 CYTypeSpecifier *specifier_;
9a39f705 1792 CYTypeModifier *modifier_;
690cf1a8 1793
9a39f705 1794 CYTypedIdentifier(CYIdentifier *identifier = NULL) :
690cf1a8 1795 identifier_(identifier),
3fe283c5 1796 specifier_(NULL),
9a39f705 1797 modifier_(NULL)
690cf1a8
JF
1798 {
1799 }
60097023 1800
3fe283c5 1801 CYTypedIdentifier(CYTypeSpecifier *specifier, CYTypeModifier *modifier = NULL) :
9a39f705 1802 identifier_(NULL),
3fe283c5 1803 specifier_(specifier),
9a39f705
JF
1804 modifier_(modifier)
1805 {
1806 }
1807
1808 inline CYTypedIdentifier *Modify(CYTypeModifier *modifier) {
1809 CYSetLast(modifier_) = modifier;
1810 return this;
1811 }
1812
1813 virtual CYExpression *Replace(CYContext &context);
60097023 1814 virtual void Output(CYOutput &out) const;
690cf1a8
JF
1815};
1816
9a39f705
JF
1817struct CYEncodedType :
1818 CYExpression
1819{
1820 CYTypedIdentifier *typed_;
1821
1822 CYEncodedType(CYTypedIdentifier *typed) :
1823 typed_(typed)
1824 {
1825 }
1826
1827 CYPrecedence(1)
1828
1829 virtual CYExpression *Replace(CYContext &context);
1830 virtual void Output(CYOutput &out, CYFlags flags) const;
1831};
1832
690cf1a8 1833struct CYTypedParameter :
9a39f705
JF
1834 CYNext<CYTypedParameter>,
1835 CYThing
690cf1a8
JF
1836{
1837 CYTypedIdentifier *typed_;
1838
1839 CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next) :
1840 CYNext<CYTypedParameter>(next),
1841 typed_(typed)
1842 {
1843 }
1844
663c538f 1845 CYArgument *Argument(CYContext &context);
690cf1a8
JF
1846 CYFunctionParameter *Parameters(CYContext &context);
1847 CYExpression *TypeSignature(CYContext &context, CYExpression *prefix);
9a39f705
JF
1848
1849 virtual void Output(CYOutput &out) const;
690cf1a8
JF
1850};
1851
1852struct CYLambda :
1853 CYExpression
1854{
9a39f705 1855 CYTypedIdentifier *typed_;
690cf1a8
JF
1856 CYTypedParameter *parameters_;
1857 CYStatement *statements_;
1858
9a39f705
JF
1859 CYLambda(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *statements) :
1860 typed_(typed),
690cf1a8
JF
1861 parameters_(parameters),
1862 statements_(statements)
1863 {
1864 }
1865
1866 CYPrecedence(1)
1867
1868 virtual CYExpression *Replace(CYContext &context);
1869 virtual void Output(CYOutput &out, CYFlags flags) const;
1870};
1871
60097023
JF
1872struct CYTypeDefinition :
1873 CYStatement
1874{
1875 CYTypedIdentifier *typed_;
1876
1877 CYTypeDefinition(CYTypedIdentifier *typed) :
1878 typed_(typed)
1879 {
1880 }
1881
1882 virtual CYStatement *Replace(CYContext &context);
1883 virtual void Output(CYOutput &out, CYFlags flags) const;
1884};
1885
3fe16be7
JF
1886struct CYTypeBlockWith :
1887 CYTypeModifier
1888{
1889 CYTypedParameter *parameters_;
1890
1891 CYTypeBlockWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
1892 CYTypeModifier(next),
1893 parameters_(parameters)
1894 {
1895 }
1896
1897 CYPrecedence(0)
1898
1899 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1900 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
1901};
1902
663c538f
JF
1903struct CYTypeFunctionWith :
1904 CYTypeModifier
1905{
1906 CYTypedParameter *parameters_;
1907
1908 CYTypeFunctionWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
1909 CYTypeModifier(next),
1910 parameters_(parameters)
1911 {
1912 }
1913
9a39f705 1914 CYPrecedence(1)
663c538f 1915
9a39f705
JF
1916 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1917 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
663c538f
JF
1918};
1919
37954781
JF
1920namespace cy {
1921namespace Syntax {
1922
1923struct Catch :
1924 CYThing
1925{
1926 CYIdentifier *name_;
1927 CYBlock code_;
1928
1929 Catch(CYIdentifier *name, CYStatement *statements) :
1930 name_(name),
1931 code_(statements)
1932 {
1933 }
1934
1935 void Replace(CYContext &context);
1936 virtual void Output(CYOutput &out) const;
1937};
1938
1939struct Try :
cf7d4c69
JF
1940 CYStatement
1941{
3b52fd1a 1942 CYBlock code_;
37954781 1943 Catch *catch_;
b10bd496 1944 CYFinally *finally_;
cf7d4c69 1945
37954781 1946 Try(CYStatement *statements, Catch *_catch, CYFinally *finally) :
3b52fd1a 1947 code_(statements),
cf7d4c69
JF
1948 catch_(_catch),
1949 finally_(finally)
1950 {
1951 }
5999c315 1952
3b52fd1a 1953 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1954 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1955};
1956
37954781 1957struct Throw :
cf7d4c69
JF
1958 CYStatement
1959{
1960 CYExpression *value_;
1961
ab2aa221 1962 Throw(CYExpression *value = NULL) :
cf7d4c69
JF
1963 value_(value)
1964 {
1965 }
5999c315 1966
3b52fd1a 1967 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1968 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1969};
1970
37954781
JF
1971} }
1972
cf7d4c69
JF
1973struct CYWith :
1974 CYStatement
1975{
1976 CYExpression *scope_;
1977 CYStatement *code_;
1978
1979 CYWith(CYExpression *scope, CYStatement *code) :
1980 scope_(scope),
1981 code_(code)
1982 {
1983 }
5999c315 1984
3b52fd1a 1985 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1986 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1987};
1988
1989struct CYSwitch :
1990 CYStatement
1991{
1992 CYExpression *value_;
1993 CYClause *clauses_;
1994
1995 CYSwitch(CYExpression *value, CYClause *clauses) :
1996 value_(value),
1997 clauses_(clauses)
1998 {
1999 }
5999c315 2000
3b52fd1a 2001 virtual CYStatement *Replace(CYContext &context);
c8a0500b
JF
2002 virtual void Output(CYOutput &out, CYFlags flags) const;
2003};
2004
2005struct CYDebugger :
2006 CYStatement
2007{
2008 CYDebugger()
2009 {
2010 }
2011
2012 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 2013 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2014};
2015
2016struct CYCondition :
2017 CYExpression
2018{
2019 CYExpression *test_;
2020 CYExpression *true_;
2021 CYExpression *false_;
2022
2023 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
91a416e4 2024 test_(test),
cf7d4c69
JF
2025 true_(_true),
2026 false_(_false)
2027 {
2028 }
5999c315 2029
d35a3b07
JF
2030 CYPrecedence(15)
2031
3b52fd1a 2032 virtual CYExpression *Replace(CYContext &context);
652ec1ba 2033 virtual void Output(CYOutput &out, CYFlags flags) const;
5999c315
JF
2034};
2035
2036struct CYAddressOf :
2037 CYPrefix
2038{
2039 CYAddressOf(CYExpression *rhs) :
2040 CYPrefix(rhs)
2041 {
2042 }
2043
2044 virtual const char *Operator() const {
2045 return "&";
2046 }
2047
b09da87b 2048 CYAlphabetic(false)
d35a3b07 2049
3b52fd1a 2050 virtual CYExpression *Replace(CYContext &context);
5999c315
JF
2051};
2052
2053struct CYIndirect :
2054 CYPrefix
2055{
2056 CYIndirect(CYExpression *rhs) :
2057 CYPrefix(rhs)
2058 {
2059 }
2060
2061 virtual const char *Operator() const {
561ac418 2062 return "*";
5999c315
JF
2063 }
2064
b09da87b 2065 CYAlphabetic(false)
d35a3b07 2066
3b52fd1a 2067 virtual CYExpression *Replace(CYContext &context);
cf7d4c69
JF
2068};
2069
4644480a
JF
2070#define CYReplace \
2071 virtual CYExpression *Replace(CYContext &context);
2072
2073#define CYPostfix_(op, name, args...) \
cf7d4c69
JF
2074 struct CY ## name : \
2075 CYPostfix \
4644480a 2076 { args \
cf7d4c69
JF
2077 CY ## name(CYExpression *lhs) : \
2078 CYPostfix(lhs) \
2079 { \
2080 } \
5999c315
JF
2081 \
2082 virtual const char *Operator() const { \
2083 return op; \
2084 } \
cf7d4c69
JF
2085 };
2086
4644480a 2087#define CYPrefix_(alphabetic, op, name, args...) \
cf7d4c69
JF
2088 struct CY ## name : \
2089 CYPrefix \
4644480a 2090 { args \
cf7d4c69
JF
2091 CY ## name(CYExpression *rhs) : \
2092 CYPrefix(rhs) \
2093 { \
2094 } \
d35a3b07 2095 \
b09da87b 2096 CYAlphabetic(alphabetic) \
5999c315
JF
2097 \
2098 virtual const char *Operator() const { \
2099 return op; \
2100 } \
cf7d4c69
JF
2101 };
2102
4644480a 2103#define CYInfix_(alphabetic, precedence, op, name, args...) \
cf7d4c69
JF
2104 struct CY ## name : \
2105 CYInfix \
4644480a 2106 { args \
cf7d4c69
JF
2107 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
2108 CYInfix(lhs, rhs) \
2109 { \
2110 } \
d35a3b07 2111 \
b09da87b 2112 CYAlphabetic(alphabetic) \
d35a3b07 2113 CYPrecedence(precedence) \
5999c315
JF
2114 \
2115 virtual const char *Operator() const { \
2116 return op; \
2117 } \
cf7d4c69
JF
2118 };
2119
4644480a 2120#define CYAssignment_(op, name, args...) \
cf7d4c69
JF
2121 struct CY ## name ## Assign : \
2122 CYAssignment \
4644480a 2123 { args \
cf7d4c69
JF
2124 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
2125 CYAssignment(lhs, rhs) \
2126 { \
2127 } \
5999c315
JF
2128 \
2129 virtual const char *Operator() const { \
2130 return op; \
2131 } \
cf7d4c69
JF
2132 };
2133
2134CYPostfix_("++", PostIncrement)
2135CYPostfix_("--", PostDecrement)
2136
b09da87b
JF
2137CYPrefix_(true, "delete", Delete)
2138CYPrefix_(true, "void", Void)
2139CYPrefix_(true, "typeof", TypeOf)
2140CYPrefix_(false, "++", PreIncrement)
2141CYPrefix_(false, "--", PreDecrement)
c0bc320e 2142CYPrefix_(false, "+", Affirm)
b09da87b
JF
2143CYPrefix_(false, "-", Negate)
2144CYPrefix_(false, "~", BitwiseNot)
2145CYPrefix_(false, "!", LogicalNot)
2146
62f398e4 2147CYInfix_(false, 5, "*", Multiply, CYReplace)
b09da87b
JF
2148CYInfix_(false, 5, "/", Divide)
2149CYInfix_(false, 5, "%", Modulus)
4644480a 2150CYInfix_(false, 6, "+", Add, CYReplace)
b09da87b
JF
2151CYInfix_(false, 6, "-", Subtract)
2152CYInfix_(false, 7, "<<", ShiftLeft)
2153CYInfix_(false, 7, ">>", ShiftRightSigned)
2154CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
2155CYInfix_(false, 8, "<", Less)
2156CYInfix_(false, 8, ">", Greater)
2157CYInfix_(false, 8, "<=", LessOrEqual)
2158CYInfix_(false, 8, ">=", GreaterOrEqual)
2159CYInfix_(true, 8, "instanceof", InstanceOf)
2160CYInfix_(true, 8, "in", In)
2161CYInfix_(false, 9, "==", Equal)
2162CYInfix_(false, 9, "!=", NotEqual)
2163CYInfix_(false, 9, "===", Identical)
2164CYInfix_(false, 9, "!==", NotIdentical)
2165CYInfix_(false, 10, "&", BitwiseAnd)
2166CYInfix_(false, 11, "^", BitwiseXOr)
2167CYInfix_(false, 12, "|", BitwiseOr)
2168CYInfix_(false, 13, "&&", LogicalAnd)
2169CYInfix_(false, 14, "||", LogicalOr)
cf7d4c69
JF
2170
2171CYAssignment_("=", )
2172CYAssignment_("*=", Multiply)
2173CYAssignment_("/=", Divide)
2174CYAssignment_("%=", Modulus)
2175CYAssignment_("+=", Add)
2176CYAssignment_("-=", Subtract)
2177CYAssignment_("<<=", ShiftLeft)
2178CYAssignment_(">>=", ShiftRightSigned)
2179CYAssignment_(">>>=", ShiftRightUnsigned)
2180CYAssignment_("&=", BitwiseAnd)
2181CYAssignment_("^=", BitwiseXOr)
2182CYAssignment_("|=", BitwiseOr)
2183
c5fa2867 2184#endif/*CYCRIPT_PARSER_HPP*/