public void GetArithmeticOperators() { Lexer lexer = new Lexer("+-*/"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Operator, token.Type); Assert.AreEqual("+", token.Value); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Operator, token.Type); Assert.AreEqual("-", token.Value); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Operator, token.Type); Assert.AreEqual("*", token.Value); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Operator, token.Type); Assert.AreEqual("/", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetAtom() { Lexer lexer = new Lexer("ok"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Atom, token.Type); Assert.AreEqual("ok", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetAtomAndSkipComment() { Lexer lexer = new Lexer("ok % this is a comment"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Atom, token.Type); Assert.AreEqual("ok", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetAtomWithAt() { Lexer lexer = new Lexer("joe@somehost"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Atom, token.Type); Assert.AreEqual("joe@somehost", token.Value); Assert.IsNull(lexer.NextToken()); }
public static void Main(string[] args) { Console.WriteLine("AjErl alfa 0.0.1"); Lexer lexer = new Lexer(Console.In); Parser parser = new Parser(lexer); Machine machine = new Machine(); while (true) try { ProcessExpression(parser, machine.RootContext); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); Console.Error.WriteLine(ex.StackTrace); } }
public void GetIntegerWithSpaces() { Lexer lexer = new Lexer(" 123 "); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Integer, token.Type); Assert.AreEqual("123", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetStrictEqualAsOperator() { Lexer lexer = new Lexer("=:="); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Operator, token.Type); Assert.AreEqual("=:=", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetNumeralBracketAsSeparator() { Lexer lexer = new Lexer("#{"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Separator, token.Type); Assert.AreEqual("#{", token.Value); Assert.IsNull(lexer.NextToken()); }
public void UnexpectedSign() { Lexer lexer = new Lexer("?"); try { lexer.NextToken(); Assert.Fail(); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ParserException)); Assert.AreEqual("Unexpected '?'", ex.Message); } }
public void GetVerticalBarAsSeparator() { Lexer lexer = new Lexer("|"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Separator, token.Type); Assert.AreEqual("|", token.Value); Assert.IsNull(lexer.NextToken()); }
public void UnclosedString() { Lexer lexer = new Lexer("\"foo"); try { lexer.NextToken(); Assert.Fail(); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ParserException)); Assert.AreEqual("unclosed string", ex.Message); } }
public void GetUnderscoreNameAsVariable() { Lexer lexer = new Lexer("_ok"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Variable, token.Type); Assert.AreEqual("_ok", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetVariable() { Lexer lexer = new Lexer("X"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Variable, token.Type); Assert.AreEqual("X", token.Value); Assert.IsNull(lexer.NextToken()); }
public Parser(Lexer lexer) { this.lexer = lexer; }
public void GetParenthesisAsSeparators() { Lexer lexer = new Lexer("()"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Separator, token.Type); Assert.AreEqual("(", token.Value); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Separator, token.Type); Assert.AreEqual(")", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetSimpleMatch() { Lexer lexer = new Lexer("X=ok."); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Variable, token.Type); Assert.AreEqual("X", token.Value); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Operator, token.Type); Assert.AreEqual("=", token.Value); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Atom, token.Type); Assert.AreEqual("ok", token.Value); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Separator, token.Type); Assert.AreEqual(".", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetSemiColonAsSeparator() { Lexer lexer = new Lexer(";"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Separator, token.Type); Assert.AreEqual(";", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetRightArrowAsOperator() { Lexer lexer = new Lexer("->"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Operator, token.Type); Assert.AreEqual("->", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetReal() { Lexer lexer = new Lexer("123.45"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Real, token.Type); Assert.AreEqual("123.45", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetPointAsOperator() { Lexer lexer = new Lexer("."); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Separator, token.Type); Assert.AreEqual(".", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetString() { Lexer lexer = new Lexer("\"foo\""); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.String, token.Type); Assert.AreEqual("foo", token.Value); Assert.IsNull(lexer.NextToken()); }
public void GetBracketsAsSeparators() { Lexer lexer = new Lexer("[]"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Separator, token.Type); Assert.AreEqual("[", token.Value); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(TokenType.Separator, token.Type); Assert.AreEqual("]", token.Value); Assert.IsNull(lexer.NextToken()); }