Functional-lang  0.0
An example functional programming language
syntax.hpp
Go to the documentation of this file.
1 #ifndef FUNC_SYNTAX_HPP
2 #define FUNC_SYNTAX_HPP
3 
8 #include "func/global.hpp"
9 #include "func/lexer.hpp"
10 #include "func/gc.hpp"
11 
12 class Expr;
13 class BiOpExpr;
14 class NumExpr;
15 class IntExpr;
16 class IdExpr;
17 class LambdaExpr;
18 class AtomExpr;
19 class IfExpr;
20 class AnyExpr;
21 class LetExpr;
22 
26 enum ExprType : int {
38 };
39 
42 class Environment : public GCObj {
43  std::map<std::string, Expr*> variables;
44  Environment *parent;
45 public:
46  Lexer *lexer;
47  std::vector<Expr*> ctx;
48 
49  Environment(GCMain &gc, Lexer *lexer = nullptr, Environment *parent = nullptr)
50  : GCObj(gc), lexer{lexer}, parent{parent}, variables() {}
51  virtual ~Environment() {}
52 
55  bool contains(const std::string &name) const noexcept;
56 
59  const Expr *get(const std::string &name) const noexcept;
60 
64  const Expr *currentGet(const std::string &name) const noexcept;
65 
66  virtual void mark(GCMain &gc) noexcept override;
67 
68  std::map<std::string, Expr*> &getVariables() noexcept
69  { return variables; }
70 
73  Environment *getParent() const noexcept { return parent; }
74 };
75 
76 std::vector<Expr*>::iterator find(std::vector<Expr*> &vec, Expr *expr) noexcept;
77 
84 template<typename T>
86  Environment &env;
87  T* expr;
88 public:
89  StackFrameObj(Environment &env, T *expr = nullptr) noexcept
90  : env{env}, expr{expr} {
91 
92  if (this->expr) env.ctx.push_back(dynamic_cast<Expr*>(expr));
93  }
94 
95  ~StackFrameObj() {
96  if (this->expr) {
97  auto it = find(env.ctx, dynamic_cast<Expr*>(this->expr));
98  if (it != env.ctx.end()) env.ctx.erase(it);
99  }
100  }
101 
102  /*\return Returns contained expression.
103  */
104  T* operator ->() const noexcept {
105  return expr;
106  }
107 
110  T* operator *() const noexcept {
111  return expr;
112  }
113 
117  bool operator ==(T *expr) const noexcept {
118  return this->expr == expr;
119  }
120 
124  bool operator ==(StackFrameObj<T> &obj) const noexcept {
125  return this->expr == *obj;
126  }
127 
131  bool operator !=(T *expr) const noexcept {
132  return this->expr != expr;
133  }
134 
138  bool operator !=(StackFrameObj<T> &obj) const noexcept {
139  return this->expr != *obj;
140  }
141 
146  StackFrameObj<T>& operator=(T *expr) noexcept {
147  if (expr) env.ctx.push_back(dynamic_cast<Expr*>(expr));
148 
149  if (this->expr) {
150  auto it = find(env.ctx, dynamic_cast<Expr*>(this->expr));
151  if (it != env.ctx.end()) env.ctx.erase(it);
152  }
153 
154  this->expr = expr; return *this;
155  }
156 
163  *this = *obj;
164  return *this;
165  }
166 
169  operator bool() const {
170  return expr != nullptr;
171  }
172 };
173 
179 class Expr : public GCObj {
180  TokenPos pos;
181  ExprType type;
182 protected:
183  std::size_t depth;
184  Expr *lastEval = nullptr;
185 public:
186  Expr(GCMain &gc, ExprType type, const TokenPos &pos)
187  : GCObj(gc), type{type}, pos(pos) {}
188 
189  virtual ~Expr() {}
190 
191  /*\return Returns a pre-calculated depth of the expresssion.
192  */
193  std::size_t getDepth() const noexcept { return depth; }
194 
198  bool hasLastEval() const noexcept { return lastEval != nullptr; }
199 
202  const TokenPos &getTokenPos() const noexcept { return pos; }
203 
207  virtual std::string toString() const noexcept { return std::string(); }
208 
212  ExprType getExpressionType() const noexcept { return type; }
213 
219  virtual Expr *eval(GCMain &gc, Environment &env) noexcept {
220  return this;
221  }
222 
228  Expr *evalWithLookup(GCMain &gc, Environment &env) noexcept;
229 
239  virtual Expr *replace(GCMain &gc, const std::string &name, Expr *expr) const noexcept {
240  return const_cast<Expr*>(this);
241  }
242 
249  virtual bool equals(const Expr *expr, bool exact = false) const noexcept
250  { return this == expr; }
251 
254  virtual std::vector<std::string> getIdentifiers() const noexcept {
255  return std::vector<std::string>();
256  }
257 
258  virtual void mark(GCMain &gc) noexcept override;
259 
263  virtual Expr *optimize(GCMain &gc) noexcept;
264 };
265 
268 class BiOpExpr : public Expr {
269  Operator op;
270  Expr *lhs, *rhs;
271 public:
272  BiOpExpr(GCMain &gc, Operator op, Expr *lhs, Expr *rhs)
273  : Expr(gc, expr_biop, TokenPos(lhs->getTokenPos(), rhs->getTokenPos())),
274  op(op), lhs{lhs}, rhs{rhs} {
275  depth = 1 + lhs->getDepth() + rhs->getDepth();
276  }
277 
278  BiOpExpr(GCMain &gc, const TokenPos &pos, Operator op, Expr *lhs, Expr *rhs)
279  : Expr(gc, expr_biop, pos),
280  op(op), lhs{lhs}, rhs{rhs} {
281  depth = 1 + lhs->getDepth() + rhs->getDepth();
282  }
283 
284  virtual ~BiOpExpr() {}
285 
287  Operator getOperator() const noexcept { return op; }
288 
290  const Expr& getRHS() const noexcept { return *rhs; }
291 
293  const Expr& getLHS() const noexcept { return *lhs; }
294 
295  virtual std::string toString() const noexcept override {
296  if (op == op_fn)
297  return lhs->toString() + " " + rhs->toString();
298 
299  return "(" + lhs->toString()
300  + " " + std::to_string(op) + " " + rhs->toString() + ")";
301  }
302 
304  virtual void mark(GCMain &gc) noexcept override {
305  if (isMarked(gc))
306  return;
307 
308  markSelf(gc);
309  if (lastEval) lastEval->mark(gc);
310  lhs->mark(gc);
311  rhs->mark(gc);
312  }
313 
314  virtual Expr *eval(GCMain &gc, Environment &env) noexcept override;
315  virtual Expr *replace(GCMain &gc, const std::string &name, Expr *expr) const noexcept override;
316 
317  virtual bool equals(const Expr *expr, bool exact = false) const noexcept override;
318 
323  bool isAtomConstructor() const noexcept;
324 
325  bool isFunctionConstructor() const noexcept;
326 
330  const AtomExpr *getAtomConstructor() const noexcept;
331 
332  virtual std::vector<std::string> getIdentifiers() const noexcept override {
333  std::vector<std::string> result = getLHS().getIdentifiers();
334  for (std::string &id : getRHS().getIdentifiers())
335  result.push_back(id);
336 
337  return result;
338  }
339 
340  virtual Expr *optimize(GCMain &gc) noexcept override;
341 
345  BiOpExpr *optimize(GCMain &gc, std::vector<Expr*> &exprs) noexcept;
346 };
347 
348 class UnOpExpr : public Expr {
349  Operator op;
350  Expr *expr;
351 public:
352  UnOpExpr(GCMain &gc, const TokenPos &pos, Operator op, Expr *expr)
353  : Expr(gc, expr_unop, pos), op{op}, expr{expr} {
354 
355  depth = 1 + expr->getDepth();
356  }
357 
358  Operator getOperator() const noexcept { return op; }
359  const Expr &getExpression() const noexcept { return *expr; }
360 
361  virtual void mark(GCMain &gc) noexcept override;
362 
363  virtual Expr *eval(GCMain &gc, Environment &env) noexcept override;
364  virtual bool equals(const Expr *expr, bool exact = false) const noexcept override;
365 
366  virtual Expr *optimize(GCMain &gc) noexcept override;
367  virtual UnOpExpr *optimize(GCMain &gc, std::vector<Expr*> &exprs) noexcept;
368 };
369 
370 const Expr *assignExpressions(GCMain &gc, Environment &env,
371  const Expr *thisExpr,
372  const Expr *lhs, const Expr *rhs) noexcept;
373 
376 class NumExpr : public Expr {
377  double num;
378 public:
379  NumExpr(GCMain &gc, const TokenPos &pos, double num)
380  : Expr(gc, expr_num, pos), num{num} {
381  depth = 1;
382  }
383 
384  virtual ~NumExpr() {}
385 
386  double getNumber() const noexcept { return num; }
387 
388  virtual std::string toString() const noexcept override {
389  return std::to_string(num);
390  }
391 
392  virtual bool equals(const Expr *expr, bool exact = false) const noexcept override;
393 };
394 
397 class IntExpr : public Expr {
398  std::int64_t num;
399 public:
400  IntExpr(GCMain &gc, const TokenPos &pos, std::int64_t num)
401  : Expr(gc, expr_int, pos), num{num} {
402  depth = 1;
403  }
404 
405  virtual ~IntExpr() {}
406 
407  std::int64_t getNumber() const noexcept { return num; }
408 
409  virtual std::string toString() const noexcept override {
410  return std::to_string(num);
411  }
412 
413  virtual bool equals(const Expr *expr, bool exact = false) const noexcept override;
414 };
415 
416 
419 class IdExpr : public Expr {
420  std::string id;
421 public:
422  IdExpr(GCMain &gc, const TokenPos &pos, const std::string &id)
423  : Expr(gc, expr_id, pos), id(id) {
424  depth = 1;
425  }
426 
427  virtual ~IdExpr() {}
428 
429  const std::string &getName() const noexcept { return id; }
430 
431  virtual std::string toString() const noexcept override {
432  return id;
433  }
434 
435  virtual Expr *eval(GCMain &gc, Environment &env) noexcept override;
436  virtual Expr *replace(GCMain &gc, const std::string &name, Expr *expr) const noexcept override;
437 
438  virtual bool equals(const Expr *expr, bool exact = false) const noexcept override;
439 
440  virtual std::vector<std::string> getIdentifiers() const noexcept override {
441  std::vector<std::string> result;
442  result.push_back(id);
443  return result;
444  }
445 };
446 
449 class LambdaExpr : public Expr {
450  std::string name;
451  Expr* expr;
452 public:
453  LambdaExpr(GCMain &gc, const TokenPos &pos, const std::string &name,
454  Expr* expr)
455  : Expr(gc, expr_lambda, TokenPos(pos, expr->getTokenPos())),
456  name(name), expr(std::move(expr)) {
457  depth = 1 + expr->getDepth();
458  }
459 
460  virtual ~LambdaExpr() {}
461 
462  const std::string &getName() const noexcept { return name; }
463  const Expr& getExpression() const noexcept { return *expr; }
464 
465  virtual std::string toString() const noexcept override {
466  return "\\" + name + " = "
467  + expr->toString();
468  }
469 
471  virtual void mark(GCMain &gc) noexcept override {
472  if (isMarked(gc))
473  return;
474 
475  markSelf(gc);
476  if (lastEval) lastEval->mark(gc);
477  expr->mark(gc);
478  }
479 
480  /*\return Returns expression where getName() is replaced by expr.
481  * \param gc
482  * \param expr
483  */
484  Expr *replace(GCMain &gc, Expr *expr) const noexcept;
485  virtual Expr *replace(GCMain &gc, const std::string &name, Expr *expr) const noexcept override;
486 
487  virtual bool equals(const Expr *expr, bool exact = false) const noexcept override;
488 
489  virtual std::vector<std::string> getIdentifiers() const noexcept override {
490  std::vector<std::string> result = expr->getIdentifiers();
491  result.push_back(name);
492  return result;
493  }
494 
495  virtual Expr *optimize(GCMain &gc) noexcept override;
496  virtual LambdaExpr *optimize(GCMain &gc, std::vector<Expr*> &exprs) noexcept;
497 };
498 
501 class AtomExpr : public Expr {
502  std::string id;
503 public:
504  AtomExpr(GCMain &gc, const TokenPos &pos, const std::string &id)
505  : Expr(gc, expr_atom, pos), id(id) {
506  depth = 1;
507  }
508 
509  virtual ~AtomExpr() {}
510 
511  const std::string &getName() const noexcept { return id; }
512 
513  virtual std::string toString() const noexcept override {
514  return "." + id;
515  }
516 
517  virtual bool equals(const Expr *expr, bool exact = false) const noexcept override;
518 };
519 
524 class IfExpr : public Expr {
525  Expr *condition, *exprTrue, *exprFalse;
526 public:
527  IfExpr(GCMain &gc, const TokenPos &pos, Expr *condition, Expr *exprTrue, Expr *exprFalse)
528  : Expr(gc, expr_if, TokenPos(pos, exprFalse->getTokenPos())),
529  condition{condition}, exprTrue{exprTrue}, exprFalse{exprFalse} {
530  depth = 1 + condition->getDepth()
531  + exprTrue->getDepth() + exprFalse->getDepth();
532  }
533 
534  virtual ~IfExpr() {}
535 
540  const Expr& getCondition() const noexcept { return *condition; }
541 
544  const Expr& getTrue() const noexcept { return *exprTrue; }
545 
547  const Expr& getFalse() const noexcept { return *exprFalse; }
548 
549  virtual std::string toString() const noexcept override {
550  return "if " + condition->toString() + " then "
551  + exprTrue->toString() + " else " + exprFalse->toString();
552  }
553 
555  virtual void mark(GCMain &gc) noexcept override {
556  if (isMarked(gc))
557  return;
558 
559  markSelf(gc);
560  if (lastEval) lastEval->mark(gc);
561  condition->mark(gc);
562  exprTrue->mark(gc);
563  exprFalse->mark(gc);
564  }
565 
566  virtual Expr *eval(GCMain &gc, Environment &env) noexcept override;
567  virtual Expr *replace(GCMain &gc, const std::string &name, Expr *expr) const noexcept override;
568 
569  virtual bool equals(const Expr *expr, bool exact = false) const noexcept override;
570 
571  virtual std::vector<std::string> getIdentifiers() const noexcept override {
572  std::vector<std::string> result = condition->getIdentifiers();
573  for (std::string &id : exprTrue->getIdentifiers())
574  result.push_back(id);
575  for (std::string &id : exprFalse->getIdentifiers())
576  result.push_back(id);
577 
578  return result;
579  }
580 
581  virtual Expr *optimize(GCMain &gc) noexcept override;
582  virtual Expr *optimize(GCMain &gc, std::vector<Expr*> &exprs) noexcept;
583 };
584 
589 class AnyExpr : public Expr {
590 public:
591  AnyExpr(GCMain &gc, const TokenPos &pos)
592  : Expr(gc, expr_any, pos) {
593  depth = 1;
594  }
595  virtual ~AnyExpr() {}
596 
597  virtual bool equals(const Expr *expr, bool exact = false) const noexcept override;
598 
599  virtual std::string toString() const noexcept override {
600  return std::string("_");
601  }
602 };
603 
606 class LetExpr : public Expr {
607  std::vector<BiOpExpr*> assignments;
608  Expr *body;
609 public:
615  LetExpr(GCMain &gc, const TokenPos &pos, const std::vector<BiOpExpr*> &assignments, Expr *body)
616  : Expr(gc, expr_let, TokenPos(pos, body->getTokenPos())),
617  assignments(assignments), body{body} {
618  depth = 1 + body->getDepth();
619  for (BiOpExpr *expr : assignments) depth += expr->getDepth();
620  }
621 
622  virtual ~LetExpr() {}
623 
626  const std::vector<BiOpExpr*> &getAssignments() const noexcept
627  { return assignments; }
628 
631  const Expr &getBody() const noexcept { return *body; }
632 
633  virtual void mark(GCMain &gc) noexcept {
634  if (isMarked(gc))
635  return;
636 
637  markSelf(gc);
638  if(lastEval) lastEval->mark(gc);
639  for (BiOpExpr *expr : assignments)
640  expr->mark(gc);
641 
642  body->mark(gc);
643  }
644 
645  virtual Expr *eval(GCMain &gc, Environment &env) noexcept;
646  virtual Expr *replace(GCMain &gc, const std::string &name, Expr *expr) const noexcept override;
647 
648  virtual std::vector<std::string> getIdentifiers() const noexcept override {
649  std::vector<std::string> result = body->getIdentifiers();
650  for (BiOpExpr *expr : assignments)
651  for (std::string &id : expr->getIdentifiers())
652  result.push_back(id);
653 
654  return result;
655  }
656 
657  virtual bool equals(const Expr *expr, bool exact = false) const noexcept override;
658 
659  virtual std::string toString() const noexcept override {
660  std::string result = "let ";
661  auto &asgs = const_cast<std::vector<BiOpExpr*>&>(assignments);
662  for (auto it = asgs.begin(); it != assignments.end(); ++it) {
663  if (it != assignments.begin())
664  result += "; ";
665 
666  result += (*it)->toString();
667  }
668 
669  return result + " in " + body->toString();
670  }
671 
672  virtual Expr *optimize(GCMain &gc) noexcept override;
673  virtual Expr *optimize(GCMain &gc, std::vector<Expr*> &exprs) noexcept;
674 };
675 
678 class FunctionExpr : public Expr {
679  std::string name;
680  std::vector<std::pair<std::vector<Expr*>, Expr*>> fncases;
681 public:
682  FunctionExpr(GCMain &gc, const TokenPos &pos,
683  const std::string &name,
684  std::pair<std::vector<Expr*>, Expr*> fncase) noexcept;
685 
686  virtual ~FunctionExpr() {}
687 
688  void calcDepth() noexcept;
689 
696  bool addCase(std::pair<std::vector<Expr*>, Expr*> fncase) noexcept;
697 
700  const std::string &getName() const noexcept { return name; }
701 
702  std::vector<std::pair<std::vector<Expr*>, Expr*>> &getFunctionCases()
703  noexcept { return fncases; }
704  const std::vector<std::pair<std::vector<Expr*>, Expr*>> &getFunctionCases()
705  const noexcept { return fncases; }
706 
707  virtual void mark(GCMain &gc) noexcept override;
708 
709  virtual Expr *eval(GCMain &gc, Environment &env) noexcept;
710 
711  virtual std::string toString() const noexcept override {
712  return getName();
713  }
714 };
715 
716 Expr *reportSyntaxError(Lexer &lexer, const std::string &msg,
717  const TokenPos &pos);
718 
725 Expr *eval(GCMain &gc, Environment &env, Expr *expr) noexcept;
726 
734 void breadthEval(GCMain &gc, Environment &env,
735  StackFrameObj<Expr> &lhs, StackFrameObj<Expr> &rhs) noexcept;
736 
737 #endif /* FUNC_SYNTAX_HPP */
LetExpr(GCMain &gc, const TokenPos &pos, const std::vector< BiOpExpr * > &assignments, Expr *body)
Initialize let expression.
Definition: syntax.hpp:615
virtual Expr * eval(GCMain &gc, Environment &env) noexcept override
Evaluates expression one time.
const Expr & getLHS() const noexcept
Definition: syntax.hpp:293
const Expr * get(const std::string &name) const noexcept
virtual std::string toString() const noexcept override
Definition: syntax.hpp:711
const std::string & getName() const noexcept
Definition: syntax.hpp:700
T * operator *() const noexcept
Definition: syntax.hpp:110
virtual void mark(GCMain &gc) noexcept override
If not marked mark itself and children.
virtual Expr * optimize(GCMain &gc) noexcept override
void breadthEval(GCMain &gc, Environment &env, StackFrameObj< Expr > &lhs, StackFrameObj< Expr > &rhs) noexcept
Executes eval function for given expressions as long as differenct expr returned. Breadth first execu...
virtual std::string toString() const noexcept override
Definition: syntax.hpp:599
virtual Expr * replace(GCMain &gc, const std::string &name, Expr *expr) const noexcept
Replace all identifiers equal to name with expr.
Definition: syntax.hpp:239
GCObj(GCMain &main) noexcept
Initialize as not marked.
Definition: lexer.hpp:96
Lexical Analysis/Tokenizer.
bool isAtomConstructor() const noexcept
Lambda function expression.
Definition: syntax.hpp:449
Integer number.
Definition: syntax.hpp:30
virtual Expr * eval(GCMain &gc, Environment &env) noexcept override
Evaluates expression one time.
virtual bool equals(const Expr *expr, bool exact=false) const noexcept override
Checks if this expression and expr have the same structure, Every expression has the same structure a...
virtual std::string toString() const noexcept override
Definition: syntax.hpp:295
const Expr & getTrue() const noexcept
Definition: syntax.hpp:544
Operator getOperator() const noexcept
Definition: syntax.hpp:287
Represents a named function.
Definition: syntax.hpp:678
const TokenPos & getTokenPos() const noexcept
Definition: syntax.hpp:202
Floating point number expression.
Definition: syntax.hpp:376
virtual Expr * eval(GCMain &gc, Environment &env) noexcept
Evaluates expression one time.
Definition: syntax.hpp:219
const Expr & getRHS() const noexcept
Definition: syntax.hpp:290
Implements a tracing garbage collector.
Definition: gc.hpp:35
virtual void mark(GCMain &gc) noexcept override
Mark self and expr.
Definition: syntax.hpp:471
bool operator !=(T *expr) const noexcept
Definition: syntax.hpp:131
Definition: lexer.hpp:66
Atom expression.
Definition: syntax.hpp:501
Lambda function.
Definition: syntax.hpp:32
Environment * getParent() const noexcept
Definition: syntax.hpp:73
ExprType getExpressionType() const noexcept
Definition: syntax.hpp:212
virtual void mark(GCMain &gc) noexcept
If not marked mark itself and children.
Definition: syntax.hpp:633
virtual std::string toString() const noexcept override
Definition: syntax.hpp:431
Not a real operator (functional substition)
Definition: lexer.hpp:63
Any '_'.
Definition: syntax.hpp:35
Let expression.
Definition: syntax.hpp:606
virtual Expr * replace(GCMain &gc, const std::string &name, Expr *expr) const noexcept override
Replace all identifiers equal to name with expr.
ExprType
Types of expressions.
Definition: syntax.hpp:26
virtual std::string toString() const noexcept
Definition: syntax.hpp:207
Class for adding Expr's to stack frame of Environment.
Definition: syntax.hpp:85
virtual void mark(GCMain &gc) noexcept override
Mark self, rhs and lhs.
Definition: syntax.hpp:304
Operator
Operator type.
Definition: lexer.hpp:45
virtual void mark(GCMain &gc) noexcept override
If not marked mark itself and children.
bool operator==(T *expr) const noexcept
Definition: syntax.hpp:117
Expr * evalWithLookup(GCMain &gc, Environment &env) noexcept
std::vector< Expr * > ctx
Context to store e.g. stack variables.
Definition: syntax.hpp:47
bool contains(const std::string &name) const noexcept
const std::vector< BiOpExpr * > & getAssignments() const noexcept
Definition: syntax.hpp:626
const Expr & getFalse() const noexcept
Evaluated if condition evaluated to the atom .true.
Definition: syntax.hpp:547
any expression
Definition: syntax.hpp:589
Binary operator.
Definition: syntax.hpp:27
virtual std::vector< std::string > getIdentifiers() const noexcept override
Definition: syntax.hpp:648
Binary operator expression.
Definition: syntax.hpp:268
Floating-point Number.
Definition: syntax.hpp:29
virtual std::string toString() const noexcept override
Definition: syntax.hpp:465
virtual std::string toString() const noexcept override
Definition: syntax.hpp:549
Atom.
Definition: syntax.hpp:33
Tracing garbage collection.
bool operator !=(StackFrameObj< T > &obj) const noexcept
Definition: syntax.hpp:138
const Expr & getCondition() const noexcept
Condition of the if-then-else expression.
Definition: syntax.hpp:540
Unary left-operator.
Definition: syntax.hpp:28
Let statement.
Definition: syntax.hpp:36
virtual void markSelf(GCMain &main)
Marks itself.
StackFrameObj< T > & operator=(StackFrameObj< T > &obj) noexcept
Assigns **this = *obj. Removes old expression from stack frame and adds *obj to stack frame.
Definition: syntax.hpp:162
Garbage collection object (objects to collect).
Definition: gc.hpp:15
If-then-else expression.
Definition: syntax.hpp:524
virtual bool isMarked(GCMain &main) const noexcept
File for managing external headers.
StackFrameObj< T > & operator=(T *expr) noexcept
Definition: syntax.hpp:146
Identifier.
Definition: syntax.hpp:31
virtual std::string toString() const noexcept override
Definition: syntax.hpp:388
Definition: syntax.hpp:348
virtual bool equals(const Expr *expr, bool exact=false) const noexcept
Checks if this expression and expr have the same structure, Every expression has the same structure a...
Definition: syntax.hpp:249
Main expression handle (should only be used as parent class).
Definition: syntax.hpp:179
virtual std::vector< std::string > getIdentifiers() const noexcept
Definition: syntax.hpp:254
virtual bool equals(const Expr *expr, bool exact=false) const noexcept override
Checks if this expression and expr have the same structure, Every expression has the same structure a...
const AtomExpr * getAtomConstructor() const noexcept
virtual std::string toString() const noexcept override
Definition: syntax.hpp:409
Environment for accessing variables.
Definition: syntax.hpp:42
virtual Expr * optimize(GCMain &gc) noexcept
bool hasLastEval() const noexcept
Definition: syntax.hpp:198
virtual std::vector< std::string > getIdentifiers() const noexcept override
Definition: syntax.hpp:332
const Expr * currentGet(const std::string &name) const noexcept
Integer number expression.
Definition: syntax.hpp:397
const Expr & getBody() const noexcept
Definition: syntax.hpp:631
Intern statement for named functions.
Definition: syntax.hpp:37
virtual Expr * optimize(GCMain &gc) noexcept override
Identifier expression.
Definition: syntax.hpp:419
virtual bool equals(const Expr *expr, bool exact=false) const noexcept override
Checks if this expression and expr have the same structure, Every expression has the same structure a...
virtual std::string toString() const noexcept override
Definition: syntax.hpp:513
virtual void mark(GCMain &gc) noexcept override
If not marked mark itself and children.
If-then-else.
Definition: syntax.hpp:34
virtual void mark(GCMain &gc) noexcept override
Mark self, condition, exprTrue and exprFalse.
Definition: syntax.hpp:555