void LayoutChildForPosition(CoverflowItem item, int size, double position) { var rotation = -Math.Atan(position * 2) / (Math.PI / 2); Point center = new Point(Width / 2, Height / 2); center.X += size * (1.3 - Math.Abs(rotation * rotation)) * position; item.SetSize(size, size); item.X = center.X - size / 2; item.Y = center.Y - size / 2; item.RotationY = (rotation * 75).Clamp(-72, 72); item.X = item.X.Clamp(-size - 10, Width + 10); item.QueueDraw(); LabelNode label = null; if (position <= 0 && position > -1) { label = leftLabel; } else if (position > 0 && position < 1) { label = rightLabel; } if (label != null) { label.Opacity = Math.Max(0, 1 - Math.Abs(position)); label.Text = item.Name; label.X = center.X - label.Width / 2; label.Y = center.Y + size * 0.6; label.SetSize(label.PreferedWidth, label.PreferedHeight); } }
public LabelNodeRenderer(LabelNode node) : base(node) { this.node = node; label = new UILabel (); AddSubview (label); }
/// <summary> /// Returns the clone of the given original label that is appropriate for use in a jump /// instruction. /// </summary> /// <param name="labelNode">a label of the original code.</param> /// <returns> /// a clone of the given label for use in a jump instruction in the inlined code. /// </returns> internal virtual LabelNode GetClonedLabelForJumpInsn(LabelNode labelNode) { // findOwner should never return null, because owner is null only if an instruction cannot be // reached from this subroutine. return(FindOwner(_enclosing.instructions.IndexOf(labelNode)).clonedLabels .GetOrNull(labelNode)); }
public override void LayoutOutline(Node node, Context context) { LabelNode label = node as LabelNode; Cairo.Engine engine = node.Canvas.Engine as Cairo.Engine; if (label.ClipInputToTextExtents) { var options = new TextOptions(); options.Color = label.Color.MultiplyAlpha(node.Opacity); options.MaxWidth = label.Width; var size = GetExtents(label.Text, options, engine); double x = label.Width - size.Width; x = (int)(x * label.XAlign); double y = label.Height - size.Height; y = (int)(y * label.YAlign); context.Rectangle(x, y, size.Width, size.Height); } else { context.Rectangle(0, 0, label.Width, label.Height); } }
public LabelNodeRenderer(LabelNode node) : base(node) { this.node = node; label = new UILabel(); AddSubview(label); }
public override void VisitLabelNode(LabelNode l) { TACodeContainer.PushNode(new TacEmptyNode() { Label = "L" + l.Inum }); }
private void OnDisplayUsageCheckedChanged(object sender, EventArgs e) { using (new WaitCursor(this)) { domainTree.BeginUpdate(); domainList.BeginUpdate(); var stack = new Stack <LabelNode>(domainTree.Nodes.Cast <LabelNode>()); while (stack.Count > 0) { LabelNode node = stack.Pop(); node.DisplayUsage = displayUsageCheckBox.Checked; foreach (TreeNode childNode in node.Nodes) { var labelNode = childNode as LabelNode; if (labelNode != null) { stack.Push(labelNode); } } } foreach (ListViewItem item in domainList.Items) { item.Text = SemanticDomainSelectionUtility.CreateLabelListItem(item.Tag as ICmObject, item.Checked, displayUsageCheckBox.Checked).Text; } domainTree.EndUpdate(); domainList.EndUpdate(); } }
private Linkbase CreateLabelLinkbase(Taxonomy taxonomy, DiscoverableTaxonomySet dts) { var linkbase = new Linkbase(GetLinkbaseFileName(taxonomy, "lab")); var labelLink = new LabelLink(LinkbaseXNames.Label, LinkRoles.Generic); linkbase.AddLink(labelLink, dts); var locCount = 0; var labCount = 0; foreach (var extensionItem in ExtensionItems) { var locLabel = $"loc{locCount}"; locCount += 1; var locNode = CreateLocatorNode(locLabel, extensionItem, dts); labelLink.AddNode(locNode); foreach (var extensionLabel in extensionItem.Labels) { var labLabel = $"lab{labCount}"; labCount += 1; var labNode = new LabelNode(labLabel, extensionLabel.Role, extensionLabel.Text, extensionLabel.Language); labelLink.AddNode(labNode); var arc = new LabelArc(locNode, labNode); labelLink.AddArc(arc); } } return(linkbase); }
/// <summary> /// Constructs a new /// <see cref="Subroutine" /> /// . /// </summary> /// <param name="start">the start of this subroutine.</param> /// <param name="maxLocals"> /// the local variables that are read or written by this subroutine. /// </param> /// <param name="caller">a JSR instruction that jump to this subroutine.</param> internal Subroutine(LabelNode start, int maxLocals, JumpInsnNode caller) { this.start = start; localsUsed = new bool[maxLocals]; callers = new List <JumpInsnNode>(); callers.Add(caller); }
private void Start() { // 取得主要的 labelList labelList = LabelMain.Instance.labelList; // 取得選擇的 label selectedToEditLabelDetail = LabelMain.Instance.selectedToEditLabelDetail; label = labelList[selectedToEditLabelDetail]; labelNameInputField.text = label.labelName; labelLatitude.text += label.labelLatitude.ToString(); labelLongitude.text += label.labelLongitude.ToString(); if (label.isNode) { GameObject.Find("ImageFrame").SetActive(false); GameObject.Find("LabelStarsInputField").SetActive(false); GameObject.Find("LabelStars").SetActive(false); } else { labelStarsInputField.text = label.labelStars.ToString(); labelImage.sprite = label.labelSprite; } }
public LabelNodeView(Context context, LabelNode label) : base(context, label) { this.label = label; this.view = new TextView (context); view.Text = label.Text; AddView (view); }
public LabelNodeView(Context context, LabelNode label) : base(context, label) { this.label = label; this.view = new TextView(context); view.Text = label.Text; AddView(view); }
internal LabelNode CreateLabelNode() { int labelId; var data = _assembler.CreateLabelData(out labelId); var node = new LabelNode(labelId); data.ContextData = node; return(node); }
/// <summary> /// Constructs a new /// <see cref="LocalVariableNode" /> /// . /// </summary> /// <param name="name">the name of a local variable.</param> /// <param name="descriptor">the type descriptor of this local variable.</param> /// <param name="signature"> /// the signature of this local variable. May be /// <literal>null</literal> /// . /// </param> /// <param name="start"> /// the first instruction corresponding to the scope of this local variable /// (inclusive). /// </param> /// <param name="end"> /// the last instruction corresponding to the scope of this local variable (exclusive). /// </param> /// <param name="index">the local variable's index.</param> public LocalVariableNode(string name, string descriptor, string signature, LabelNode start, LabelNode end, int index) { this.name = name; desc = descriptor; this.signature = signature; this.start = start; this.end = end; this.index = index; }
public MainScene(Location Size) : base(Size) { ConnectionClient Connection = new ConnectionClient(); Connection.Connect((Port) => { if (Port != 0) { Logger.Log("Connecting on Port " + Port); Client = new Client(Port); } else { Logger.Log("Failed to connect to remote host"); } Connection.Dispose(); }); Player = new Player(); Player.Scale = 10; Player.Layer = 10; AddChild(Player); Players.Add(Player); Tiles = new TileManager(2048, 2048, ClansGame.TestTileTexture, 8); Tiles.Scale = 5; for (int Y = 0; Y < Tiles.Height; Y++) { for (int X = 0; X < Tiles.Width; X++) { Tiles.Set(X, Y, 3 + JRandom.Next(3), 0, 1, 0); } } Tiles.Layer = -1; AddChild(Tiles); Camera.Target = Player; Snow = new SnowEffect(2); Snow.Intensity = 0; UI.AddChild(Snow); Info = new LabelNode(Font.Default, "WASD to move + and - to change the bleeding", 20); Info.Position = new Location(Size.X / 2, Size.Y * 0.3); Info.AnchorPoint.X = 0.5; Info.Color = new Color(128, 128, 130); UI.AddChild(Info); Input.ListenForKey(Keys.I, this); Input.ListenForKey(Keys.O, this); Input.ListenForKey(Keys.P, this); }
public static IEnumerable <Node> BuildTrace(Node node) { trace.Clear(); epilog = LabelFactory.NextLabel(); labels.Clear(); assigned.Clear(); DfsVisit(node); trace.Add(epilog); return(trace); }
private void CreateInstructionNode(InstructionId instructionId, Operand[] operands) { var options = _assembler.GetInstructionOptionsAndReset(); if (instructionId.IsJump()) { LabelNode target = null; JumpNode next = null; CodeNodeFlags flags = 0; if (!options.IsSet(InstructionOptions.Unfollow)) { if (operands[0].IsLabel()) { target = _assembler.GetLabelData(operands[0].Id).ContextData; } else { options |= InstructionOptions.Unfollow; } } flags |= instructionId == InstructionId.Jmp ? CodeNodeFlags.Jmp | CodeNodeFlags.Taken : CodeNodeFlags.Jcc; if (target != null) { next = target.From; } // The 'jmp' is always taken, conditional jump can contain hint, we detect it. if (instructionId == InstructionId.Jmp) { flags |= CodeNodeFlags.Taken; } else if (options.IsSet(InstructionOptions.Taken)) { flags |= CodeNodeFlags.Taken; } var node = new JumpNode(instructionId, options, operands); node.Flags |= flags; node.Target = target; if (target != null) { node.NextJump = next; target.From = node; target.ReferenceCount++; } AddNode(node); return; } var inst = new InstructionNode(instructionId, options, operands); AddNode(inst); }
public Coverflow() { images = new List<CoverflowItem> (); leftLabel = new LabelNode (); rightLabel = new LabelNode (); imagesize = 100; TouchEvents = true; base.Add (leftLabel); base.Add (rightLabel); Hints.Shadow = true; }
public Coverflow() { images = new List <CoverflowItem> (); leftLabel = new LabelNode(); rightLabel = new LabelNode(); imagesize = 100; TouchEvents = true; base.Add(leftLabel); base.Add(rightLabel); Hints.Shadow = true; }
public void setLabel(bool isNode) { Debug.Log("Click Button setLabel"); Text LabelName = GameObject.Find("LabelName").transform.Find("Text").GetComponent <Text>();; Debug.Log(LabelName.text.ToString()); if (LabelName.text == string.Empty) { Debug.Log("Please Input Text"); return; } if (!labelList.ContainsKey(LabelName.text)) { // 建立 label 和 labelToggle label = new LabelNode(LabelName.text, latitude, longitude); // 設定 isNode label.isNode = isNode; // 建立 labelToggle 物件, 指派 parent 為 LabelCanvas label.labelToggle = Instantiate(labelTogglePrefab, labelToggleParent.transform).GetComponent <Toggle>(); label.labelToggle.name = label.labelName; // 調整 labelToggle 的 Y 軸位置 label.labelToggle.transform.localPosition = new Vector2(labelToggleX, labelToggleY); labelToggleY -= labelToggleHeight; // 設定 labelToggle 中的文字 Text labelText = label.labelToggle.transform.Find("Label").GetComponent <Text>(); labelText.text = label.labelName; if (label.isNode) { labelText.color = Color.blue; } if (labelMarkerCounter < labelMarker.Length) { labelText.text = labelMarker[labelMarkerCounter] + ": " + labelText.text; labelMarkerCounter++; } // 設定 isON label.labelToggle.isOn = false; // 把 label 加入 List 中 labelList.Add(LabelName.text, label); } }
public int AddLabel(string ident, int targetIndex, int funcIndex) { if (GetLabelByIdent(ident, funcIndex) != null) { return(-1); } var newLabel = new LabelNode { ident = ident, targetIndex = targetIndex, funcIndex = funcIndex, index = table.Length }; table.Push(newLabel); return(newLabel.index); }
public static void Main(string[] args) { Application.Init(); MainWindow win = new MainWindow(); Gtk.Canvas canvas = new Gtk.Canvas(); canvas.Engine.SetBackground(new Color(0.5, 0.5, 0.5)); win.Add(canvas); BoxNode box = new BoxNode(new Color(1, 1, 1), 100, 100); box.Draggable = true; canvas.Root.Add(box); PolygonNode poly = new PolygonNode(50, 50); poly.Color = new Color(0, 0, 1); poly.SetVerticies(new [] { new Point(0, 1), new Point(0, 0), new Point(1, 0.5), }); poly.Draggable = true; canvas.Root.Add(poly); LabelNode label = new LabelNode("Label Node Test"); label.Color = new Color(1, 0, 0); label.Draggable = true; label.ClipInputToTextExtents = true; canvas.Root.Add(label); Random r = new Random(); box.ActivatedEvent += (sender, e) => { box.RotateTo(r.NextDouble() * 5); }; ButtonNode button = new ButtonNode(new LabelNode("Button")); canvas.Root.Add(button); button.MoveTo(300, 100); win.SetSizeRequest(800, 200); win.ShowAll(); Application.Run(); }
public void TestUnconditionalJump() { var lbl = new LabelNode("target"); var jmp = new UnconditionalJumpToLabelNode(lbl); var tile = TileFactory.Jump.Unconditional_Label(); var map = TileFactoryTestUtils.createMapping(); var instructions = tile.Cover(jmp); TileFactoryTestUtils.updateMapping(instructions, map); var got = TileFactoryTestUtils.getASM(instructions, map); var expected = "jmp " + lbl.Label + "\n"; Assert.AreEqual(expected, got); }
public int AddLabel(string Ident, int TargetIndex, int FuncIndex) { if (GetLabelByIdent(Ident, FuncIndex) != null) { return(-1); } var Label = new LabelNode(); Label.Ident = Ident; Label.TargetIndex = TargetIndex; Label.FuncIndex = FuncIndex; LabelTable_.Add(Label); var Index = LabelTable_.Count - 1; Label.Index = Index; return(Index); }
private void AddNodeLabel(ViewNode pNode) { if (null != pNode) { if ((MyConst.View.KnxPageType == pNode.Name) || (MyConst.Controls.KnxGroupBoxType == pNode.Name)) { LabelNode node = new LabelNode(); //pNode.Nodes.Add(node); this.cqpo.ExecuteCommand(new TreeNodeAdd(this.tvPage, pNode, node, -1)); NodeAddEventArgs arg = new NodeAddEventArgs(); arg.mPageNode = this.CurPageNode; arg.mParentNode = pNode; arg.mNode = node; AddNodeNotify(node, arg); } } }
private LabelNode Create(IEnumerable<string> labels) { var enumerable = labels as string[] ?? labels.ToArray(); var lastLabel = enumerable.Last(); var child = this.children.FirstOrDefault(x => x.label == lastLabel); if (child == null) { child = new LabelNode(this, lastLabel); this.children.Add(child); } var count = enumerable.Count() - 1; if (count > 0) { child = child.Create(enumerable.Take(count)); } return child; }
public override void update() { CswNbtMetaDataObjectClass RoleOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswEnumNbtObjectClass.RoleClass ); foreach( CswNbtObjClassRole RoleNode in RoleOC.getNodes( false, true ) ) { RoleNode.IsDemo = false; RoleNode.postChanges( false ); } CswNbtMetaDataObjectClass UserOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswEnumNbtObjectClass.UserClass ); foreach( CswNbtObjClassUser UserNode in UserOC.getNodes( false, true ) ) { if( UserNode.IsAdministrator() ) { UserNode.IsDemo = false; UserNode.postChanges( false ); } } CswNbtMetaDataObjectClass InvGrpOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswEnumNbtObjectClass.InventoryGroupClass ); foreach( CswNbtNode InvGrpNode in InvGrpOC.getNodes( false, true ) ) { InvGrpNode.IsDemo = false; InvGrpNode.postChanges( false ); } CswNbtMetaDataObjectClass InvGrpPermOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswEnumNbtObjectClass.InventoryGroupPermissionClass ); foreach( CswNbtNode InvGrpPermNode in InvGrpPermOC.getNodes( false, true ) ) { InvGrpPermNode.IsDemo = false; InvGrpPermNode.postChanges( false ); } CswNbtMetaDataObjectClass JurisdictionOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswEnumNbtObjectClass.JurisdictionClass ); foreach( CswNbtNode JurisdictionNode in JurisdictionOC.getNodes( false, true ) ) { JurisdictionNode.IsDemo = false; JurisdictionNode.postChanges( false ); } CswNbtMetaDataObjectClass LabelOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswEnumNbtObjectClass.PrintLabelClass ); foreach( CswNbtNode LabelNode in LabelOC.getNodes( false, true ) ) { LabelNode.IsDemo = false; LabelNode.postChanges( false ); } } // update()
private ParseTreeNode<ITreeNode> jumpToLabel(ParseTreeNode<ITreeNode> curNode, String label) { ILabelNode sdf = new LabelNode(""); if (curNode.getComponentType() == LexemeType.LABELED_BLOCK) { sdf = (ILabelNode)curNode.getComponent(); if (sdf.getLabel() == label) { return curNode; } else { return jumpToLabel(curNode.getRight(), label); } } else { return jumpToLabel(curNode.getRight(), label); } }
public void Test_Label() { var node = new LabelNode("myLabel"); var map = TileFactoryTestUtils.createMapping(); var instructions = TileFactory.LabelTile().Cover(node); TileFactoryTestUtils.updateMapping(instructions, map); var insn = instructions.ToArray() [0]; Assert.IsFalse(insn.IsCopyInstruction); Assert.IsFalse(insn.IsJumpInstruction); Assert.IsTrue(insn.IsLabel); Assert.AreEqual(node.Label, insn.Label); var got = TileFactoryTestUtils.getASM(instructions, map); var expected = node.Label + ":\n"; Assert.AreEqual(expected, got); }
static void testCondRegConstJump( Func <RegisterNode, ConstantNode <long>, BinaryOperatorNode> condMaker, Tile tile, string cond_type) { var l = new TemporaryNode(); var r = new ConstantNode <long> (15L); var lbl = new LabelNode("target"); var jmp = new ConditionalJumpToLabelNode(condMaker(l, r), lbl); var map = TileFactoryTestUtils.createMapping(); map.Add(l, TileFactoryTestUtils.RAX); var instructions = tile.Cover(jmp); TileFactoryTestUtils.updateMapping(instructions, map); var got = TileFactoryTestUtils.getASM(instructions, map); var expected = "cmp " + TileFactoryTestUtils.RAX + ", 15\n" + "j" + cond_type + " " + lbl.Label + "\n"; Assert.AreEqual(expected, got); }
public override void Render(Node node, Context context) { LabelNode label = node as LabelNode; Cairo.Engine engine = node.Canvas.Engine as Cairo.Engine; var options = new TextOptions(); options.Color = label.Color.MultiplyAlpha(node.Opacity); options.MaxWidth = label.Width; var size = GetExtents(label.Text, options, engine); double x = label.Width - size.Width; x = (int)(x * label.XAlign); double y = label.Height - size.Height; y = (int)(y * label.YAlign); engine.RenderText(context, label.Text, options, new Point(x, y)); }
public virtual void Visit (LabelNode node) { Visit (node as Node); }
public override void VisitLabelNode(LabelNode l) { Text += l.ToString(); }
public LabelCompiler(LabelNode node) { this.node = node; }
public virtual XzaarExpression Visit(LabelNode label) { return(null); }
private void SecondParse() { Token token = null; while ((token = lexer.NextToken()).type != TokenType.EOF) { // Console.WriteLine ( token ); switch (token.type) { case TokenType.FUNC: isFuncActive = true; currentFunc = script.funcTable.GetFuncByName(lexer.NextToken().value); currentParamIndex = 0; break; case TokenType.CLOSE_BRACE: isFuncActive = false; if (currentFunc.name == XASMLexer.Keyworkd_Main) { script.instrStream.instrs [instrStreamSize].opCode = OpCode.Exit; script.instrStream.instrs [instrStreamSize].opCount = 1; script.instrStream.instrs [instrStreamSize].opList.Add(new Op { type = OpType.INT, intLiteral = 0 }); } else { script.instrStream.instrs [instrStreamSize].opCode = OpCode.Ret; script.instrStream.instrs [instrStreamSize].opCount = 0; script.instrStream.instrs [instrStreamSize].opList = null; } // Console.WriteLine ( $"添加 {script.instrStream.instrs [ instrStreamSize ]} {instrStreamSize} {lexer.LexerPosition}" ); instrStreamSize++; break; case TokenType.PARAM: var paramNameToken = lexer.NextToken(); int stackIndex = -(currentFunc.localDataSize + 2 + (currentParamIndex + 1)); // +2 因为从-2 开始(-1保留) +1 因为参数在返回地址的下面 if (script.symbolTable.AddSymbol(paramNameToken.value, 1, stackIndex, currentFunc.index) == -1) { throw new SyntaxError( string.Format(Messages.ERROR_MSG_FUNC_PARAM_DUPLICATE_DEFINITION, paramNameToken.value), token.span.Start.Line, token.span.Start.Column); } currentParamIndex++; break; case TokenType.INSTR: InstrLookup currentInstrLookup = null; if (!instrLookupTable.GetInstrByMnemonic(token.value, out currentInstrLookup)) { throw new SyntaxError( string.Format(Messages.ERROR_MSG_INSTR_NOT_FOUND, token.value), token.span.Start.Line, token.span.Start.Column); } script.instrStream.instrs [instrStreamSize].opCode = currentInstrLookup.opCode; script.instrStream.instrs [instrStreamSize].opCount = currentInstrLookup.opCount; for (int i = 0; i < currentInstrLookup.opCount; i++) { OpFlagType currentOpFlagType = currentInstrLookup.opList [i]; Token instrParamToken = lexer.NextToken(); // Console.WriteLine ( $"指令参数{i}: {instrParamToken}" ); switch (instrParamToken.type) { case TokenType.INT: if ((currentOpFlagType & OpFlagType.INT) == OpFlagType.INT) { script.instrStream.instrs [instrStreamSize].opList.Add(new Op { type = OpType.INT, intLiteral = int.Parse(instrParamToken.value) }); } else { throw new SyntaxError( string.Format(Messages.ERROR_MSG_INSTR_WRONG_PARAM, token.value, i, instrParamToken.value), token.span.Start.Line, token.span.Start.Column); } break; case TokenType.FLOAT: if ((currentOpFlagType & OpFlagType.FLOAT) == OpFlagType.FLOAT) { script.instrStream.instrs [instrStreamSize].opList.Add(new Op { type = OpType.FLOAT, floatLiteral = float.Parse(instrParamToken.value) }); } else { throw new SyntaxError( string.Format(Messages.ERROR_MSG_INSTR_WRONG_PARAM, token.value, i, instrParamToken.value), token.span.Start.Line, token.span.Start.Column); } break; case TokenType.STRING: if ((currentOpFlagType & OpFlagType.STRING) == OpFlagType.STRING) { int stringTableIdx = script.stringTable.AddString(instrParamToken.value); script.instrStream.instrs [instrStreamSize].opList.Add(new Op { type = OpType.STRING, stringTableIndex = stringTableIdx }); } else { throw new SyntaxError( string.Format(Messages.ERROR_MSG_INSTR_WRONG_PARAM, token.value, i, instrParamToken.value), token.span.Start.Line, token.span.Start.Column); } break; case TokenType.REG_RETVAL: if ((currentOpFlagType & OpFlagType.REG) == OpFlagType.REG) { script.instrStream.instrs [instrStreamSize].opList.Add(new Op { type = OpType.REG, reg = 0 }); } else { throw new SyntaxError( string.Format(Messages.ERROR_MSG_INSTR_WRONG_PARAM, token.value, i, instrParamToken.value), token.span.Start.Line, token.span.Start.Column); } break; case TokenType.IDENT: if ((currentOpFlagType & OpFlagType.FUNC_NAME) == OpFlagType.FUNC_NAME) { FuncNode func = script.funcTable.GetFuncByName(instrParamToken.value); if (func != null) { script.instrStream.instrs [instrStreamSize].opList.Add(new Op { type = OpType.FUNC_INDEX, funcIndex = func.index }); } else { throw new SyntaxError( string.Format(Messages.ERROR_MSG_FUNC_NOT_FOUND, instrParamToken.value), token.span.Start.Line, token.span.Start.Column); } } if ((currentOpFlagType & OpFlagType.LINE_LABEL) == OpFlagType.LINE_LABEL) { LabelNode labelNode = script.labelTable.GetLabelByIdent(instrParamToken.value, currentFunc.index); if (labelNode != null) { script.instrStream.instrs [instrStreamSize].opList.Add(new Op { type = OpType.INSTR_INDEX, instrIndex = labelNode.targetIndex }); } else { throw new SyntaxError( string.Format(Messages.ERROR_MSG_LABEL_NOT_FOUND, instrParamToken.value), token.span.Start.Line, token.span.Start.Column); } } if ((currentOpFlagType & OpFlagType.MEM_REF) == OpFlagType.MEM_REF) { SymbolNode symbolNode = script.symbolTable.GetSymbolByIdent(instrParamToken.value, currentFunc.index); // 如果该变量不是函数作用域内定义的,则查找全局变量 if (symbolNode == null) { symbolNode = script.symbolTable.GetSymbolByIdent(instrParamToken.value, -1); } if (symbolNode == null) { throw new SyntaxError( string.Format(Messages.ERROR_MSG_VAR_NOT_FOUND, instrParamToken.value), token.span.Start.Line, token.span.Start.Column); } int baseIndex = symbolNode.stackIndex; char symbolNextChar = lexer.PeekChar(1); if (symbolNextChar != char.MinValue) { // 非数组成员 if (symbolNextChar != XASMLexer.Open_Bracket) { // 验证非数组定义 if (symbolNode.size > 1) { throw new SyntaxError(Messages.ERROR_MSG_VAR_ARRAY_START_ERROR, token.span.Start.Line, token.span.Start.Column); } script.instrStream.instrs [instrStreamSize].opList.Add(new Op { type = OpType.ABS_STACK_INDEX, stackIndex = baseIndex }); } else { // 验证数组定义 if (symbolNode.size <= 1) { throw new SyntaxError( string.Format(Messages.ERROR_MSG_VAR_TYPE_IS_NOT_A_ARRAY, instrParamToken.value), token.span.Start.Line, token.span.Start.Column); } // 左中括号 lexer.NextToken(); // 数组索引参数 Token arrayIndexParamToken = lexer.NextToken(); // 数组索引是常数 if (arrayIndexParamToken.type == TokenType.INT) { int offset = int.Parse(arrayIndexParamToken.value); if (offset >= symbolNode.size) { throw new SyntaxError( string.Format(Messages.ERROR_MSG_INDEX_OUT_OF_BOUNDS, arrayIndexParamToken.value), token.span.Start.Line, token.span.Start.Column); } script.instrStream.instrs [instrStreamSize].opList.Add(new Op { type = OpType.ABS_STACK_INDEX, stackIndex = baseIndex >= 0 ? baseIndex + offset : baseIndex - offset }); } // 数组索引是变量 else if (arrayIndexParamToken.type == TokenType.IDENT) { SymbolNode offsetSymbolNode = script.symbolTable.GetSymbolByIdent(arrayIndexParamToken.value, currentFunc.index); // 如果该变量不是函数作用域内定义的,则查找全局变量 if (offsetSymbolNode == null) { symbolNode = script.symbolTable.GetSymbolByIdent(arrayIndexParamToken.value, -1); } if (offsetSymbolNode == null) { throw new SyntaxError( string.Format(Messages.ERROR_MSG_VAR_NOT_FOUND, arrayIndexParamToken.value), token.span.Start.Line, token.span.Start.Column); } // 不支持数组作为数组的索引 if (offsetSymbolNode.size > 1) { throw new SyntaxError( string.Format(Messages.ERROR_MSG_VAR_ARRAY_INDEX_TYPE_NOT_SUPPORT, arrayIndexParamToken.value), token.span.Start.Line, token.span.Start.Column); } script.instrStream.instrs [instrStreamSize].opList.Add(new Op { type = OpType.REL_STACK_INDEX, stackIndex = offsetSymbolNode.stackIndex }); // 右中括号 if (lexer.NextToken().type != TokenType.CLOSE_BRACKET) { throw new SyntaxError(Messages.ERROR_MSG_VAR_ARRAY_END_ERROR, token.span.Start.Line, token.span.Start.Column); } } else { throw new SyntaxError( string.Format(Messages.ERROR_MSG_VAR_ARRAY_INDEX_TYPE_NOT_SUPPORT, arrayIndexParamToken.value), token.span.Start.Line, token.span.Start.Column); } } } else { throw new SyntaxError(Messages.ERROR_MSG_INVALID_TOKEN, token.span.Start.Line, token.span.Start.Column); } } break; default: throw new SyntaxError( string.Format(Messages.ERROR_MSG_INVALID_PARAM_TYPE, instrParamToken.value), token.span.Start.Line, token.span.Start.Column); break; } // 指令参数之间的逗号分隔符 if (i < currentInstrLookup.opCount - 1) { if (lexer.NextToken().type != TokenType.COMMA) { throw new SyntaxError(Messages.ERROR_MSG_INSTR_PARAM_MISS_COMMA, token.span.Start.Line, token.span.Start.Column); } } } // 每条指令以换行符结束 if (lexer.NextToken().type != TokenType.NEWLINE) { throw new SyntaxError(Messages.ERROR_MSG_INSTR_END_MISMATCH, token.span.Start.Line, token.span.Start.Column); } // Console.WriteLine ( $"添加 {script.instrStream.instrs [ instrStreamSize ]} {instrStreamSize} {lexer.LexerPosition}" ); instrStreamSize++; break; // End Of TokenType.INSTR } // End Of switch ( token.Type ) // SkipToNextLine??? } // End Of While }
public ITreeNode Program() { ITreeNode programNode = new ErrorNode(); switch (curTokenType) { case TokenType.BEGINBL: Match(ref matchToken, TokenType.BEGINBL); ITreeNode someStatement = Program(); BlockNode block = new BlockNode(); block.addStatement(someStatement); while (curTokenType != TokenType.ENDBL) { someStatement = Program(); block.addStatement(someStatement); } Match(ref matchToken, TokenType.ENDBL); programNode = block; break; case TokenType.LABEL: Match(ref matchToken, TokenType.LABEL); LabelNode labeledBlock = new LabelNode(matchToken.getValue()); ITreeNode labeledStatement; do { labeledStatement = Program(); labeledBlock.addStatement(labeledStatement); } while (curTokenType != TokenType.EOF); programNode = labeledBlock; break; case TokenType.INTDEC: Match(ref matchToken, TokenType.INTDEC); Match(ref matchToken, TokenType.ID); programNode = new IdentifierDeclarationNode(IdentifierType.INT, matchToken.getValue()); Match(ref matchToken, TokenType.EOS); break; case TokenType.BOOLDEC: Match(ref matchToken, TokenType.BOOLDEC); Match(ref matchToken, TokenType.ID); programNode = new IdentifierDeclarationNode(IdentifierType.BOOL, matchToken.getValue()); Match(ref matchToken, TokenType.EOS); break; case TokenType.FOR: Match(ref matchToken, TokenType.FOR); Match(ref matchToken, TokenType.LPAREN); AssignmentNode init = (AssignmentNode)Program(); AssignmentNode step = (AssignmentNode)Program(); BooleanExpressionNode condition = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.RPAREN); BlockNode forBody = (BlockNode)Program(); programNode = new ForNode(init, step, condition, forBody); break; /*case TokenType.FUN: Match(ref matchToken, TokenType.FUN); IdentifierNode id = (IdentifierNode)Factor(); programNode = new FunctionNode(id); Match(ref matchToken, TokenType.EOS); break;*/ case TokenType.GOTO: Match(ref matchToken, TokenType.GOTO); Match(ref matchToken, TokenType.ID); IdentifierNode gotoLabel = new IdentifierNode(matchToken.getValue(), IdentifierType.LABEL); programNode = new GotoNode(gotoLabel); Match(ref matchToken, TokenType.EOS); break; case TokenType.ID: Match(ref matchToken, TokenType.ID); IdentifierNode assignId = new IdentifierNode(matchToken.getValue(), IdentifierType.UNKNOWN); Match(ref matchToken, TokenType.ASSIGN); BooleanExpressionNode assignValue = (BooleanExpressionNode)BooleanExpression(); programNode = new AssignmentNode(assignId, assignValue); Match(ref matchToken, TokenType.EOS); break; case TokenType.IF: Match(ref matchToken, TokenType.IF); ITreeNode thenBranch; ITreeNode elseBranch; Match(ref matchToken, TokenType.LPAREN); BooleanExpressionNode ifCondition = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.RPAREN); Match(ref matchToken, TokenType.THEN); thenBranch = (BlockNode)Program(); if (curTokenType == TokenType.ELSE) { Match(ref matchToken, TokenType.ELSE); elseBranch = (BlockNode)Program(); } else { elseBranch = new BlankNode(); } programNode = new IfNode(ifCondition, thenBranch, elseBranch); break; /*case TokenType.LET: Match(ref matchToken, TokenType.LET); IdentifierNode shortId = (IdentifierNode)Factor(); Match(ref matchToken, TokenType.ASSIGN); BooleanExpressionNode subst = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.IN); BooleanExpressionNode target = (BooleanExpressionNode)BooleanExpression(); programNode = new LetNode(shortId, subst, target); Match(ref matchToken, TokenType.EOS); break;*/ case TokenType.PRINT: Match(ref matchToken, TokenType.PRINT); Match(ref matchToken, TokenType.LPAREN); BooleanExpressionNode printArgument = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.RPAREN); programNode = new PrintNode(printArgument); Match(ref matchToken, TokenType.EOS); break; case TokenType.WHILE: Match(ref matchToken, TokenType.WHILE); Match(ref matchToken, TokenType.LPAREN); BooleanExpressionNode whileCondition = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.RPAREN); BlockNode whileBody = (BlockNode)Program(); programNode = new WhileNode(whileCondition, whileBody); break; case TokenType.EOF: programNode = new BlankNode(); break; default: Expect(TokenType.UNKNOWN, lookAheadToken); break; } return programNode; }
public DnsNameWriter(Stream stream) { this.stream = stream; this.rootLabelNode = new LabelNode(null, string.Empty); }
public LabelNode(LabelNode parent, string label) { this.label = label; this.parent = parent; this.children = new List<LabelNode>(); }
public void Accept(LabelNode node) { if (!table.ContainsSymbol(node.Identifier)) table.AddSymbol(node.Identifier); method.Instructions.Reverse(); method.Emit(node.SourceLocation, InstructionType.StoreLocal, table.GetSymbol(node.Identifier)); method.Emit(node.SourceLocation, InstructionType.BuildLabel, method.Instructions.Count); method.Instructions.Reverse(); }
public ParseTreeNode<ITreeNode> extractLabels(ILabelNode node) { bool labelFound = false; int position = 0; List<ITreeNode> curBlock = node.getBlock(); //the highest block, with possible nested blocks String curLabel = node.getLabel(); ParseTreeNode<ITreeNode> labelNode;//the node we return ParseTreeNode<ITreeNode> nextLabelNode = new ParseTreeNode<ITreeNode>(null, null, node); while (position < curBlock.Count) { if (curBlock[position].getLexemeType() == LexemeType.LABELED_BLOCK) { ILabelNode tempNode = (ILabelNode)curBlock[position]; //create a new ParseTreeNode, with that element as a component //and with the result of extractLabels() as a right node labelFound = true; ILabelNode subNode = new LabelNode(tempNode.getLabel(), tempNode.getBlock()); nextLabelNode = extractLabels(subNode); } position++; } if (labelFound) { labelNode = new ParseTreeNode<ITreeNode>(null, nextLabelNode, node); } else { labelNode = new ParseTreeNode<ITreeNode>(null, null, node); } return labelNode; }
public void Accept(LabelNode node) { }