Created
September 13, 2020 08:23
-
-
Save gaufung/a35376d9d2416ef8cb0f68f3fd27ea4e to your computer and use it in GitHub Desktop.
Calculator Expression
This file contains hidden or 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
public abstract class Expression | |
{ | |
public abstract string TokenLiteral(); | |
} | |
//IntegerExpression.cs | |
public class IntegerExpression : Expression | |
{ | |
public Token Token { get; set; } | |
public long Value { get; set; } | |
//... | |
public override string ToString() | |
{ | |
return $"{Value}"; | |
} | |
} | |
// PrefixExpression.cs | |
public class PrefixExpression : Expression | |
{ | |
public Token Token { get; set; } | |
public Expression Right { get; set; } | |
public string Operator { get; set; } | |
public override string ToString() | |
{ | |
return $"({Token.Literal} {Right.ToString()})"; | |
} | |
} | |
//InfixExpression.cs | |
public class InfixExpression : Expression | |
{ | |
public Expression Left { get; set; } | |
public Expression Right { get; set; } | |
public Token Token { get; set; } | |
public string Operator { get; set; | |
public override string ToString() | |
{ | |
return $"({Left.ToString()} {Token.Literal} {Right.ToString()})"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment