Пример #1
0
        /// <summary>
        /// Gets the semantic element corresponding to the specified label
        /// </summary>
        /// <param name="label">The label of an AST node</param>
        /// <returns>The corresponding semantic element</returns>
        public SemanticElement GetSemanticElementForLabel(TableElemRef label)
        {
            switch (label.Type)
            {
            case TableType.Token:
                return(tableTokens[label.Index]);

            case TableType.Variable:
                return(new ASTLabel(tableVariables[label.Index], SymbolType.Variable));

            case TableType.Virtual:
                return(new ASTLabel(tableVirtuals[label.Index], SymbolType.Virtual));

            case TableType.None:
                return(new ASTLabel(tableTokens.Terminals[0], SymbolType.Terminal));
            }
            // This cannot happen
            return(null);
        }
Пример #2
0
        /// <summary>
        /// Gets the symbol corresponding to the specified label
        /// </summary>
        /// <param name="label">A node label</param>
        /// <returns>The corresponding symbol</returns>
        public Symbol GetSymbolFor(TableElemRef label)
        {
            switch (label.Type)
            {
            case TableType.Token:
                return(tableTokens.GetSymbol(label.Index));

            case TableType.Variable:
                return(tableVariables[label.Index]);

            case TableType.Virtual:
                return(tableVirtuals[label.Index]);

            case TableType.None:
                return(tableTokens.Terminals[0]);                        // terminal epsilon
            }
            // This cannot happen
            return(new Symbol(0, string.Empty));
        }
Пример #3
0
 /// <summary>
 /// Initializes this node
 /// </summary>
 /// <param name="label">The node's label</param>
 /// <param name="count">The number of children</param>
 /// <param name="first">The index of the first child</param>
 public Node(TableElemRef label, int count, int first)
 {
     this.label = label;
     this.count = count;
     this.first = first;
 }
Пример #4
0
 /// <summary>
 /// Initializes this node
 /// </summary>
 /// <param name="label">The node's label</param>
 public Node(TableElemRef label)
 {
     this.label = label;
     this.count = 0;
     this.first = -1;
 }
Пример #5
0
        /// <summary>
        /// Gets the value of the given node
        /// </summary>
        /// <param name="node">A node</param>
        /// <returns>The associated value</returns>
        public string GetValue(int node)
        {
            TableElemRef sym = nodes[node].label;

            return(sym.Type == TableType.Token ? tableTokens.GetValue(sym.Index) : null);
        }
Пример #6
0
        /// <summary>
        /// Gets the context in the input of the given node
        /// </summary>
        /// <param name="node">A node</param>
        /// <returns>The context</returns>
        public TextContext GetContext(int node)
        {
            TableElemRef sym = nodes[node].label;

            return(sym.Type == TableType.Token ? tableTokens.GetContext(sym.Index) : new TextContext());
        }
Пример #7
0
        /// <summary>
        /// Gets the span in the input text of the given node
        /// </summary>
        /// <param name="node">A node</param>
        /// <returns>The span in the text</returns>
        public TextSpan GetSpan(int node)
        {
            TableElemRef sym = nodes[node].label;

            return(sym.Type == TableType.Token ? tableTokens.GetSpan(sym.Index) : new TextSpan(0, 0));
        }