public static IExpression BuildBinaryExpression(List <Token> tokens, ref int index, IExpression leftExpr, Stack <int?> precedenceStack) { IBinaryExpressionCreator bxc = binaryExpressionCreators[tokens[index++].Value]; IBinaryExpression bx = bxc.Create(); bx.Left = leftExpr; precedenceStack.Push(bx.Precedence); bx.BuildExpression(tokens, ref index, precedenceStack); precedenceStack.Pop(); return(bx); }
public static IExpression BuildBinaryExpression(TokenList tokens, IExpression leftExpr, Stack <int?> precedenceStack) { IBinaryExpressionCreator bxc = binaryExpressionCreators[tokens.Current.Value]; IBinaryExpression bx = bxc.Create(); bx.Left = leftExpr; precedenceStack.Push(bx.Precedence); bx.PrepareExpression(tokens, precedenceStack); precedenceStack.Pop(); return(bx); }
static TokenParser() { instructionCreators = new Dictionary <string, IInstructionCreator>(); binaryExpressionCreators = new Dictionary <string, IBinaryExpressionCreator>(); expressionCreators = new Dictionary <string, IExpressionCreator>(); foreach (Type t in Core.Modules.GetInterfaceImplementations(typeof(IInstructionCreator))) { IInstructionCreator ic = (IInstructionCreator)Activator.CreateInstance(t); instructionCreators.Add(ic.Keyword.ToLower(), ic); } foreach (Type t in Core.Modules.GetInterfaceImplementations(typeof(IBinaryExpressionCreator))) { IBinaryExpressionCreator bxc = (IBinaryExpressionCreator)Activator.CreateInstance(t); binaryExpressionCreators.Add(bxc.Keyword.ToLower(), bxc); } foreach (Type t in Core.Modules.GetInterfaceImplementations(typeof(IExpressionCreator))) { IExpressionCreator xc = (IExpressionCreator)Activator.CreateInstance(t); expressionCreators.Add(xc.Keyword.ToLower(), xc); } }