/// <summary> /// Gets the symbol at the i-th index /// </summary> /// <param name="index">Index of the symbol</param> /// <returns>The symbol at the given index</returns> public SemanticElement this[int index] { get { SPPFNodeRef reference = cacheChildren[handleIndices[index]]; SPPFNode sppfNode = sppf.GetNode(reference.NodeId); TableElemRef label = (sppfNode as SPPFNodeNormal).GetVersion(reference.Version).Label; return(result.GetSemanticElementForLabel(label)); } }
/// <summary> /// Builds the final AST for the specified SPPF node reference /// </summary> /// <param name="reference">A reference to an SPPF node in a specific version</param> /// <returns>The AST node for the SPPF reference</returns> public AST.Node BuildFinalAST(SPPFNodeRef reference) { SPPFNode sppfNode = sppf.GetNode(reference.NodeId); SPPFNodeVersion version = (sppfNode as SPPFNodeNormal).GetVersion(reference.Version); if (version.ChildrenCount == 0) { return(new AST.Node(version.Label)); } AST.Node[] buffer = new AST.Node[version.ChildrenCount]; for (int i = 0; i != version.ChildrenCount; i++) { buffer[i] = BuildFinalAST(version.Children[i]); } int first = result.Store(buffer, 0, version.ChildrenCount); return(new AST.Node(version.Label, version.ChildrenCount, first)); }
/// <summary> /// Adds the specified GSS label to the reduction cache with the given tree action /// </summary> /// <param name="gssLabel">The label to add to the cache</param> /// <param name="action">The tree action to apply</param> private void AddToCache(int gssLabel, TreeAction action) { if (action == TreeAction.Drop) { return; } SPPFNode node = sppf.GetNode(gssLabel); if (node.IsReplaceable) { SPPFNodeReplaceable replaceable = node as SPPFNodeReplaceable; // this is replaceable sub-tree for (int i = 0; i != replaceable.ChildrenCount; i++) { AddToCache(sppf.GetNode(replaceable.Children[i].NodeId) as SPPFNodeNormal, replaceable.Actions[i]); } } else { // this is a simple reference to an existing SPPF node AddToCache(node as SPPFNodeNormal, action); } }