void Associative_FunctionalStatement(out ProtoCore.AST.AssociativeAST.AssociativeNode node) { while (!(StartOf(10))) {SynErr(77); Get();} node = null; ProtoCore.AST.AssociativeAST.AssociativeNode leftNode = null; ProtoCore.AST.AssociativeAST.BinaryExpressionNode expressionNode = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(); isLeft = true; Associative_DecoratedIdentifier(out leftNode); isLeft = false; NodeUtils.CopyNodeLocation(expressionNode, leftNode); node = leftNode; if (la.kind == 23) { Get(); if (core.ParsingMode != ParseMode.AllowNonAssignment) { expressionNode.LeftNode = leftNode; expressionNode.RightNode = null; expressionNode.Optr = Operator.assign; NodeUtils.UpdateBinaryExpressionLocation(expressionNode); node = expressionNode; } } else if (la.kind == 51) { Get(); ProtoCore.AST.AssociativeAST.AssociativeNode rightNode = null; bool isLeftMostNode = false; if (leftVar == null) { if (node is ProtoCore.AST.AssociativeAST.IdentifierListNode) { isLeftVarIdentList = true; leftVar = ProtoCore.Utils.CoreUtils.GenerateIdentListNameString(node); } else { isLeftVarIdentList = false; leftVar = node.Name; } isLeftMostNode = true; withinModifierCheckScope = true; } if (HasMoreAssignmentStatements()) { Associative_FunctionalStatement(out rightNode); expressionNode.LeftNode = leftNode; expressionNode.RightNode = rightNode; NodeUtils.SetNodeEndLocation(expressionNode, rightNode); expressionNode.Optr = Operator.assign; expressionNode.isMultipleAssign = true; node = expressionNode; } else if (la.kind == 10) { withinModifierCheckScope = false; Associative_LanguageBlock(out rightNode); NodeUtils.SetNodeEndLocation(expressionNode, t); expressionNode.LeftNode = leftNode; expressionNode.RightNode = rightNode; expressionNode.Optr = Operator.assign; node = expressionNode; } else if (IsModifierStack()) { withinModifierCheckScope = false; Expect(45); ProtoCore.AST.AssociativeAST.ModifierStackNode mstack = new ProtoCore.AST.AssociativeAST.ModifierStackNode(); NodeUtils.SetNodeStartLocation(mstack, t); Associative_Expression(out rightNode); if (la.val == "=") SynErr(String.Format(Resources.InvalidSymbol, la.val)); ProtoCore.AST.AssociativeAST.IdentifierNode identifier = null; if (la.kind == 53) { Get(); Expect(1); identifier = mstack.CreateIdentifierNode(t, leftNode); } if (null == identifier) identifier = mstack.CreateIdentifierNode(leftNode, core); expressionNode.RightNode = rightNode; expressionNode.LeftNode = leftNode; expressionNode.Optr = Operator.assign; Node elementNode = mstack.AddElementNode(expressionNode, identifier); if (la.val != ";") SynErr(Resources.SemiColonExpected); while (!(la.kind == 0 || la.kind == 23)) {SynErr(78); Get();} Expect(23); NodeUtils.SetNodeEndLocation(elementNode, t); while (StartOf(11)) { bool bHasOperator = false; Operator op = Operator.add; int opLine = Constants.kInvalidIndex; int opCol = Constants.kInvalidIndex; if (StartOf(12)) { bHasOperator = true; Associative_BinaryOps(out op); opLine = t.line; opCol = t.col; } Associative_Expression(out rightNode); if (la.val == "=") SynErr(String.Format(Resources.InvalidSymbol, la.val)); identifier = null; if (la.kind == 53) { Get(); Expect(1); identifier = mstack.CreateIdentifierNode(t, leftNode); } expressionNode = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(); if(!bHasOperator) { expressionNode.RightNode = rightNode; } else { int count = mstack.ElementNodes.Count; ProtoCore.AST.AssociativeAST.BinaryExpressionNode previousElementNode = mstack.ElementNodes[count - 1] as ProtoCore.AST.AssociativeAST.BinaryExpressionNode; // Create function call node from binary expression node expressionNode.RightNode = GenerateBinaryOperatorMethodCallNode(op, previousElementNode.LeftNode, rightNode); NodeUtils.SetNodeStartLocation(expressionNode.RightNode, opLine, opCol); expressionNode.IsModifier = true; } if (null == identifier) identifier = mstack.CreateIdentifierNode(leftNode, core); expressionNode.LeftNode = leftNode; expressionNode.Optr = Operator.assign; elementNode = mstack.AddElementNode(expressionNode, identifier); if (la.val != ";") SynErr(Resources.SemiColonExpected); while (!(la.kind == 0 || la.kind == 23)) {SynErr(79); Get();} Expect(23); NodeUtils.SetNodeEndLocation(elementNode, t); } ProtoCore.AST.AssociativeAST.BinaryExpressionNode previousNode = mstack.ElementNodes[mstack.ElementNodes.Count - 1] as ProtoCore.AST.AssociativeAST.BinaryExpressionNode; if (previousNode.LeftNode.Name.Contains(Constants.kTempModifierStateNamePrefix)) { // if a temporary exists for the final state, assign the modifier block variable to the final state directly expressionNode.RightNode = previousNode.RightNode; // delete previous temporary node mstack.ElementNodes.RemoveAt(mstack.ElementNodes.Count - 1); } else // if the final state has a right assigned variable { expressionNode.RightNode = previousNode.LeftNode; } expressionNode.LeftNode = leftNode; expressionNode.Optr = Operator.assign; NodeUtils.SetNodeStartLocation(expressionNode, expressionNode.LeftNode); mstack.ElementNodes.Add(expressionNode); node = mstack; Expect(46); NodeUtils.SetNodeEndLocation(expressionNode, t); NodeUtils.SetNodeEndLocation(mstack, t); } else if (StartOf(4)) { Associative_Expression(out rightNode); expressionNode.LeftNode = leftNode; expressionNode.RightNode = rightNode; expressionNode.Optr = Operator.assign; NodeUtils.UpdateBinaryExpressionLocation(expressionNode); if (rightNode is ProtoCore.AST.AssociativeAST.ExprListNode) expressionNode.RightNode.Name = leftVar; if (la.kind != _endline) SynErr(Resources.SemiColonExpected); Expect(23); NodeUtils.SetNodeEndLocation(expressionNode, t); node = expressionNode; } else SynErr(80); if (isLeftMostNode) { leftVar = null; if (node is ProtoCore.AST.AssociativeAST.BinaryExpressionNode) { node.IsModifier = isModifier; /* if ((node as ProtoCore.AST.AssociativeAST.BinaryExpressionNode).RightNode is ProtoCore.AST.AssociativeAST.InlineConditionalNode) { node.IsModifier = false; } */ } isModifier = false; withinModifierCheckScope = false; isLeftVarIdentList = false; } } else if (StartOf(13)) { SynErr(Resources.SemiColonExpected); } else SynErr(81); }
public ModifierStackNode(ModifierStackNode rhs) : base(rhs) { ElementNodes = new List<AssociativeNode>(); foreach (AssociativeNode elemNode in rhs.ElementNodes) { AssociativeNode tempNode = NodeUtils.Clone(elemNode); ElementNodes.Add(tempNode); } ReturnNode = null; if (null != rhs.ReturnNode) { ReturnNode = ProtoCore.Utils.NodeUtils.Clone(rhs.ReturnNode); } }