Ejemplo n.º 1
0
  /**
   * Get the precedence level for the top-most precedence rule.
   *
   * @return The precedence level for the top-most precedence rule, or -1 if the parser context is
   *     not nested within a precedence rule.
   */
  public final int getPrecedence() {
    if (_precedenceStack.isEmpty()) {
      return -1;
    }

    return _precedenceStack.peek();
  }
Ejemplo n.º 2
0
 /** reset the parser's state */
 public void reset() {
   if (getInputStream() != null) getInputStream().seek(0);
   _errHandler.reset(this);
   _ctx = null;
   _syntaxErrors = 0;
   matchedEOF = false;
   setTrace(false);
   _precedenceStack.clear();
   _precedenceStack.push(0);
   ATNSimulator interpreter = getInterpreter();
   if (interpreter != null) {
     interpreter.reset();
   }
 }
Ejemplo n.º 3
0
 public void enterRecursionRule(
     ParserRuleContext localctx, int state, int ruleIndex, int precedence) {
   setState(state);
   _precedenceStack.push(precedence);
   _ctx = localctx;
   _ctx.start = _input.LT(1);
   if (_parseListeners != null) {
     triggerEnterRuleEvent(); // simulates rule entry for left-recursive rules
   }
 }
Ejemplo n.º 4
0
  public void unrollRecursionContexts(ParserRuleContext _parentctx) {
    _precedenceStack.pop();
    _ctx.stop = _input.LT(-1);
    ParserRuleContext retctx = _ctx; // save current ctx (return value)

    // unroll so _ctx is as it was before call to recursive method
    if (_parseListeners != null) {
      while (_ctx != _parentctx) {
        triggerExitRuleEvent();
        _ctx = (ParserRuleContext) _ctx.parent;
      }
    } else {
      _ctx = _parentctx;
    }

    // hook into tree
    retctx.parent = _parentctx;

    if (_buildParseTrees && _parentctx != null) {
      // add return ctx into invoking rule's tree
      _parentctx.addChild(retctx);
    }
  }
Ejemplo n.º 5
0
 @Override
 public boolean precpred(RuleContext localctx, int precedence) {
   return precedence >= _precedenceStack.peek();
 }
Ejemplo n.º 6
0
 {
   _precedenceStack = new IntegerStack();
   _precedenceStack.push(0);
 }