public override void ProcessNode(BoolValueNode node) { }
private bool TryValue(ParserContext context, out IAstNode instr) { instr = null; if (context.Stream.Consume(TokenTypes.Identity, out var value)) { if (context.Stream.Consume(TokenTypes.LeftParentheses)) { // We have parentheses = must be a function if (!context.Stream.Consume <List <IAstNode> >(TryParameters, context, out var parameters)) { throw new ParserException("Syntax error", context.Stream); } if (!context.Stream.Consume(TokenTypes.RightParentheses)) { throw new ParserException("Syntax error, expected )", context.Stream); } var functionName = value.ToString(); // Validate that the function exists var matchingFunctions = context.ValidFunctions.Where(i => i.Name.Equals(functionName, StringComparison.InvariantCultureIgnoreCase)).ToList(); if (!matchingFunctions.Any()) { throw new ParserException($"Unknown function: {functionName}", context.Stream); } // Validate that we have a function that has the same number of parameters // as was entered in the script if (matchingFunctions.All(i => i.Parameters.Count != parameters.Count)) { var errMsg = new StringBuilder(); errMsg.AppendLine("Invalid number of parameters"); errMsg.AppendLine("Supported: "); foreach (var func in matchingFunctions) { errMsg.AppendLine( $" * {func.Name}({string.Join(",", func.Parameters.Select(i => i.Name))})"); } throw new ParserException(errMsg.ToString(), context.Stream); } instr = new FunctionNode(functionName, parameters); return(true); } // Missing parentheses = must be a bound variable. instr = new VariableNode(value?.ToString()); return(true); } if (context.Stream.Consume(TokenTypes.String, out value)) { if (value == null) { instr = new ValueNode(null); } else { instr = new ValueNode(Regex.Unescape(value.ToString())); } return(true); } if (context.Stream.Consume(TokenTypes.Integer, out value) || context.Stream.Consume(TokenTypes.Decimal, out value) || context.Stream.Consume(TokenTypes.Char, out value)) { instr = new ValueNode(value); return(true); } if (context.Stream.Consume(TokenTypes.LeftParentheses)) { if (!context.Stream.Consume <IAstNode>(TryStatement, context, out instr)) { throw new ParserException("Syntax error", context.Stream); } if (!context.Stream.Consume(TokenTypes.RightParentheses)) { throw new ParserException("Syntax error, expected )", context.Stream); } return(true); } if (context.Stream.Consume(TokenTypes.Plus)) { if (!context.Stream.Consume <IAstNode>(TryFactor, context, out instr)) { throw new ParserException("Syntax error", context.Stream); } return(true); } if (context.Stream.Consume(TokenTypes.Minus)) { if (!context.Stream.Consume <IAstNode>(TryFactor, context, out var factor)) { throw new ParserException("Syntax error", context.Stream); } instr = new MultiplyNode(new ValueNode(-1), factor); return(true); } if (context.Stream.Consume(TokenTypes.Null)) { instr = new ValueNode(null); return(true); } if (context.Stream.Consume(TokenTypes.True)) { instr = new BoolValueNode(true); return(true); } if (context.Stream.Consume(TokenTypes.False)) { instr = new BoolValueNode(false); return(true); } return(false); }
public override void ProcessNode(BslFunctionCallNode node) { ExpressionReference expressionReference = m_decompilerLookup.FunctionOpCodeLookup[node.OperationCode]; FunctionReference functionReference; OperatorReference operatorReference; GlobalReference globalReference; if ((functionReference = expressionReference as FunctionReference) != null) { if (functionReference.Function.IsOverloadedByBooleanArgument) { node.Children.Add(new BoolValueNode(functionReference.Overload == 1)); } node.Replace(new PslFunctionUsageNode(functionReference.Function, node.Children)); foreach (NodeBase child in node.Children) { child.VisitThis(this); } } else if ((operatorReference = expressionReference as OperatorReference) != null) { switch (operatorReference.Operation.Specification) { case FunctionSpecification.Begin: node.Replace(new GroupingNode(node.Children)); foreach (NodeBase child in node.Children) { child.VisitThis(this); } break; case FunctionSpecification.BeginRandom: ValueDiscrepancy vd = SingleValueDiscrepancySearch.Perform(node.Children); if (vd != null) { short typeIndex = vd.TypeIndex; string pluralTypeName = m_engineDefinition.GetTypeName(typeIndex); List <NodeBase> randomizerExpressions = node.Children[0].Children; VariableNode iteratorParameter = new VariableNode(pluralTypeName + "s", typeIndex, true, true, null); vd.Nodes[0].Replace(new VariableReferenceValueNode(iteratorParameter, typeIndex)); List <NodeBase> parameters = new List <NodeBase>(); parameters.Add(iteratorParameter); ScriptNode randomFunction = new ScriptNode("Randomize" + StringOps.CapitalizeWords(pluralTypeName), ScriptType.Random, (short)IntegralValueType.Void, randomizerExpressions); m_scriptInsertionQueue.QueueInsertion(m_state.CurrentScriptIndex, randomFunction); List <NodeBase> randomFunctionArguments = new List <NodeBase>(); randomFunctionArguments.Add(new PslArrayNode(typeIndex, vd.Nodes)); node.Replace(new ScriptCallNode(randomFunction, randomFunctionArguments)); foreach (NodeBase child in node.Children) { child.VisitThis(this); } } break; case FunctionSpecification.If: // Early recursion to identify GroupingNodes and sub Ifs before constructing conditional node foreach (NodeBase child in node.Children) { child.VisitThis(this); } ConditionalConstructNode conditionalConstruct = null; NodeBase condition = node.Children[0]; GroupingNode expressions = GroupingNode.MakeGrouping(node.Children[1]); GroupingNode elseExpressions = null; if (node.Children.Count > 2) { elseExpressions = GroupingNode.MakeGrouping(node.Children[2]); ConditionalConstructNode embeddedIf; if (elseExpressions.Children.Count == 1 && (embeddedIf = elseExpressions.Children[0] as ConditionalConstructNode) != null) { BoolValueNode potentialAlwaysTrueStatement = embeddedIf.Conditions[0] as BoolValueNode; if (potentialAlwaysTrueStatement != null && potentialAlwaysTrueStatement.Value) { elseExpressions = embeddedIf.ExpressionSets[0] as GroupingNode; } else { conditionalConstruct = embeddedIf; conditionalConstruct.InsertConditional(condition, expressions); } } } if (conditionalConstruct == null) { List <NodeBase> conditions = new List <NodeBase>(); conditions.Add(condition); List <NodeBase> expressionSets = new List <NodeBase>(); expressionSets.Add(expressions); conditionalConstruct = new ConditionalConstructNode(conditions, expressionSets, elseExpressions); } node.Replace(conditionalConstruct); break; case FunctionSpecification.Cond: throw new NeedMoreResearchException("How does cond look in compiled form - how are its children mapped out?"); //node.Replace(new ConditionalConstructNode()); //break; default: List <NodeBase> children = node.Children; node.Replace(new PslOperatorUsageNode(operatorReference.Operation, children)); foreach (NodeBase child in children) { child.VisitThis(this); } break; } } else if ((globalReference = expressionReference as GlobalReference) != null) { switch (globalReference.Method) { case GlobalReference.AccessMethod.Get: node.Replace(new PslGameGlobalReferenceNode(globalReference.Global)); break; case GlobalReference.AccessMethod.Set: List <NodeBase> operands = new List <NodeBase>(); operands.Add(new PslGameGlobalReferenceNode(globalReference.Global)); operands.Add(node.Children[0]); node.Replace(new PslOperatorUsageNode(m_engineDefinition.SpecificFunctions[(int)FunctionSpecification.Set], operands)); operands[1].VisitThis(this); break; } } else if (expressionReference is CasterReference) { node.Replace(node.Children[0]); node.Children[0].VisitThis(this); } }
public override void Visit(BoolValueNode node) { CSharpString.Append(node.BoolValue.ToString().ToLower()); }
public override void Visit(BoolValueNode node) { node.Type = "bool"; }
public override void ProcessNode(BoolValueNode node) { m_output.Append(node.Value.ToString().ToLower()); }
public override void Visit(BoolValueNode node) { Console.Write(node.BoolValue.ToString().ToLower()); }
internal abstract void Visit(BoolValueNode node);
public abstract void ProcessNode(BoolValueNode node);
public object Visit(BoolValueNode node) { return(node.Value); }
public abstract void Visit(BoolValueNode node);
public RuntimeBoolValueNode(BoolValueNode valueNode, RuntimeScope scope) : base(valueNode, BoolValueNode.Type, scope) { }