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