// Add a new token to the list public void AddToken(MathToken tokenToAdd) { if (TokenList == null) { TokenList = new List <MathToken>(); TokenList.Add(tokenToAdd); } else { //check if the token is the same type as last token var a = tokenToAdd is OperatorToken; var b = TokenList[TokenList.Count - 1] is OperatorToken; //the tokens are different if (a != b) { //add new token TokenList.Add(tokenToAdd); } else { //replace last token TokenList[TokenList.Count - 1] = tokenToAdd; } } }
public bool validate() { if (TokenList == null) { return(false); } for (int i = 0; i < TokenList.Count - 1; i++) { MathToken currenttoken = TokenList[i]; if (currenttoken is OperatorToken) { if ((currenttoken is DivisionToken | currenttoken is ModuloToken) & TokenList[i + 1].GetResult().rawValue == 0) { return(false); } } } return(true); }
public void build(MathToken left, MathToken right = null) { this.left = left; this.right = right; }