public void StatementBlockPosition() { Enviroment enviroment = new Enviroment(provider); var block = TokenParser.Parse("int 0f .", enviroment, CodePosition.GetExternal()); Assert.AreEqual(block.position, CodePosition.GetExternal()); }
static void Run(string code) { List <CodeTokenizer.Token> tokens = null; StatementBlock block = null; try { tokens = CodeTokenizer.Tokenize(code, file); var tokensEnum = (IEnumerator <CodeTokenizer.Token>)tokens.GetEnumerator(); block = TokenParser.Parse(ref tokensEnum, enviroment, CodePosition.GetExternal()); } catch (WordScriptException ex) { Console.WriteLine(ex.Message); } if (tokens != null) { foreach (var token in tokens) { Console.WriteLine(token.ToString()); } } Console.WriteLine(""); if (block != null) { foreach (var node in block.GetSyntaxNodes()) { Console.WriteLine(node.Debug()); } var ret = block.Evaluate(); Console.WriteLine(ret?.ToString() ?? "null"); } }
public void ReturningFromBlock() { Enviroment enviroment = new Enviroment(provider); var block = TokenParser.Parse("return 10 .", enviroment, CodePosition.GetExternal()); block.Validate(enviroment); Assert.AreEqual(block.ReturnType, typeof(int)); }
public void VariableTypeSafetyInCode() { Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal()); enviroment.StartBlock(CodePosition.GetExternal()); enviroment.DefineVariable("x", typeof(string), CodePosition.GetExternal()); TokenParser.Parse("x= 0 .", enviroment, CodePosition.GetExternal()); enviroment.EndBlock(); }
public void VariableRedefinitionFail() { Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal()); enviroment.StartBlock(CodePosition.GetExternal()); enviroment.DefineVariable("x", typeof(int), CodePosition.GetExternal()); enviroment.DefineVariable("x", typeof(int), CodePosition.GetExternal()); enviroment.EndBlock(); }
public void TypeAttribute() { Enviroment enviroment = new Enviroment(provider); Assert.IsNotNull(TokenParser.Parse("TestMapClass .", enviroment, CodePosition.GetExternal()).Evaluate() as TestMapClass); Assert.AreEqual(5, TokenParser.Parse("TestMapClass , .i .", enviroment, CodePosition.GetExternal()).Evaluate()); Assert.AreEqual(20, TokenParser.Parse("TestMapClass 20 , .i .", enviroment, CodePosition.GetExternal()).Evaluate()); Assert.AreEqual(20, TokenParser.Parse("TestMapClass 20 , .GetI .", enviroment, CodePosition.GetExternal()).Evaluate()); }
public void RunTheExampleFile() { var text = System.IO.File.ReadAllText("../../../Examples/example.ws"); Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal()); var block = TokenParser.Parse(text, enviroment, CodePosition.GetExternal()); block.Validate(enviroment); Assert.AreEqual(typeof(string), block.ReturnType); Assert.AreEqual("aaaab", block.Evaluate()); }
public void VariableDefinition() { Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal()); enviroment.StartBlock(CodePosition.GetExternal()); Assert.IsNull(enviroment.GetVariable("y")); enviroment.DefineVariable("x", typeof(int), CodePosition.GetExternal()); Assert.IsNotNull(enviroment.GetVariable("x")); enviroment.EndBlock(); }
public void VariablesInCode() { Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal()); enviroment.StartBlock(CodePosition.GetExternal()); enviroment.DefineVariable("x", typeof(int), CodePosition.GetExternal()); TokenParser.Parse("DEFINE:y:int . &y . y= 0 . &x . x= &y .", enviroment, CodePosition.GetExternal(), true); Assert.IsNotNull(enviroment.GetVariable("y")); Assert.AreEqual(enviroment.GetVariable("y").Type, typeof(int)); enviroment.EndBlock(); }
public void VariableInheritance() { Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal()); enviroment.StartBlock(CodePosition.GetExternal()); var xOut = enviroment.DefineVariable("x", typeof(string), CodePosition.GetExternal()); var yOut = enviroment.DefineVariable("y", typeof(int), CodePosition.GetExternal()); enviroment.StartBlock(CodePosition.GetExternal()); Assert.AreEqual(yOut, enviroment.GetVariable("y")); Assert.AreEqual(xOut, enviroment.GetVariable("x")); var yInner = enviroment.DefineVariable("y", typeof(string), CodePosition.GetExternal()); var zInner = enviroment.DefineVariable("z", typeof(string), CodePosition.GetExternal()); Assert.AreNotEqual(yOut, enviroment.GetVariable("y")); enviroment.EndBlock(); Assert.AreEqual(yOut, enviroment.GetVariable("y")); Assert.IsNull(enviroment.GetVariable("z")); enviroment.EndBlock(); }
public void CodeExecutionReturn() { Enviroment enviroment = new Enviroment(provider); Assert.AreEqual(TokenParser.Parse("add 10 15 , return .", enviroment, CodePosition.GetExternal()).Evaluate(), 25); }
public void Parsing() { Enviroment enviroment = new Enviroment(TypeInfoProvider.GetGlobal()); var block = TokenParser.Parse("\"Comment\" .\nprint IN string 25 . .\nprint IN add \"Hello\" \"world\" . .\n mul 5 10 , string , add \" = 25\" , print .", enviroment, CodePosition.GetExternal()); var statements = block.GetSyntaxNodes(); Assert.AreEqual(statements.Count, 4); }