public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); instruction = (Instructions)Enum.Parse(typeof(Instructions), treeNode.ChildNodes[0].FindTokenAndGetText()); AddChild("firstOperand", treeNode.ChildNodes[1]); AddChild("secondOperand", treeNode.ChildNodes[2]); }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); AddChild("LValue", treeNode.ChildNodes[0].ChildNodes[0]); AddChild("RValue", treeNode.ChildNodes[2]); @operator = treeNode.ChildNodes[1].FindTokenAndGetText(); ResultType = "word"; if (opcodes == null) { opcodes = new Dictionary<string, Instructions>(); opcodes.Add("=", Instructions.SET); opcodes.Add("+=", Instructions.ADD); opcodes.Add("-=", Instructions.SUB); opcodes.Add("*=", Instructions.MUL); opcodes.Add("/=", Instructions.DIV); opcodes.Add("-*=", Instructions.MLI); opcodes.Add("-/=", Instructions.DVI); opcodes.Add("%=", Instructions.MOD); opcodes.Add("-%=", Instructions.MDI); opcodes.Add("<<=", Instructions.SHL); opcodes.Add(">>=", Instructions.SHR); opcodes.Add("&=", Instructions.AND); opcodes.Add("|=", Instructions.BOR); opcodes.Add("^=", Instructions.XOR); } }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); if (treeNode.ChildNodes.Count == 1) { Value = new IntegerAstNode() { Value = 1 }; PeriodicType = PeriodicTypeAst.Day; } else { Value = AddChild("value", treeNode.FirstChild) as ExpressionAstNode; string periodType = treeNode.ChildNodes[1].FindTokenAndGetText().ToLower(); switch (periodType) { case "month": case "months": PeriodicType = PeriodicTypeAst.Month; break; case "days": case "day": PeriodicType = PeriodicTypeAst.Day; break; default: throw new ArgumentException("Unregconized period type:" + periodType); } } }
protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread) { object retval = null; thread.CurrentNode = this; //standard prolog if (Left != null) { if (_TheFunction != null) { _TheFunction.Left = Left; retval = _TheFunction.Evaluate(thread); } else if (_PropNode != null) { _PropNode.Left = Left; retval = _PropNode.Evaluate(thread); } } if (_queue != null) { _queue.Left = retval; retval = _queue.Evaluate(thread); } thread.CurrentNode = Parent; //standard epilog return retval; }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); _globalParamDef = new List<GlobalIdentifierAstNode>(); foreach (var node in treeNode.ChildNodes[0].ChildNodes) { _globalParamDef.Add((GlobalIdentifierAstNode)node.AstNode ); } PositionSets = new List<DefinePositionSetAstNode>(); StrategyParameters = new List<StrategyParameterAstNode>(); Irony.Ast.AstNode targetAstNode; foreach (var node in treeNode.ChildNodes[1].ChildNodes) { targetAstNode = node.FirstChild.AstNode as Irony.Ast.AstNode; if (targetAstNode is DefinePositionSetAstNode) PositionSets.Add(targetAstNode as DefinePositionSetAstNode); else if (targetAstNode is StrategyParameterAstNode) StrategyParameters.Add(targetAstNode as StrategyParameterAstNode); } TradingRules = new List<GeneralRuleAstNode>(); foreach (var node in treeNode.ChildNodes[2].ChildNodes) { TradingRules.Add(node.AstNode as GeneralRuleAstNode); } }
public override void Evaluate(Irony.Interpreter.EvaluationContext context, AstMode mode) { _x.Evaluate (context, AstMode.Read); _y.Evaluate (context, AstMode.Read); _z.Evaluate (context, AstMode.Read); _dx.Evaluate (context, AstMode.Read); _dy.Evaluate (context, AstMode.Read); _dz.Evaluate (context, AstMode.Read); _ux.Evaluate (context, AstMode.Read); _uy.Evaluate (context, AstMode.Read); _uz.Evaluate (context, AstMode.Read); double x = Convert.ToDouble (context.Data[8]); double y = Convert.ToDouble (context.Data[7]); double z = Convert.ToDouble (context.Data[6]); double ux = Convert.ToDouble (context.Data[2]); double uy = Convert.ToDouble (context.Data[1]); double uz = Convert.ToDouble (context.Data[0]); double dx = Convert.ToDouble (context.Data[5]); double dy = Convert.ToDouble (context.Data[4]); double dz = Convert.ToDouble (context.Data[3]); Api.LookAt (x, y, z, ux, uy, uz, dx, dy, dz); }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); AddChild("instruction", treeNode.ChildNodes[0]); AddChild("firstOperand", treeNode.ChildNodes[1]); AddChild("secondOperand", treeNode.ChildNodes[2]); }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init (context, treeNode); _paramName = AddChild ("name", treeNode.ChildNodes[0]); _array = AddChild ("array", treeNode.ChildNodes[1]); }
public override bool convert( Irony.Parsing.ParseTreeNode node, Compiler c ) { base.convert( node, c ); if( node.Term.Name == "DictExpr" ) { var elems = node.ChildNodes[1]; if( elems.Term.Name != "DictElements" ) throw new CompilationException( "Expected DictElements", node ); foreach( var child in elems.ChildNodes ) { if( child.Term.Name != "DictElement" ) throw new CompilationException( "Expected DictElement", child ); Pair p = new Pair() { key = c.convertNode( child.ChildNodes[0] ), value = c.convertNode( child.ChildNodes[1] ) }; this.pairs.Add( p ); } return true; } return false; }
protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread) { // List<object> retval = new List<object>(); object retval = null; thread.CurrentNode = this; //standard prolog string propertyName = property.ChildNodes[0].FindTokenAndGetText(); if (Left is IEnumerable<object>) { IEnumerable<object> o = Left as IEnumerable<object>; foreach (var origItem in o) { IPersistIfcEntity entity = origItem as IPersistIfcEntity; retval = entity.GetPropertyByName(propertyName); } } else if (Left is IPersistIfcEntity) { IPersistIfcEntity entity = Left as IPersistIfcEntity; retval = entity.GetPropertyByName(propertyName); } thread.CurrentNode = Parent; //standard epilog return retval; }
public override void Evaluate(Irony.Interpreter.EvaluationContext context, AstMode mode) { _paramName.Evaluate (context, AstMode.Read); _array.Evaluate (context, AstMode.Read); _name = (_paramName as Irony.Ast.LiteralValueNode).Value as string; }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); if (treeNode.ChildNodes[1].FirstChild.ChildNodes.Count > 0) AddChild("value", treeNode.ChildNodes[1].FirstChild.FirstChild); this.AsString = treeNode.FindTokenAndGetText(); }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); AddChild("Expression", treeNode.ChildNodes[1].FirstChild); AddChild("Block", treeNode.ChildNodes[2]); this.AsString = "While"; }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); _exchangeRateAccessor = AddChild("exchangeRateAccessor", treeNode.ChildNodes[0]) as ExchangeRateAccessorAstNode; _dateExpr = AddChild("dateExpr", treeNode.ChildNodes[1]) as ExpressionAstNode; }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); _positionSetAstNode = (PositionSetAstNode)AddChild("PositionSetAstNode", treeNode.ChildNodes[0]); _expressionAstNode = (ExpressionAstNode)AddChild("ExpressionAstNode", treeNode.ChildNodes[1]); }
protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread) { thread.CurrentNode = this; try { var res = new MtResult(); var accessor = thread.Bind(_targetName.AsString, BindingRequestFlags.Write | BindingRequestFlags.ExistingOrNew); accessor.SetValueRef(thread, res); // To allow recursive definitions, we have // to evaluate _expression inside the new context. var exprResult = _expression.Evaluate(thread) as MtResult; exprResult.GetValue((o) => { res.SetValue((state) => { return o; }); }); return res; } catch (Exception e) { throw new Exception("Exception on MtBind.DoEvaluate", e); } finally { //thread.CurrentNode = Parent; } }
public override void Init(Irony.Ast.AstContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); var nodes = treeNode.ChildNodes; if (nodes.Count != 3) { throw new Exception("If node extended 3 children, received {0}".SafeFormat(nodes.Count)); } _expression = AddChild(string.Empty, nodes[0]) as AstNode; if (_expression == null) { throw new Exception("No expression for if!"); } _trueBranch = AddChild(string.Empty, nodes[1]) as AstNode; if (_expression == null) { throw new Exception("No true branch for if!"); } _falseBranch = AddChild(string.Empty, nodes[2]) as AstNode; if (_expression == null) { throw new Exception("No false branch for if!"); } }
public override void Init(Irony.Ast.AstContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); _target = AddChild(string.Empty, treeNode.ChildNodes[0]) as AstNode; _source = AddChild(string.Empty, treeNode.ChildNodes[1]) as AstNode; }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); AsString = treeNode.ChildNodes[0].FindTokenAndGetText(); foreach (var parameter in treeNode.ChildNodes[1].ChildNodes) AddChild("parameter", parameter); }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init (context, treeNode); for (int i = 0; i < 16; ++i) _numberNodes[i] = AddChild ("p" + i, treeNode.ChildNodes[1 + i]); }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); Name = treeNode.ChildNodes[0].FindTokenAndGetText(); Statements = treeNode.ChildNodes[2].ChildNodes.Select(c => c.AstNode as Statement); ExecuteFrequency = treeNode.ChildNodes[1].AstNode as TimeIntervalDefinition; }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); AsString = ""; foreach (var child in treeNode.ChildNodes) AsString += child.FindTokenAndGetText(); }
protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread) { object retval = null; thread.CurrentNode = this; //standard prolog thread.CurrentNode = Parent; //standard epilog return retval; }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); foreach (var child in treeNode.ChildNodes[1].ChildNodes) { var token = child.FindTokenAndGetText(); if (child.Term.Name == "BlockLiteral" || (child.ChildNodes.Count > 0 && child.FirstChild.Term.Name == "BlockLiteral")) { int d = 0; if (token.StartsWith("0x")) d = atoh(token.Substring(2)); else d = Convert.ToUInt16(token); for (int i = 0; i < d; ++i) data.Add(0); } else if (token[0] == '\"') foreach (var c in token.Substring(1, token.Length - 2)) data.Add((ushort)c); else if (token[0] == '\'') data.Add((ushort)token[1]); else if (token.StartsWith("0x")) data.Add(atoh(token.Substring(2))); else data.Add(Convert.ToUInt16(token)); } dataLabel = Scope.GetLabel() + "_DATA"; }
public static SourceSpan FromIrony(Irony.Parsing.SourceSpan span, string source) { return new SourceSpan( FromIrony(span.Location, source), new SourceLocation(span.Location.Line, span.Location.Column + span.Length, span.EndPosition, source) ); }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init (context, treeNode); _pluginName = AddChild ("plugin", treeNode.ChildNodes[1]); _parameters = AddChild ("parameters", treeNode.ChildNodes[2]); }
public override void Init(Irony.Parsing.GrammarData grammarData) { base.Init(grammarData); //Check that Parser-scanner link is enabled - this terminal can be used only if this link is enabled if (Grammar.LanguageFlags.IsSet(LanguageFlags.DisableScannerParserLink)) grammarData.Language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrImpliedOpUseParserLink, this.Name); //"ImpliedSymbolTerminal cannot be used in grammar with DisableScannerParserLink flag set" }
protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread) { List<IPersistIfcEntity> returnVal = new List<IPersistIfcEntity>(); thread.CurrentNode = this; //standard prolog XbimModel m = thread.App.Globals["model"] as XbimModel; if (m != null) { // todo: is there a way to make this lazy with yield? foreach (var child in ElementList.ChildNodes) { string tk = child.FindTokenAndGetText(); int iEl = -1; if (Int32.TryParse(tk, out iEl)) { returnVal.Add(m.Instances[iEl]); } else if (tk == @"*") { returnVal.AddRange(m.Instances); } else { returnVal.AddRange(m.Instances.OfType(tk, false)); } } } thread.CurrentNode = Parent; //standard epilog return returnVal; }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); AddChild("Block", treeNode.ChildNodes[3]); localScope = new Scope(); var parameters = treeNode.ChildNodes[2].ChildNodes; for (int i = 0; i < parameters.Count; ++i) { var variable = new Variable(); variable.scope = localScope; variable.name = parameters[i].ChildNodes[0].FindTokenAndGetText(); localScope.variables.Add(variable); if (i < 3) { variable.location = (Register)i; localScope.UseRegister(i); } else { variable.location = Register.STACK; variable.stackOffset = localScope.stackDepth; localScope.stackDepth += 1; } parameterCount += 1; } this.AsString = treeNode.ChildNodes[1].FindTokenAndGetText(); label = Scope.GetLabel() + "_" + AsString; localScope.activeFunction = this; }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); var literal = treeNode.MappedChildNodes[0]; Member = literal.Token.ValueString; AsString = literal.Token.ValueString + " (identifier)"; }