Phasor 3.3.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
AST.hpp
Go to the documentation of this file.
1#pragma once
2#include <iostream>
3#include <memory>
4#include <string>
5#include <utility>
6#include <vector>
7#include <filesystem>
8#include <format>
9
11namespace Phasor
12{
24
25struct Token
26{
28 std::string lexeme;
29 size_t line;
30 size_t column;
31};
32
34namespace AST
35{
36
37// Forward declarations
38struct Node;
39struct Expression;
40struct Statement;
41struct Program;
42
44struct Node
45{
46 virtual ~Node() = default;
47 virtual void print(int indent = 0) const = 0;
48 size_t line = 0;
49 size_t column = 0;
50};
51
53struct Expression : public Node
54{
55};
56
58struct Statement : public Node
59{
60};
61
63struct Program : public Node
64{
65 std::vector<std::unique_ptr<Statement>> statements;
66 void print(int indent = 0) const override
67 {
68 for (const auto &stmt : statements)
69 {
70 stmt->print(indent);
71 }
72 }
73};
74
76struct TypeNode : public Node
77{
78 std::string name;
79 bool isPointer = false;
80 std::vector<int> arrayDimensions;
81
82 TypeNode(std::string n, bool ptr = false, std::vector<int> dims = {})
83 : name(std::move(n)), isPointer(ptr), arrayDimensions(std::move(dims))
84 {
85 }
86 void print(int indent = 0) const override
87 {
88 std::cout << std::format("{:>{}}Type: {}\n", "", indent, name);
89 for (int dim : arrayDimensions)
90 {
91 std::cout << std::format("{:>{}}ArrayDim: {}\n", "", indent + 2, dim);
92 }
93 }
94};
95
97struct NumberExpr : public Expression
98{
99 std::string value;
100 NumberExpr(std::string v) : value(std::move(v))
101 {
102 }
103 void print(int indent = 0) const override
104 {
105 std::cout << std::format("{:>{}}Number: {}\n", "", indent, value);
106 }
107};
108
110struct StringExpr : public Expression
111{
112 std::string value;
113 StringExpr(std::string v) : value(std::move(v))
114 {
115 }
116 void print(int indent = 0) const override
117 {
118
119 std::cout << std::format("{:>{}}String: {}\n", "", indent, value);
120 }
121};
122
125{
126 std::string name;
127 IdentifierExpr(std::string n) : name(std::move(n))
128 {
129 }
130 void print(int indent = 0) const override
131 {
132 std::cout << std::format("{:>{}}Identifier: {}\n", "", indent, name);
133 }
134};
135
137struct BooleanExpr : public Expression
138{
139 bool value;
140 BooleanExpr(bool v) : value(v)
141 {
142 }
143 void print(int indent = 0) const override
144 {
145 std::cout << std::format("{:>{}}Boolean: {}\n", "", indent, value);
146 }
147};
148
150struct NullExpr : public Expression
151{
152 void print(int indent = 0) const override
153 {
154 std::cout << std::string(indent, ' ') << "Null\n";
155 }
156};
157
159enum class UnaryOp : uint8_t
160{
161 Negate, // -x
162 Not, // !x
165};
166
184
186enum class PostfixOp : uint8_t
187{
188 Increment, // x++
190};
191
193struct PostfixExpr : public Expression
194{
196 std::unique_ptr<Expression> operand;
197
198 PostfixExpr(PostfixOp o, std::unique_ptr<Expression> expr) : op(o), operand(std::move(expr))
199 {
200 }
201
202 void print(int indent = 0) const override
203 {
204 std::cout << std::string(indent, ' ') << "PostfixExpr: ";
205 switch (op)
206 {
208 std::cout << "++\n";
209 break;
211 std::cout << "--\n";
212 break;
213 }
214 operand->print(indent + 2);
215 }
216};
217
219struct UnaryExpr : public Expression
220{
222 std::unique_ptr<Expression> operand;
223
224 UnaryExpr(UnaryOp o, std::unique_ptr<Expression> expr) : op(o), operand(std::move(expr))
225 {
226 }
227
228 void print(int indent = 0) const override
229 {
230 std::cout << std::string(indent, ' ') << "UnaryExpr: ";
231 switch (op)
232 {
233 case UnaryOp::Negate:
234 std::cout << "-\n";
235 break;
236 case UnaryOp::Not:
237 std::cout << "!\n";
238 break;
240 std::cout << "&\n";
241 break;
243 std::cout << "*\n";
244 break;
245 }
246 operand->print(indent + 2);
247 }
248};
249
251struct BinaryExpr : public Expression
252{
253 std::unique_ptr<Expression> left;
255 std::unique_ptr<Expression> right;
256
257 BinaryExpr(std::unique_ptr<Expression> l, BinaryOp o, std::unique_ptr<Expression> r)
258 : left(std::move(l)), op(o), right(std::move(r))
259 {
260 }
261
262 void print(int indent = 0) const override
263 {
264 std::cout << std::string(indent, ' ') << "BinaryExpr: ";
265 switch (op)
266 {
267 case BinaryOp::Add:
268 std::cout << "+\n";
269 break;
271 std::cout << "-\n";
272 break;
274 std::cout << "*\n";
275 break;
276 case BinaryOp::Divide:
277 std::cout << "/\n";
278 break;
279 case BinaryOp::Modulo:
280 std::cout << "%\n";
281 break;
282 case BinaryOp::And:
283 std::cout << "&&\n";
284 break;
285 case BinaryOp::Or:
286 std::cout << "||\n";
287 break;
288 case BinaryOp::Equal:
289 std::cout << "==\n";
290 break;
292 std::cout << "!=\n";
293 break;
295 std::cout << "<\n";
296 break;
298 std::cout << ">\n";
299 break;
301 std::cout << "<=\n";
302 break;
304 std::cout << ">=\n";
305 break;
306 }
307 left->print(indent + 2);
308 right->print(indent + 2);
309 }
310};
311
314{
315 std::unique_ptr<Expression> array;
316 std::unique_ptr<Expression> index;
317
318 ArrayAccessExpr(std::unique_ptr<Expression> arr, std::unique_ptr<Expression> idx)
319 : array(std::move(arr)), index(std::move(idx))
320 {
321 }
322
323 void print(int indent = 0) const override
324 {
325 std::cout << std::string(indent, ' ') << "ArrayAccess:\n";
326 array->print(indent + 2);
327 std::cout << std::string(indent + 2, ' ') << "Index:\n";
328 index->print(indent + 4);
329 }
330};
331
334{
335 std::vector<std::unique_ptr<Expression>> elements;
336 ArrayLiteralExpr(std::vector<std::unique_ptr<Expression>> elems) : elements(std::move(elems))
337 {
338 }
339 void print(int indent = 0) const override
340 {
341 std::cout << std::string(indent, ' ') << "ArrayLiteral:\n";
342 for (const auto &elem : elements)
343 {
344 elem->print(indent + 2);
345 }
346 }
347};
348
351{
352 std::unique_ptr<Expression> object;
353 std::string member;
354
355 MemberAccessExpr(std::unique_ptr<Expression> obj, std::string mem) : object(std::move(obj)), member(std::move(mem))
356 {
357 }
358
359 void print(int indent = 0) const override
360 {
361 std::cout << std::string(indent, ' ') << "MemberAccess: ." << member << "\n";
362 object->print(indent + 2);
363 }
364};
365
367struct CallExpr : public Expression
368{
369 std::string callee;
370 std::vector<std::unique_ptr<Expression>> arguments;
371
372 CallExpr(std::string name, std::vector<std::unique_ptr<Expression>> args)
373 : callee(std::move(name)), arguments(std::move(args))
374 {
375 }
376
377 void print(int indent = 0) const override
378 {
379 std::cout << std::string(indent, ' ') << "CallExpr: " << callee << "\n";
380 for (const auto &arg : arguments)
381 {
382 arg->print(indent + 2);
383 }
384 }
385};
386
389{
390 std::unique_ptr<Expression> target;
391 std::unique_ptr<Expression> value;
392
393 AssignmentExpr(std::unique_ptr<Expression> t, std::unique_ptr<Expression> v)
394 : target(std::move(t)), value(std::move(v))
395 {
396 }
397
398 void print(int indent = 0) const override
399 {
400 std::cout << std::string(indent, ' ') << "AssignmentExpr:\n";
401 std::cout << std::string(indent + 2, ' ') << "Target:\n";
402 target->print(indent + 4);
403 std::cout << std::string(indent + 2, ' ') << "Value:\n";
404 value->print(indent + 4);
405 }
406};
407
409struct VarDecl : public Statement
410{
411 std::string name;
412 std::unique_ptr<Expression> initializer;
413 VarDecl(std::string n, std::unique_ptr<Expression> init) : name(std::move(n)), initializer(std::move(init))
414 {
415 }
416 void print(int indent = 0) const override
417 {
418 std::cout << std::string(indent, ' ') << "VarDecl: " << name << "\n";
419 if (initializer)
420 {
421 initializer->print(indent + 2);
422 }
423 }
424};
425
428{
429 std::unique_ptr<Expression> expression;
430 ExpressionStmt(std::unique_ptr<Expression> expr) : expression(std::move(expr))
431 {
432 }
433 void print(int indent = 0) const override
434 {
435 expression->print(indent);
436 }
437};
438
440struct PrintStmt : public Statement
441{
442 std::unique_ptr<Expression> expression;
443 PrintStmt(std::unique_ptr<Expression> expr) : expression(std::move(expr))
444 {
445 }
446 void print(int indent = 0) const override
447 {
448 std::cout << std::string(indent, ' ') << "PrintStmt:\n";
449 expression->print(indent + 2);
450 }
451};
452
454struct IncludeStmt : public Statement
455{
456 std::filesystem::path modulePath;
457 IncludeStmt(std::filesystem::path path) : modulePath(std::move(path))
458 {
459 }
460 void print(int indent = 0) const override
461 {
462 std::cout << std::format("{:>{}}IncludeStmt: {}\n", "", indent, modulePath.string());
463 }
464};
465
467struct ImportStmt : public Statement
468{
469 std::string modulePath;
470 ImportStmt(std::string path) : modulePath(std::move(path))
471 {
472 }
473 void print(int indent = 0) const override
474 {
475 std::cout << std::string(indent, ' ') << "ImportStmt: " << modulePath << "\n";
476 }
477};
478
480struct ExportStmt : public Statement
481{
482 std::unique_ptr<Statement> declaration;
483 ExportStmt(std::unique_ptr<Statement> decl) : declaration(std::move(decl))
484 {
485 }
486 void print(int indent = 0) const override
487 {
488 std::cout << std::string(indent, ' ') << "ExportStmt:\n";
489 declaration->print(indent + 2);
490 }
491};
492
494struct BlockStmt : public Statement
495{
496 std::vector<std::unique_ptr<Statement>> statements;
497 BlockStmt(std::vector<std::unique_ptr<Statement>> stmts) : statements(std::move(stmts))
498 {
499 }
500 void print(int indent = 0) const override
501 {
502 std::cout << std::string(indent, ' ') << "BlockStmt:\n";
503 for (const auto &stmt : statements)
504 {
505 stmt->print(indent + 2);
506 }
507 }
508};
509
511struct ReturnStmt : public Statement
512{
513 std::unique_ptr<Expression> value;
514 ReturnStmt(std::unique_ptr<Expression> val) : value(std::move(val))
515 {
516 }
517 void print(int indent = 0) const override
518 {
519 std::cout << std::string(indent, ' ') << "ReturnStmt:\n";
520 if (value)
521 {
522 value->print(indent + 2);
523 }
524 }
525};
526
528struct BreakStmt : public Statement
529{
530 void print(int indent = 0) const override
531 {
532 std::cout << std::string(indent, ' ') << "BreakStmt\n";
533 }
534};
535
537struct ContinueStmt : public Statement
538{
539 void print(int indent = 0) const override
540 {
541 std::cout << std::string(indent, ' ') << "ContinueStmt\n";
542 }
543};
544
546struct IfStmt : public Statement
547{
548 std::unique_ptr<Expression> condition;
549 std::unique_ptr<Statement> thenBranch;
550 std::unique_ptr<Statement> elseBranch;
551
552 IfStmt(std::unique_ptr<Expression> cond, std::unique_ptr<Statement> thenB, std::unique_ptr<Statement> elseB)
553 : condition(std::move(cond)), thenBranch(std::move(thenB)), elseBranch(std::move(elseB))
554 {
555 }
556
557 void print(int indent = 0) const override
558 {
559 std::cout << std::string(indent, ' ') << "IfStmt:\n";
560 condition->print(indent + 2);
561 thenBranch->print(indent + 2);
562 if (elseBranch)
563 {
564 std::cout << std::string(indent, ' ') << "Else:\n";
565 elseBranch->print(indent + 2);
566 }
567 }
568};
569
571struct WhileStmt : public Statement
572{
573 std::unique_ptr<Expression> condition;
574 std::unique_ptr<Statement> body;
575
576 WhileStmt(std::unique_ptr<Expression> cond, std::unique_ptr<Statement> b)
577 : condition(std::move(cond)), body(std::move(b))
578 {
579 }
580
581 void print(int indent = 0) const override
582 {
583 std::cout << std::string(indent, ' ') << "WhileStmt:\n";
584 condition->print(indent + 2);
585 body->print(indent + 2);
586 }
587};
588
590struct ForStmt : public Statement
591{
592 std::unique_ptr<Statement> initializer;
593 std::unique_ptr<Expression> condition;
594 std::unique_ptr<Expression> increment;
595 std::unique_ptr<Statement> body;
596
597 ForStmt(std::unique_ptr<Statement> init, std::unique_ptr<Expression> cond, std::unique_ptr<Expression> incr,
598 std::unique_ptr<Statement> b)
599 : initializer(std::move(init)), condition(std::move(cond)), increment(std::move(incr)), body(std::move(b))
600 {
601 }
602
603 void print(int indent = 0) const override
604 {
605 std::cout << std::string(indent, ' ') << "ForStmt:\n";
606 if (initializer)
607 {
608 initializer->print(indent + 2);
609 }
610 if (condition)
611 {
612 condition->print(indent + 2);
613 }
614 if (increment)
615 {
616 increment->print(indent + 2);
617 }
618 body->print(indent + 2);
619 }
620};
621
624{
625 std::unique_ptr<BlockStmt> block;
626 UnsafeBlockStmt(std::unique_ptr<BlockStmt> b) : block(std::move(b))
627 {
628 }
629 void print(int indent = 0) const override
630 {
631 std::cout << std::string(indent, ' ') << "UnsafeBlockStmt:\n";
632 block->print(indent + 2);
633 }
634};
635
637struct FunctionDecl : public Statement
638{
639 std::string name;
640 struct Param
641 {
642 std::string name;
643 std::unique_ptr<TypeNode> type;
644 };
645 std::vector<Param> params;
646 std::unique_ptr<TypeNode> returnType;
647 std::unique_ptr<BlockStmt> body;
648
649 FunctionDecl(std::string n, std::vector<Param> p, std::unique_ptr<TypeNode> rt, std::unique_ptr<BlockStmt> b)
650 : name(std::move(n)), params(std::move(p)), returnType(std::move(rt)), body(std::move(b))
651 {
652 }
653
654 void print(int indent = 0) const override
655 {
656 std::cout << std::string(indent, ' ') << "FunctionDecl: " << name << "\n";
657 for (const auto &param : params)
658 {
659 std::cout << std::string(indent + 2, ' ') << "Param: " << param.name << " Type: ";
660 param.type->print(0);
661 }
662 std::cout << std::string(indent + 2, ' ') << "Return Type: ";
663 if (returnType)
664 {
665 returnType->print(0);
666 }
667 else
668 {
669 std::cout << "void\n";
670 }
671 if (body)
672 {
673 body->print(indent + 2);
674 }
675 }
676};
677
680{
681 std::string name;
682 std::unique_ptr<TypeNode> type;
683
684 StructField(std::string n, std::unique_ptr<TypeNode> t) : name(std::move(n)), type(std::move(t))
685 {
686 }
687};
688
690struct StructDecl : public Statement
691{
692 std::string name;
693 std::vector<StructField> fields;
694
695 StructDecl(std::string n, std::vector<StructField> f) : name(std::move(n)), fields(std::move(f))
696 {
697 }
698
699 void print(int indent = 0) const override
700 {
701 std::cout << std::string(indent, ' ') << "StructDecl: " << name << "\n";
702 for (const auto &field : fields)
703 {
704 std::cout << std::string(indent + 2, ' ') << field.name << ": ";
705 field.type->print(0);
706 }
707 }
708};
709
712{
713 std::string structName;
714 std::vector<std::pair<std::string, std::unique_ptr<Expression>>> fieldValues;
715
716 StructInstanceExpr(std::string name, std::vector<std::pair<std::string, std::unique_ptr<Expression>>> fields)
717 : structName(std::move(name)), fieldValues(std::move(fields))
718 {
719 }
720
721 void print(int indent = 0) const override
722 {
723 std::cout << std::string(indent, ' ') << "StructInstance: " << structName << "\n";
724 for (const auto &field : fieldValues)
725 {
726 std::cout << std::string(indent + 2, ' ') << field.first << ":\n";
727 field.second->print(indent + 4);
728 }
729 }
730};
731
734{
735 std::unique_ptr<Expression> object;
736 std::string fieldName;
737
738 FieldAccessExpr(std::unique_ptr<Expression> obj, std::string field)
739 : object(std::move(obj)), fieldName(std::move(field))
740 {
741 }
742
743 void print(int indent = 0) const override
744 {
745 std::cout << std::string(indent, ' ') << "FieldAccess: ." << fieldName << "\n";
746 object->print(indent + 2);
747 }
748};
749
752{
753 std::unique_ptr<Expression> value;
754 std::vector<std::unique_ptr<Statement>> statements;
755
756 CaseClause(std::unique_ptr<Expression> v, std::vector<std::unique_ptr<Statement>> stmts)
757 : value(std::move(v)), statements(std::move(stmts))
758 {
759 }
760};
761
763struct SwitchStmt : public Statement
764{
765 std::unique_ptr<Expression> expr;
766 std::vector<CaseClause> cases;
767 std::vector<std::unique_ptr<Statement>> defaultStmts;
768
769 SwitchStmt(std::unique_ptr<Expression> e, std::vector<CaseClause> c, std::vector<std::unique_ptr<Statement>> d)
770 : expr(std::move(e)), cases(std::move(c)), defaultStmts(std::move(d))
771 {
772 }
773
774 void print(int indent = 0) const override
775 {
776 std::cout << std::string(indent, ' ') << "SwitchStmt:\n";
777 expr->print(indent + 2);
778 for (const auto &c : cases)
779 {
780 std::cout << std::string(indent + 2, ' ') << "case:\n";
781 c.value->print(indent + 4);
782 for (const auto &stmt : c.statements)
783 {
784 stmt->print(indent + 4);
785 }
786 }
787 if (!defaultStmts.empty())
788 {
789 std::cout << std::string(indent + 2, ' ') << "default:\n";
790 for (const auto &stmt : defaultStmts)
791 {
792 stmt->print(indent + 4);
793 }
794 }
795 }
796};
797} // namespace AST
798} // namespace Phasor
Abstract Syntax Tree (AST) namespace.
Definition AST.hpp:35
UnaryOp
Unary operator types.
Definition AST.hpp:160
BinaryOp
Binary operator types.
Definition AST.hpp:169
PostfixOp
Postfix operator types.
Definition AST.hpp:187
The Phasor Programming Language and Runtime.
Definition AST.hpp:12
TokenType
Token types for the lexer.
Definition AST.hpp:15
ArrayAccessExpr(std::unique_ptr< Expression > arr, std::unique_ptr< Expression > idx)
Definition AST.hpp:318
std::unique_ptr< Expression > array
Definition AST.hpp:315
void print(int indent=0) const override
Definition AST.hpp:323
std::unique_ptr< Expression > index
Definition AST.hpp:316
void print(int indent=0) const override
Definition AST.hpp:339
std::vector< std::unique_ptr< Expression > > elements
Definition AST.hpp:335
ArrayLiteralExpr(std::vector< std::unique_ptr< Expression > > elems)
Definition AST.hpp:336
AssignmentExpr(std::unique_ptr< Expression > t, std::unique_ptr< Expression > v)
Definition AST.hpp:393
std::unique_ptr< Expression > target
Definition AST.hpp:390
std::unique_ptr< Expression > value
Definition AST.hpp:391
void print(int indent=0) const override
Definition AST.hpp:398
std::unique_ptr< Expression > right
Definition AST.hpp:255
BinaryExpr(std::unique_ptr< Expression > l, BinaryOp o, std::unique_ptr< Expression > r)
Definition AST.hpp:257
std::unique_ptr< Expression > left
Definition AST.hpp:253
void print(int indent=0) const override
Definition AST.hpp:262
std::vector< std::unique_ptr< Statement > > statements
Definition AST.hpp:496
void print(int indent=0) const override
Definition AST.hpp:500
BlockStmt(std::vector< std::unique_ptr< Statement > > stmts)
Definition AST.hpp:497
void print(int indent=0) const override
Definition AST.hpp:143
Break Statement Node.
Definition AST.hpp:529
void print(int indent=0) const override
Definition AST.hpp:530
CallExpr(std::string name, std::vector< std::unique_ptr< Expression > > args)
Definition AST.hpp:372
std::string callee
Definition AST.hpp:369
std::vector< std::unique_ptr< Expression > > arguments
Definition AST.hpp:370
void print(int indent=0) const override
Definition AST.hpp:377
CaseClause(std::unique_ptr< Expression > v, std::vector< std::unique_ptr< Statement > > stmts)
Definition AST.hpp:756
std::vector< std::unique_ptr< Statement > > statements
Definition AST.hpp:754
std::unique_ptr< Expression > value
Definition AST.hpp:753
Continue Statement Node.
Definition AST.hpp:538
void print(int indent=0) const override
Definition AST.hpp:539
ExportStmt(std::unique_ptr< Statement > decl)
Definition AST.hpp:483
void print(int indent=0) const override
Definition AST.hpp:486
std::unique_ptr< Statement > declaration
Definition AST.hpp:482
std::unique_ptr< Expression > expression
Definition AST.hpp:429
ExpressionStmt(std::unique_ptr< Expression > expr)
Definition AST.hpp:430
void print(int indent=0) const override
Definition AST.hpp:433
Expression Node.
Definition AST.hpp:54
FieldAccessExpr(std::unique_ptr< Expression > obj, std::string field)
Definition AST.hpp:738
void print(int indent=0) const override
Definition AST.hpp:743
std::unique_ptr< Expression > object
Definition AST.hpp:735
std::unique_ptr< Statement > initializer
Definition AST.hpp:592
std::unique_ptr< Expression > increment
Definition AST.hpp:594
void print(int indent=0) const override
Definition AST.hpp:603
std::unique_ptr< Statement > body
Definition AST.hpp:595
ForStmt(std::unique_ptr< Statement > init, std::unique_ptr< Expression > cond, std::unique_ptr< Expression > incr, std::unique_ptr< Statement > b)
Definition AST.hpp:597
std::unique_ptr< Expression > condition
Definition AST.hpp:593
std::unique_ptr< TypeNode > type
Definition AST.hpp:643
FunctionDecl(std::string n, std::vector< Param > p, std::unique_ptr< TypeNode > rt, std::unique_ptr< BlockStmt > b)
Definition AST.hpp:649
std::unique_ptr< TypeNode > returnType
Definition AST.hpp:646
void print(int indent=0) const override
Definition AST.hpp:654
std::vector< Param > params
Definition AST.hpp:645
std::unique_ptr< BlockStmt > body
Definition AST.hpp:647
IdentifierExpr(std::string n)
Definition AST.hpp:127
void print(int indent=0) const override
Definition AST.hpp:130
void print(int indent=0) const override
Definition AST.hpp:557
std::unique_ptr< Statement > elseBranch
Definition AST.hpp:550
std::unique_ptr< Expression > condition
Definition AST.hpp:548
IfStmt(std::unique_ptr< Expression > cond, std::unique_ptr< Statement > thenB, std::unique_ptr< Statement > elseB)
Definition AST.hpp:552
std::unique_ptr< Statement > thenBranch
Definition AST.hpp:549
ImportStmt(std::string path)
Definition AST.hpp:470
std::string modulePath
Definition AST.hpp:469
void print(int indent=0) const override
Definition AST.hpp:473
std::filesystem::path modulePath
Definition AST.hpp:456
IncludeStmt(std::filesystem::path path)
Definition AST.hpp:457
void print(int indent=0) const override
Definition AST.hpp:460
std::unique_ptr< Expression > object
Definition AST.hpp:352
void print(int indent=0) const override
Definition AST.hpp:359
MemberAccessExpr(std::unique_ptr< Expression > obj, std::string mem)
Definition AST.hpp:355
AST Node.
Definition AST.hpp:45
size_t line
Definition AST.hpp:48
virtual void print(int indent=0) const =0
virtual ~Node()=default
size_t column
Definition AST.hpp:49
NULL Expression Node.
Definition AST.hpp:151
void print(int indent=0) const override
Definition AST.hpp:152
std::string value
Definition AST.hpp:99
NumberExpr(std::string v)
Definition AST.hpp:100
void print(int indent=0) const override
Definition AST.hpp:103
PostfixExpr(PostfixOp o, std::unique_ptr< Expression > expr)
Definition AST.hpp:198
std::unique_ptr< Expression > operand
Definition AST.hpp:196
void print(int indent=0) const override
Definition AST.hpp:202
std::unique_ptr< Expression > expression
Definition AST.hpp:442
void print(int indent=0) const override
Definition AST.hpp:446
PrintStmt(std::unique_ptr< Expression > expr)
Definition AST.hpp:443
Program Node.
Definition AST.hpp:64
std::vector< std::unique_ptr< Statement > > statements
Definition AST.hpp:65
void print(int indent=0) const override
Definition AST.hpp:66
ReturnStmt(std::unique_ptr< Expression > val)
Definition AST.hpp:514
std::unique_ptr< Expression > value
Definition AST.hpp:513
void print(int indent=0) const override
Definition AST.hpp:517
Statement Node.
Definition AST.hpp:59
void print(int indent=0) const override
Definition AST.hpp:116
std::string value
Definition AST.hpp:112
StringExpr(std::string v)
Definition AST.hpp:113
void print(int indent=0) const override
Definition AST.hpp:699
std::vector< StructField > fields
Definition AST.hpp:693
std::string name
Definition AST.hpp:692
StructDecl(std::string n, std::vector< StructField > f)
Definition AST.hpp:695
StructField(std::string n, std::unique_ptr< TypeNode > t)
Definition AST.hpp:684
std::unique_ptr< TypeNode > type
Definition AST.hpp:682
StructInstanceExpr(std::string name, std::vector< std::pair< std::string, std::unique_ptr< Expression > > > fields)
Definition AST.hpp:716
std::vector< std::pair< std::string, std::unique_ptr< Expression > > > fieldValues
Definition AST.hpp:714
void print(int indent=0) const override
Definition AST.hpp:721
SwitchStmt(std::unique_ptr< Expression > e, std::vector< CaseClause > c, std::vector< std::unique_ptr< Statement > > d)
Definition AST.hpp:769
void print(int indent=0) const override
Definition AST.hpp:774
std::vector< CaseClause > cases
Definition AST.hpp:766
std::vector< std::unique_ptr< Statement > > defaultStmts
Definition AST.hpp:767
std::unique_ptr< Expression > expr
Definition AST.hpp:765
TypeNode(std::string n, bool ptr=false, std::vector< int > dims={})
Definition AST.hpp:82
void print(int indent=0) const override
Definition AST.hpp:86
std::vector< int > arrayDimensions
Definition AST.hpp:80
std::string name
Definition AST.hpp:78
UnaryExpr(UnaryOp o, std::unique_ptr< Expression > expr)
Definition AST.hpp:224
std::unique_ptr< Expression > operand
Definition AST.hpp:222
void print(int indent=0) const override
Definition AST.hpp:228
UnsafeBlockStmt(std::unique_ptr< BlockStmt > b)
Definition AST.hpp:626
void print(int indent=0) const override
Definition AST.hpp:629
std::unique_ptr< BlockStmt > block
Definition AST.hpp:625
void print(int indent=0) const override
Definition AST.hpp:416
VarDecl(std::string n, std::unique_ptr< Expression > init)
Definition AST.hpp:413
std::string name
Definition AST.hpp:411
std::unique_ptr< Expression > initializer
Definition AST.hpp:412
WhileStmt(std::unique_ptr< Expression > cond, std::unique_ptr< Statement > b)
Definition AST.hpp:576
std::unique_ptr< Expression > condition
Definition AST.hpp:573
std::unique_ptr< Statement > body
Definition AST.hpp:574
void print(int indent=0) const override
Definition AST.hpp:581
Token structure.
Definition AST.hpp:26
size_t line
Definition AST.hpp:29
std::string lexeme
Definition AST.hpp:28
TokenType type
Definition AST.hpp:27
size_t column
Definition AST.hpp:30