This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from DemonExposer/loops
Implemented while loops and refactored
- Loading branch information
Showing
5 changed files
with
48 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,12 @@ | ||
using System.Text; | ||
using Interpreter.Tokens.Operators.Unary; | ||
using Boolean = Interpreter.Types.Comparable.Boolean; | ||
using Object = Interpreter.Types.Object; | ||
|
||
namespace Interpreter.Tokens.Statements; | ||
|
||
public class OnStatement : Statement { | ||
public string Symbol = "on"; | ||
public ParenthesesOperator Left = null!; | ||
public Token Right = null!; | ||
|
||
public override string ToString(int indent) { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
StringBuilder indentSb = new StringBuilder(); | ||
for (int i = 0; i < indent; i++) | ||
indentSb.Append('\t'); | ||
string indentStr = indentSb.ToString(); | ||
|
||
sb.Append(indentStr).Append(Symbol).Append('\n'); | ||
if (Left != null!) | ||
sb.Append(Left.ToString(indent+1)); | ||
if (Right != null!) | ||
sb.Append(Right.ToString(indent+1)); | ||
|
||
return sb.ToString(); | ||
public OnStatement() { | ||
Symbol = "on"; | ||
} | ||
|
||
public override Object Evaluate() => ((Boolean) Left.Evaluate()).Bool ? Right.Evaluate() : null!; | ||
|
||
public override int Size() => 1 + Left.Size() + Right.Size(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
using System.Text; | ||
using Interpreter.Tokens.Operators.Unary; | ||
|
||
namespace Interpreter.Tokens.Statements; | ||
|
||
public abstract class Statement : Token { | ||
public string Symbol = null!; | ||
public ParenthesesOperator Left = null!; | ||
public Token Right = null!; | ||
|
||
public override string ToString(int indent) { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
StringBuilder indentSb = new StringBuilder(); | ||
for (int i = 0; i < indent; i++) | ||
indentSb.Append('\t'); | ||
string indentStr = indentSb.ToString(); | ||
|
||
sb.Append(indentStr).Append(Symbol).Append('\n'); | ||
if (Left != null!) | ||
sb.Append(Left.ToString(indent+1)); | ||
if (Right != null!) | ||
sb.Append(Right.ToString(indent+1)); | ||
|
||
return sb.ToString(); | ||
} | ||
|
||
public override int Size() => 1 + Left.Size() + Right.Size(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Object = Interpreter.Types.Object; | ||
using Boolean = Interpreter.Types.Comparable.Boolean; | ||
|
||
namespace Interpreter.Tokens.Statements; | ||
|
||
public class WhileLoop : Statement { | ||
public WhileLoop() { | ||
Symbol = "while"; | ||
} | ||
|
||
public override Object Evaluate() { | ||
while (((Boolean) Left.Evaluate()).Bool) | ||
Right.Evaluate(); | ||
|
||
return null!; | ||
} | ||
} |