Returns an Array containing all the terminal names as symbols. The first
 terminal is always `:$EOF` to ensure the array has the same amount of rows
 as there are columns in the `table` array.

 @param [LL::CompiledGrammar] grammar
 @return [Array]
17951
def generate_terminals(grammar)
      terminals = [:$EOF]

      grammar.terminals.each do |term|
        terminals << term.name.to_sym
      end

      return terminals
    end
787923
function FindFirstSets()
    {
        for ($i = 0; $i < $this->nsymbol; $i++) {
            $this->symbols[$i]->lambda = false;
        }
        for($i = $this->nterminal; $i < $this->nsymbol; $i++) {
            $this->symbols[$i]->firstset = array();
        }

        /* First compute all lambdas */
        do{
            $progress = 0;
            for ($rp = $this->rule; $rp; $rp = $rp->next) {
                if ($rp->lhs->lambda) {
                    continue;
                }
                for ($i = 0; $i < $rp->nrhs; $i++) {
                    $sp = $rp->rhs[$i];
                    if ($sp->type != PHP_ParserGenerator_Symbol::TERMINAL || $sp->lambda === false) {
                        break;
                    }
                }
                if ($i === $rp->nrhs) {
                    $rp->lhs->lambda = true;
                    $progress = 1;
                }
            }
        } while ($progress);

        /* Now compute all first sets */
        do {
            $progress = 0;
            for ($rp = $this->rule; $rp; $rp = $rp->next) {
                $s1 = $rp->lhs;
                for ($i = 0; $i < $rp->nrhs; $i++) {
                    $s2 = $rp->rhs[$i];
                    if ($s2->type == PHP_ParserGenerator_Symbol::TERMINAL) {
                        //progress += SetAdd(s1->firstset,s2->index);
                        $progress += isset($s1->firstset[$s2->index]) ? 0 : 1;
                        $s1->firstset[$s2->index] = 1;
                        break;
                    } elseif ($s2->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) {
                        for ($j = 0; $j < $s2->nsubsym; $j++) {
                            //progress += SetAdd(s1->firstset,s2->subsym[j]->index);
                            $progress += isset($s1->firstset[$s2->subsym[$j]->index]) ? 0 : 1;
                            $s1->firstset[$s2->subsym[$j]->index] = 1;
                        }
                        break;
                    } elseif ($s1 === $s2) {
                        if ($s1->lambda === false) {
                            break;
                        }
                    } else {
                        //progress += SetUnion(s1->firstset,s2->firstset);
                        $test = array_diff_key($s2->firstset, $s1->firstset);
                        if (count($test)) {
                            $progress++;
                            $s1->firstset += $test;
                        }
                        if ($s2->lambda === false) {
                            break;
                        }
                    }
                }
            }
        } while ($progress);
    }
1185129
def parse
      @table = []
      rows = @doc.split(/\r?\n/)
      rows.each do |row|
        row_array = row.split("|")
        row_array.each(&:strip!)
        @table.push(row_array)
      end
      @table.delete_at(1) if @header # strip header separator
      @table
    end
946688
def p_lexpr(p):
    
    global LET_ASSIGNMENT

    LET_ASSIGNMENT = True  # Mark we're about to start a LET sentence

    if p[1] == 'LET':
        p[0] = p[2]
        i = 2
    else:
        p[0] = p[1]
        i = 1

    SYMBOL_TABLE.access_id(p[i], p.lineno(i))
773578
function() {
      var terminalList = [];
      if(this.wires) {
         for(var i = 0 ; i < this.wires.length ; i++) {
            terminalList.push(this.wires[i].getOtherTerminal(this));
         }
      }
      return terminalList;
   }
1145076
def extract(grammar, inputdata, fixed_start = False, return_first=False):
    
    if not inputdata:
        return []
    checker = checker_factory(grammar)

    totallen = len(inputdata)
    from pydsl.grammar.PEG import Choice
    try:
        maxl = grammar.maxsize or totallen
    except NotImplementedError:
        maxl = totallen
    try:
        #minl = grammar.minsize #FIXME: It won't work with incompatible alphabets
        minl = 1
    except NotImplementedError:
        minl = 1
    if fixed_start:
        max_start = 1
    else:
        max_start = totallen
    result = []
    for i in range(max_start):
        for j in range(i+minl, min(i+maxl, totallen) + 1):
            slice = inputdata[i:j]
            check = checker.check(slice)
            if check:
                this_pt = PositionToken(slice, grammar, i, j)
                if return_first:
                    return this_pt
                result.append(this_pt)
    return result
703182
def warn_for_unused_terminals(compiled_grammar)
      compiled_grammar.terminals.each do |terminal|
        next if terminal.references > 0

        compiled_grammar.add_warning(
          "Unused terminal #{terminal.name.inspect}",
          terminal.source_line
        )
      end
    end
880845
public static Grammar translate(Rule[] rules, StringArrayList symbolTable) throws ActionException {
        int i;
        Ebnf builder;
        Grammar tmp;
        Grammar buffer;
        int firstHelper;
        int lastHelper;

        firstHelper = symbolTable.size();
        buffer = new Grammar(rules[0].getLeft(), symbolTable);
        builder = new Ebnf(firstHelper);
        for (i = 0; i < rules.length; i++) {
            tmp = (Grammar) rules[i].getRight().visit(builder);
            buffer.addProduction(new int[]{rules[i].getLeft(), tmp.getStart()});
            buffer.addProductions(tmp);
            buffer.expandSymbol(tmp.getStart());
            buffer.removeProductions(tmp.getStart());
        }
        lastHelper = builder.getHelper() - 1;
        buffer.removeDuplicateSymbols(firstHelper, lastHelper);
        buffer.removeDuplicateRules();
        buffer.packSymbols(firstHelper, lastHelper + 1);
        return buffer;
    }
206971
def core__get_modules_languages
      lato_modules = core__get_modules_list
      languages = {}
      lato_modules.each do |lato_module_name|
        languages[lato_module_name.to_sym] = core__get_module_languages(lato_module_name)
      end
      languages
    end
764547
def remove_unreachable_symbols(grammar, inplace=False):
    # type: (Grammar, bool) -> Grammar
    
    # copy if required
    if inplace is False:
        grammar = copy(grammar)
    # check if start symbol is set
    if grammar.start is None:
        raise StartSymbolNotSetException()
    # create process sets
    reachable = {grammar.start}
    rules = grammar.rules.copy()
    # begin iterations
    while True:
        # create sets for current iteration
        active = reachable.copy()
        # loop the working rules
        for rule in rules.copy():
            # lf left part of rule already in reachable symbols
            if rule.fromSymbol in reachable:
                # set symbols on the right as reachable
                for symbol in rule.right:
                    active.add(symbol)
                # remove rule from the next iteration
                rules.remove(rule)
            # end of rules loop
        # if current and previous iterations are same, we are done
        if active == reachable:
            break
        # otherwise swap the sets
        reachable = active
    # remove the symbols
    nonterminals_to_remove = grammar.nonterminals.difference(reachable)
    terminals_to_remove = grammar.terminals.difference(reachable)
    grammar.nonterminals.remove(*nonterminals_to_remove)
    grammar.terminals.remove(*terminals_to_remove)
    # return grammar
    return grammar
1219175
public static function Symbol_new($x)
    {
        if (isset(self::$_symbol_table[$x])) {
            return self::$_symbol_table[$x];
        }
        $sp = new PHP_ParserGenerator_Symbol;
        $sp->name = $x;
        $sp->type = preg_match('/[A-Z]/', $x[0]) ? self::TERMINAL : self::NONTERMINAL;
        $sp->rule = 0;
        $sp->fallback = 0;
        $sp->prec = -1;
        $sp->assoc = self::UNK;
        $sp->firstset = array();
        $sp->lambda = false;
        $sp->destructor = 0;
        $sp->datatype = 0;
        self::$_symbol_table[$sp->name] = $sp;
        return $sp;
    }
346287
function FindStates()
    {
        PHP_ParserGenerator_Config::Configlist_init();
    
        /* Find the start symbol */
        if ($this->start) {
            $sp = PHP_ParserGenerator_Symbol::Symbol_find($this->start);
            if ($sp == false) {
                PHP_ParserGenerator::ErrorMsg($this->filename, 0,
                    "The specified start symbol \"%s\" is not " .
                    "in a nonterminal of the grammar.  \"%s\" will be used as the start " .
                    "symbol instead.", $this->start, $this->rule->lhs->name);
                $this->errorcnt++;
                $sp = $this->rule->lhs;
            }
        } else {
            $sp = $this->rule->lhs;
        }
    
        /* Make sure the start symbol doesn't occur on the right-hand side of
        ** any rule.  Report an error if it does.  (YACC would generate a new
        ** start symbol in this case.) */
        for ($rp = $this->rule; $rp; $rp = $rp->next) {
            for ($i = 0; $i < $rp->nrhs; $i++) {
                if ($rp->rhs[$i]->type == PHP_ParserGenerator_Symbol::MULTITERMINAL) {
                    foreach ($rp->rhs[$i]->subsym as $subsp) {
                        if ($subsp === $sp) {
                            PHP_ParserGenerator::ErrorMsg($this->filename, 0,
                                "The start symbol \"%s\" occurs on the " .
                                "right-hand side of a rule. This will result in a parser which " .
                                "does not work properly.", $sp->name);
                            $this->errorcnt++;
                        }
                    }
                } elseif ($rp->rhs[$i] === $sp) {
                    PHP_ParserGenerator::ErrorMsg($this->filename, 0,
                        "The start symbol \"%s\" occurs on the " .
                        "right-hand side of a rule. This will result in a parser which " .
                        "does not work properly.", $sp->name);
                    $this->errorcnt++;
                }
            }
        }
    
        /* The basis configuration set for the first state
        ** is all rules which have the start symbol as their
        ** left-hand side */
        for ($rp = $sp->rule; $rp; $rp = $rp->nextlhs) {
            $newcfp = PHP_ParserGenerator_Config::Configlist_addbasis($rp, 0);
            $newcfp->fws[0] = 1;
        }
    
        /* Compute the first state.  All other states will be
        ** computed automatically during the computation of the first one.
        ** The returned pointer to the first state is not used. */
        $newstp = array();
        $newstp = $this->getstate();
        if (is_array($newstp)) {
            $this->buildshifts($newstp[0]); /* Recursively compute successor states */
        }
    }
290155
private static char[] buildTable() {
    char[] table = new char[26];
    for (int ix = 0; ix < table.length; ix++)
      table[ix] = '0';
    table['B' - 'A'] = '1';
    table['P' - 'A'] = '1';
    table['F' - 'A'] = '1';
    table['V' - 'A'] = '1';
    table['C' - 'A'] = '2';
    table['S' - 'A'] = '2';
    table['K' - 'A'] = '2';
    table['G' - 'A'] = '2';
    table['J' - 'A'] = '2';
    table['Q' - 'A'] = '2';
    table['X' - 'A'] = '2';
    table['Z' - 'A'] = '2';
    table['D' - 'A'] = '3';
    table['T' - 'A'] = '3';
    table['L' - 'A'] = '4';
    table['M' - 'A'] = '5';
    table['N' - 'A'] = '5';
    table['R' - 'A'] = '6';
    return table;
  }
65132
private Grammar getEqualGrammar(Grammar gr) {

		for (Grammar gx : this.grammars) {
			if (gr == gx) {
				// System.out.println("Exactly the same grammar found: " + gx);
				return gx;
			}

			if (isSameGrammarType(gr, gx)) {
				// type of grammar the same

				if (gr.getNumberOfEvents() == gx.getNumberOfEvents()) {
					List<Grammar> handled = new ArrayList<Grammar>();
					if (isEqualGrammar(gr, gx, handled)) {
						// the same grammar found
						// System.out.println("Same grammar found for: " + gx +
						// " == " + gr);
						return gx;
					}
				}
			}

		}

		return null;
	}
980414
function getSymbols() {
    const symbols = {};
    if (hasUnicode()) {
        symbols.check = '✔';
        symbols.cross = '✘';
    } else {
        symbols.check = 'v';
        symbols.cross = 'x';
    }
    return symbols;
}
711845
def on_terminals(node, compiled_grammar)
      node.children.each do |child|
        name = process(child, compiled_grammar)

        if compiled_grammar.has_terminal?(name)
          compiled_grammar.add_error(
            "The terminal #{name.inspect} has already been defined",
            child.source_line
          )
        else
          compiled_grammar.add_terminal(name, child.source_line)
        end
      end
    end
33071
private static function getSttyColumns()
    {
        $info = static::runCommand('stty -a | grep columns');

        if ($info && preg_match('/rows.(\d+);.columns.(\d+);/i', $info, $matches)) {
            // extract [w, h] from "rows h; columns w;"
        } elseif ($info && preg_match('/;.(\d+).rows;.(\d+).columns/i', $info, $matches)) {
            // extract [w, h] from "; h rows; w columns"
        } else {
            return [];
        }

        return [(int) $matches[2], (int) $matches[1]];
    }