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