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