Created
September 13, 2020 08:25
-
-
Save gaufung/e221e42144c8706cde6ac42b1ba5ed9a to your computer and use it in GitHub Desktop.
Calculator Parser
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
| //Pecedence.cs | |
| public enum Precedence | |
| { | |
| LOWEST = 0, | |
| SUM = 1, | |
| PRODUCT = 2, | |
| PREFIX = 3, | |
| POWER = 4, | |
| GROUP = 5, | |
| } | |
| //Parser.cs | |
| public class Parser | |
| { | |
| //... | |
| private static IDictionary<TokenType, Precedence> _precedences = new Dictionary<TokenType, Precedence> | |
| { | |
| {TokenType.PLUS, Precedence.SUM}, | |
| {TokenType.MINUS, Precedence.SUM}, | |
| {TokenType.MULTIPLY, Precedence.PRODUCT}, | |
| {TokenType.DIVIDE, Precedence.PRODUCT}, | |
| {TokenType.POWER, Precedence.POWER}, | |
| {TokenType.LPAREN, Precedence.GROUP} | |
| }; | |
| //... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment