public void TestSimpleParenthesisExpression() { LexicalScanner scanner = new LexicalScanner("(1*2)"); AbstractToken token = scanner.GetNextToken(); Assert.IsInstanceOf(typeof(OpenParenthesis), token); Assert.IsTrue(token.GetValue().Equals("(")); token = scanner.GetNextToken(); Assert.IsInstanceOf(typeof(Integer), token); Assert.IsTrue(token.GetValue().Equals("1")); token = scanner.GetNextToken(); Assert.IsInstanceOf(typeof(Operator), token); Assert.IsTrue(token.GetValue().Equals("*")); token = scanner.GetNextToken(); Assert.IsInstanceOf(typeof(Integer), token); Assert.IsTrue(token.GetValue().Equals("2")); token = scanner.GetNextToken(); Assert.IsInstanceOf(typeof(CloseParenthesis), token); Assert.IsTrue(token.GetValue().Equals(")")); }
public void TestFloat() { LexicalScanner scanner = new LexicalScanner("1.0"); AbstractToken token = scanner.GetNextToken(); Assert.IsInstanceOf(typeof(Float), token); Assert.IsTrue(token.GetValue().Equals("1.0")); }
public void TestInt() { LexicalScanner scanner = new LexicalScanner("1"); AbstractToken token = scanner.GetNextToken(); Assert.IsInstanceOf(typeof(Integer), token); Assert.IsTrue(token.GetValue().Equals("1")); }
public void TestSimpleAddSubExpression() { LexicalScanner scanner = new LexicalScanner("1+2"); AbstractToken token = scanner.GetNextToken(); Assert.IsInstanceOf(typeof(Integer), token); Assert.IsTrue(token.GetValue().Equals("1")); token = scanner.GetNextToken(); Assert.IsInstanceOf(typeof(AddSub), token); Assert.IsTrue(token.GetValue().Equals("+")); token = scanner.GetNextToken(); Assert.IsInstanceOf(typeof(Integer), token); Assert.IsTrue(token.GetValue().Equals("2")); }
public ParseNode Parse() { _current = _lex.GetNextToken(); try { Expressie(); } catch (MatchException me) { Console.WriteLine(me.Message); } return(_start); }
public void TestPolynomialsExpression() { LexicalScanner scanner = new LexicalScanner("(5-2)*3^6+1"); List <AbstractToken> tokens = new List <AbstractToken>(); while (!scanner.EndOfInput) { tokens.Add(scanner.GetNextToken()); } Assert.AreEqual(11, tokens.Count); }
public void TestPolynomialsExpression() { LexicalScanner scanner = new LexicalScanner("(5-2)*3^6+1"); List<AbstractToken> tokens = new List<AbstractToken>(); while (!scanner.EndOfInput) { tokens.Add(scanner.GetNextToken()); } Assert.AreEqual(11, tokens.Count); }