----------------------------------------------------------------- Grammar -----------------------------------------------------------------
972537
function(){
            
                /*
                 * stylesheet
                 *  : [ CHARSET_SYM S* STRING S* ';' ]?
                 *    [S|CDO|CDC]* [ import [S|CDO|CDC]* ]*
                 *    [ namespace [S|CDO|CDC]* ]*
                 *    [ [ ruleset | media | page | font_face ] [S|CDO|CDC]* ]*
                 *  ;
                 */ 
               
                var tokenStream = this._tokenStream,
                    charset     = null,
                    token,
                    tt;
                    
                this.fire("startstylesheet");
            
                //try to read character set
                this._charset();
                
                this._skipCruft();

                //try to read imports - may be more than one
                while (tokenStream.peek() == Tokens.IMPORT_SYM){
                    this._import();
                    this._skipCruft();
                }
                
                //try to read namespaces - may be more than one
                while (tokenStream.peek() == Tokens.NAMESPACE_SYM){
                    this._namespace();
                    this._skipCruft();
                }
                
                //get the next token
                tt = tokenStream.peek();
                
                //try to read the rest
                while(tt > Tokens.EOF){
                
                    try {
                
                        switch(tt){
                            case Tokens.MEDIA_SYM:
                                this._media();
                                this._skipCruft();
                                break;
                            case Tokens.PAGE_SYM:
                                this._page(); 
                                this._skipCruft();
                                break;                   
                            case Tokens.FONT_FACE_SYM:
                                this._font_face(); 
                                this._skipCruft();
                                break;  
                            case Tokens.S:
                                this._readWhitespace();
                                break;
                            default:                            
                                if(!this._ruleset()){
                                
                                    //error handling for known issues
                                    switch(tt){
                                        case Tokens.CHARSET_SYM:
                                            token = tokenStream.LT(1);
                                            this._charset(false);
                                            throw new SyntaxError("@charset not allowed here.", token.startLine, token.startCol);
                                        case Tokens.IMPORT_SYM:
                                            token = tokenStream.LT(1);
                                            this._import(false);
                                            throw new SyntaxError("@import not allowed here.", token.startLine, token.startCol);
                                        case Tokens.NAMESPACE_SYM:
                                            token = tokenStream.LT(1);
                                            this._namespace(false);
                                            throw new SyntaxError("@namespace not allowed here.", token.startLine, token.startCol);
                                        default:
                                            tokenStream.get();  //get the last token
                                            this._unexpectedToken(tokenStream.token());
                                    }
                                
                                }
                        }
                    } catch(ex) {
                        if (ex instanceof SyntaxError && !this.options.strict){
                            this.fire({
                                type:       "error",
                                error:      ex,
                                message:    ex.message,
                                line:       ex.line,
                                col:        ex.col
                            });                     
                        } else {
                            throw ex;
                        }
                    }
                    
                    tt = tokenStream.peek();
                }
                
                if (tt != Tokens.EOF){
                    this._unexpectedToken(tokenStream.token());
                }
            
                this.fire("endstylesheet");
            }
1018362
public final void ruleValidID() throws RecognitionException {

        		int stackSize = keepStackSize();
        	
        try {
            // InternalXbase.g:1879:2: ( ( RULE_ID ) )
            // InternalXbase.g:1880:2: ( RULE_ID )
            {
            // InternalXbase.g:1880:2: ( RULE_ID )
            // InternalXbase.g:1881:3: RULE_ID
            {
            if ( state.backtracking==0 ) {
               before(grammarAccess.getValidIDAccess().getIDTerminalRuleCall()); 
            }
            match(input,RULE_ID,FOLLOW_2); if (state.failed) return ;
            if ( state.backtracking==0 ) {
               after(grammarAccess.getValidIDAccess().getIDTerminalRuleCall()); 
            }

            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {

            	restoreStackSize(stackSize);

        }
        return ;
    }
1225621
public Grammar getFragmentGrammar() {
		/*
		 * Fragment Content
		 */
		Grammar builtInFragmentContentGrammar = new BuiltInFragmentContent();

		/*
		 * Fragment
		 */
		fragmentGrammar = new Fragment("Fragment");
		fragmentGrammar.addProduction(new StartDocument(),
				builtInFragmentContentGrammar);

		return fragmentGrammar;
	}
1308077
function compile(grammar) {
  var compiler     = require('./compiler.js'),
      tree         = compiler.parser.matchAll(grammar, 'topLevel'),
	    parserString = compiler.translator.match(tree, 'trans');
  return parserString;
}
166372
public function addFluentCommands(Grammar $grammar)
    {
        foreach ($this->columns as $column) {
            foreach ($grammar->getFluentCommands() as $commandName) {
                $attributeName = lcfirst($commandName);

                if (! isset($column->{$attributeName})) {
                    continue;
                }

                $value = $column->{$attributeName};

                $this->addCommand(
                    $commandName, compact('value', 'column')
                );
            }
        }
    }
1012240
protected function grammar()
		{
			if (isset($this->grammar)) return $this->grammar;

			switch (isset($this->config['grammar']) ? $this->config['grammar'] : $this->driver()) {
				case 'mysql':
					return $this->grammar = new Query\Grammars\MySQL($this);

				case 'sqlsrv':
					return $this->grammar = new Query\Grammars\SQLServer($this);

				default:
					return $this->grammar = new Query\Grammars\Grammar($this);
			}
		}
78195
function Grammar(delimiters) {
    this.delimiters = delimiters;

    this.internal = [
      makeEntry("START_IF", "if"),
      makeEntry("ELSE", "else"),
      makeEntry("ELSIF", "elsif"),
      makeEntry("END_IF", "endif"),
      makeEntry("NOT", "not"),
      makeEntry("EQUALITY", "=="),
      makeEntry("NOT_EQUALITY", "!="),
      makeEntry("GREATER_THAN_EQUAL", ">="),
      makeEntry("GREATER_THAN", ">"),
      makeEntry("LESS_THAN_EQUAL", "<="),
      makeEntry("LESS_THAN", "<"),
      makeEntry("START_EACH", "each"),
      makeEntry("END_EACH", "endeach"),
      makeEntry("ASSIGN", "as"),
      makeEntry("PARTIAL", "partial"),
      makeEntry("START_EXTEND", "extend"),
      makeEntry("END_EXTEND", "endextend"),
      makeEntry("MAGIC", ".")
    ];
  }
979004
public final void ruleOpOr() throws RecognitionException {

        		int stackSize = keepStackSize();
        	
        try {
            // InternalXbase.g:196:2: ( ( '||' ) )
            // InternalXbase.g:197:2: ( '||' )
            {
            // InternalXbase.g:197:2: ( '||' )
            // InternalXbase.g:198:3: '||'
            {
            if ( state.backtracking==0 ) {
               before(grammarAccess.getOpOrAccess().getVerticalLineVerticalLineKeyword()); 
            }
            match(input,14,FOLLOW_2); if (state.failed) return ;
            if ( state.backtracking==0 ) {
               after(grammarAccess.getOpOrAccess().getVerticalLineVerticalLineKeyword()); 
            }

            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {

            	restoreStackSize(stackSize);

        }
        return ;
    }
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;
	}
313921
private function doTransitionFromG() : self
    {
        if ($this->getToken() === Grammar::T_N) {
            $this
                ->setState(self::STATE_Y)
                ->addPosition(1);
            return $this;
        }

        if ($this->getToken() === Grammar::T_M) {
            $this
                ->setState(self::STATE_G)
                ->addPosition(1)
                ->addTokenValue(Grammar::T_M);
            return $this;
        }

        $this->setState(self::STATE_F);
        return $this;
    }
57505
function Rule (subrules, type, handler, props, groupProps, encoding) {
  var self = this
  var n = subrules.length

  this.props = props

  this.debug = false

  // Used for cloning
  this.subrules = subrules

  // Required by Atok#_resolveRules
  for (var p in groupProps)
    this[p] = groupProps[p]

  // Runtime values for continue props
  this.continue = this.props.continue[0]
  this.continueOnFail = this.props.continue[1]

  this.type = type
  this.handler = handler

  // For debug
  this.prevHandler = null
  this.id = this.type !== null ? this.type : handler
  // Id for debug
  this._id = (handler !== null ? (handler.name || '#emit()') : this.type)

  // Subrule pattern index that matched (-1 if only 1 pattern)
  this.idx = -1

  // Single subrule: special case for trimRight
  this.single = (n === 1)

  // First subrule
  var subrule = this.first = n > 0
    ? SubRule.firstSubRule( subrules[0], this.props, encoding, this.single )
    // Special case: no rule given -> passthrough
    : SubRule.emptySubRule

  // Special case: one empty rule -> tokenize whole buffer
  if (n === 1 && subrule.length === 0) {
    subrule = this.first = SubRule.allSubRule
    // Make infinite loop detection ignore this
    this.length = -1
  } else {
    // First subrule pattern length (max of all patterns if many)
    // - used in infinite loop detection
    this.length = this.first.length
  }

  // Instantiate and link the subrules
  // { test: {Function}
  // , next: {SubRule|undefined}
  // }
  var prev = subrule
  // Many subrules or none
  for (var i = 1; i < n; i++) {
    subrule = SubRule.SubRule( subrules[i], this.props, encoding )
    prev.next = subrule
    subrule.prev = prev // Useful in some edge cases
    prev = subrule
    if (this.length < subrule.length) this.length = subrule.length
  }

  // Last subrule (used for trimRight and matched idx)
  this.last = subrule

  // Set the first and last subrules length based on trim properties
  if (!this.props.trimLeft) this.first.length = 0
  if (!this.single && !this.props.trimRight) this.last.length = 0

  this.next = null
  this.nextFail = null
  this.currentRule = null
}
796295
public static final void parseSentence(final int[] sent, final CnfGrammar grammar, final LoopOrder loopOrder, final Chart chart, final Scorer scorer) {
        // Apply lexical rules to each word.
        for (int i = 0; i <= sent.length - 1; i++) {
            ChartCell cell = chart.getCell(i, i+1);
            for (final Rule r : grammar.getLexicalRulesWithChild(sent[i])) {
                double score = scorer.score(r, i, i+1, i+1);
                cell.updateCell(r.getParent(), score, i+1, r);
            }
        }
        
        // For each cell in the chart. (width increasing)
        for (int width = 1; width <= sent.length; width++) {
            for (int start = 0; start <= sent.length - width; start++) {
                int end = start + width;
                ChartCell cell = chart.getCell(start, end);
                
                // Apply binary rules.
                if (loopOrder == LoopOrder.CARTESIAN_PRODUCT) {
                    processCellCartesianProduct(grammar, chart, start, end, cell, scorer);
                } else if (loopOrder == LoopOrder.LEFT_CHILD) {
                    processCellLeftChild(grammar, chart, start, end, cell, scorer);
                } else if (loopOrder == LoopOrder.RIGHT_CHILD) {
                    processCellRightChild(grammar, chart, start, end, cell, scorer);
                } else {
                    throw new RuntimeException("Not implemented: " + loopOrder);
                }
                
                processCellUnaryRules(grammar, start, end, cell, scorer);
                if (width == sent.length) {
                    processCellUnaryRules(grammar, start, end, cell, scorer);
                }
                
                cell.close();
            }
        }
    
    }
472619
public function analyze(): iterable
    {
        if (\count($this->rules) === 0) {
            throw new GrammarException('No rules specified');
        }

        $this->parsedRules = [];

        foreach ($this->rules as $delegate) {
            $this->ruleName = $delegate->getRuleName();
            $nodeId = $delegate->isKept()
                ? $delegate->getRuleName()
                : null;

            $pNodeId = $nodeId;
            $rule = $this->rule($delegate->getInnerTokens(), $pNodeId);

            if ($rule === null) {
                $error = \sprintf('Error while parsing rule %s.', $delegate->getRuleName());
                throw new GrammarException($error, 1);
            }

            $zeRule = $this->parsedRules[$rule];
            $zeRule->setName($delegate->getRuleName());

            if ($nodeId !== null) {
                $zeRule->setDefaultId($nodeId);
            }

            unset($this->parsedRules[$rule]);
            $this->parsedRules[$delegate->getRuleName()] = $zeRule;
        }

        foreach ($this->parsedRules as $builder) {
            yield $builder->build();
        }
    }
1072863
public final void ruleXTypeLiteral() throws RecognitionException {

        		int stackSize = keepStackSize();
        	
        try {
            // InternalXbase.g:1396:2: ( ( ( rule__XTypeLiteral__Group__0 ) ) )
            // InternalXbase.g:1397:2: ( ( rule__XTypeLiteral__Group__0 ) )
            {
            // InternalXbase.g:1397:2: ( ( rule__XTypeLiteral__Group__0 ) )
            // InternalXbase.g:1398:3: ( rule__XTypeLiteral__Group__0 )
            {
            if ( state.backtracking==0 ) {
               before(grammarAccess.getXTypeLiteralAccess().getGroup()); 
            }
            // InternalXbase.g:1399:3: ( rule__XTypeLiteral__Group__0 )
            // InternalXbase.g:1399:4: rule__XTypeLiteral__Group__0
            {
            pushFollow(FOLLOW_2);
            rule__XTypeLiteral__Group__0();

            state._fsp--;
            if (state.failed) return ;

            }

            if ( state.backtracking==0 ) {
               after(grammarAccess.getXTypeLiteralAccess().getGroup()); 
            }

            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {

            	restoreStackSize(stackSize);

        }
        return ;
    }
997923
def dump_grammar(self, out=sys.stdout):
        
        for rule in sorted(self.rule2name.items()):
            out.write("%s\n" % rule2str(rule[0]))
        return
1001465
private function validateDeterministic(Grammar $grammar): void
    {
        /** @var Item[] */
        $finite = [];
        $terminals = [];
        $non_terminals = [];
        foreach ($this->items as $item) {
            $next_symbol = $item->getExpected();
            if (!$next_symbol) {
                $finite[] = $item;
            } elseif ($next_symbol->isTerminal()) {
                $terminals[] = $item;
            } else {
                $non_terminals[] = $item;
            }
        }

        $this->validateDeterministicShiftReduce(
            $finite,
            $terminals,
            $non_terminals,
            $grammar
        );
        $this->validateDeterministicReduceReduce($finite);
    }
1030560
function dump( Lex $Lex, Grammar $Grammar, $state = null ){
		$table = array();
		$heads = array( '' => 0 );
		// translate cell data and get other meta data
		foreach( $this->table as $i => $row ){
			if( ! is_null($state) && $i !== $state ){
				continue;
			}
			$table[$i] = array();
			// create row header
			$table[$i][''] = "#$i";
			$heads[''] = max( $heads[''], strlen($table[$i]['']) );
			// iterate over cols in this row
			foreach( $row as $sym => $entry ){
				if( is_null($sym) ){
					$sym = 'null';
				}
				else{
					$sym = $Lex->name($sym);
				}
				// rules are event, states are odd
				if( $entry & 1 ){
					$str = " #$entry ";
				}
				else {
					list( $nt, $rhs ) = $Grammar->get_rule( $entry );
					$str = ' '.$Lex->name($nt).' -> ';
					foreach( $rhs as $t ){
						$str .= $Lex->name($t).' ';
					}
				}
				// insert cell
				$table[$i][$sym] = $str;
				// collect known column header with max cell width in column
				if( !isset($heads[$sym]) ){
					$heads[$sym] = strlen($sym);
				}
				$heads[$sym] = max( $heads[$sym], strlen($str) );
			}
		}
		// print all headers
		$a = array();
		$b = array();
		foreach( $heads as $sym => $len ){
			$b[] = str_repeat( '-', $len );
			$a[] = str_pad( $sym, $len, ' ', STR_PAD_BOTH );
		}
		echo '+', implode('+', $b ), "+\n";
		echo '|', implode('|', $a ), "|\n";
		foreach( $table as $i => $row ){
			$c = array();
			foreach( $heads as $sym => $len ){
				if( isset($table[$i][$sym]) ){
					$c[] = str_pad( $row[$sym], $len, ' ', STR_PAD_BOTH );
				}
				else {
					$c[] = str_repeat(' ', $len );
				}
			}
			echo '+', implode('+', $b ), "+\n";
			echo '|', implode('|', $c ), "|\n";
		}
		echo '+', implode('+', $b ), "+\n";
	}