public LispOperator <TBb> Compile(TBb blackboard, string code) { LispParser lispParser = new LispParser(); LispParser.Node parseTree = lispParser.Parse(code); return(Compile(blackboard, parseTree)); }
public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.MethodNode methodNode = node as LispParser.MethodNode; if (methodNode == null || methodNode.Identifier.Value != Name) { return(null); } LispMethod <TBb> method = CreateMethod(blackboard, methodNode, compiler); if (method != null) { if (method.GetType() != GetType()) { throw new InvalidOperationException( string.Format( "Expected {0} but compiled to {1}!", TypeHelper.GetFriendlyTypeName(GetType()), TypeHelper.GetFriendlyTypeName(method.GetType()))); } foreach (LispParser.Node child in methodNode.Children) { method.Children.Add((LispOperator <TBb>)compiler.Compile(blackboard, child)); } } return(method); }
public LispOperator <TBb> Compile(TBb blackboard, LispParser.Node parseTree) { foreach (LispOperator <TBb> lispOperator in Operators) { LispOperator <TBb> result = lispOperator.CreateOperator(blackboard, parseTree, this); if (result != null) { return(result); } } throw new InvalidOperationException( string.Format("Unrecognized token: {0}.", parseTree)); }
public override LispOperator <TBb> CreateOperator( TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.IdentifierNode identifierNode = node as LispParser.IdentifierNode; if (identifierNode == null) { return(null); } Func <bool> func = blackboard.GetBoolFunction(identifierNode.Value); if (func == null) { return(null); } return(new BlackboardBoolFunction <TBb>(identifierNode.Value, func)); }
LispParser.ICanCreateFromLispParseTree <TBb> LispParser.ICompiler <TBb> .Compile(TBb blackboard, LispParser.Node parseTree) { return(Compile(blackboard, parseTree)); }
LispParser.ICanCreateFromLispParseTree <TBb> LispParser.ICanCreateFromLispParseTree <TBb> .CreateFromParseTree(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { return(CreateOperator(blackboard, node, compiler)); }
public abstract LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler);
public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.StringNode stringNode = node as LispParser.StringNode; return(stringNode != null ? new StringConstant <TBb>(stringNode.Value) : null); }
public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.IdentifierNode identifierNode = node as LispParser.IdentifierNode; return(identifierNode != null && identifierNode.Value == "False" ? new FalseConstant <TBb>() : null); }
public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.IntegerNode integerNode = node as LispParser.IntegerNode; return(integerNode != null ? new IntConstant <TBb>(integerNode.Value) : null); }