How to use the pyquil._parser.gen3.QuilParser.QuilParser function in pyquil

To help you get started, we’ve selected a few pyquil examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rigetti / pyquil / pyquil / _parser / gen3 / QuilParser.py View on Github external
def addr(self):

        localctx = QuilParser.AddrContext(self, self._ctx, self.state)
        self.enterRule(localctx, 36, self.RULE_addr)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 262
            self.match(QuilParser.LBRACKET)
            self.state = 263
            self.classicalBit()
            self.state = 264
            self.match(QuilParser.RBRACKET)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx
github rigetti / pyquil / pyquil / _parser / PyQuilListener.py View on Github external
return _binary_exp(expression, operator.truediv)
    elif isinstance(expression, QuilParser.AddSubExpContext):
        if expression.PLUS():
            return _binary_exp(expression, operator.add)
        elif expression.MINUS():
            return _binary_exp(expression, operator.sub)
    elif isinstance(expression, QuilParser.SignedExpContext):
        if expression.sign().PLUS():
            return _expression(expression.expression())
        elif expression.sign().MINUS():
            return -1 * _expression(expression.expression())
    elif isinstance(expression, QuilParser.FunctionExpContext):
        return _apply_function(expression.function(), _expression(expression.expression()))
    elif isinstance(expression, QuilParser.AddrExpContext):
        return _addr(expression.addr())
    elif isinstance(expression, QuilParser.NumberExpContext):
        return _number(expression.number())
    elif isinstance(expression, QuilParser.VariableExpContext):
        return _variable(expression.variable())

    raise RuntimeError("Unexpected expression type:" + expression.getText())
github rigetti / pyquil / pyquil / _parser / gen3 / QuilParser.py View on Github external
def realN(self):

        localctx = QuilParser.RealNContext(self, self._ctx, self.state)
        self.enterRule(localctx, 80, self.RULE_realN)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 370
            _la = self._input.LA(1)
            if not(_la==QuilParser.INT or _la==QuilParser.FLOAT):
                self._errHandler.recoverInline(self)
            else:
                self._errHandler.reportMatch(self)
                self.consume()
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
github rigetti / pyquil / pyquil / _parser / gen3 / QuilParser.py View on Github external
def getRuleIndex(self):
            return QuilParser.RULE_quil
github rigetti / pyquil / pyquil / _parser / gen3 / QuilParser.py View on Github external
def defGate(self):
            return self.getTypedRuleContext(QuilParser.DefGateContext,0)
github rigetti / pyquil / pyquil / _parser / gen3 / QuilParser.py View on Github external
def imaginaryN(self):

        localctx = QuilParser.ImaginaryNContext(self, self._ctx, self.state)
        self.enterRule(localctx, 78, self.RULE_imaginaryN)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 367
            self.realN()
            self.state = 368
            self.match(QuilParser.I)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx
github rigetti / pyquil / pyquil / _parser / gen3 / QuilParser.py View on Github external
def TAB(self, i:int=None):
            if i is None:
                return self.getTokens(QuilParser.TAB)
            else:
                return self.getToken(QuilParser.TAB, i)
github rigetti / pyquil / pyquil / _parser / gen3 / QuilParser.py View on Github external
def quil(self):

        localctx = QuilParser.QuilContext(self, self._ctx, self.state)
        self.enterRule(localctx, 0, self.RULE_quil)
        self._la = 0 # Token type
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 83
            self._errHandler.sync(self)
            _la = self._input.LA(1)
            if (((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << QuilParser.DEFGATE) | (1 << QuilParser.DEFCIRCUIT) | (1 << QuilParser.MEASURE) | (1 << QuilParser.LABEL) | (1 << QuilParser.HALT) | (1 << QuilParser.JUMP) | (1 << QuilParser.JUMPWHEN) | (1 << QuilParser.JUMPUNLESS) | (1 << QuilParser.RESET) | (1 << QuilParser.WAIT) | (1 << QuilParser.NOP) | (1 << QuilParser.INCLUDE) | (1 << QuilParser.PRAGMA) | (1 << QuilParser.FALSE) | (1 << QuilParser.TRUE) | (1 << QuilParser.NOT) | (1 << QuilParser.AND) | (1 << QuilParser.OR) | (1 << QuilParser.MOVE) | (1 << QuilParser.EXCHANGE) | (1 << QuilParser.IDENTIFIER))) != 0):
                self.state = 82
                self.allInstr()


            self.state = 93
            self._errHandler.sync(self)
            _alt = self._interp.adaptivePredict(self._input,2,self._ctx)
            while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
                if _alt==1:
                    self.state = 86 
                    self._errHandler.sync(self)
                    _la = self._input.LA(1)
                    while True:
                        self.state = 85
                        self.match(QuilParser.NEWLINE)
                        self.state = 88
github rigetti / pyquil / pyquil / _parser / gen3 / QuilParser.py View on Github external
def param(self):

        localctx = QuilParser.ParamContext(self, self._ctx, self.state)
        self.enterRule(localctx, 12, self.RULE_param)
        try:
            self.enterOuterAlt(localctx, 1)
            self.state = 148
            self.expression(0)
        except RecognitionException as re:
            localctx.exception = re
            self._errHandler.reportError(self, re)
            self._errHandler.recover(self, re)
        finally:
            self.exitRule()
        return localctx
github rigetti / pyquil / pyquil / _parser / PyQuilListener.py View on Github external
elif isinstance(expression, QuilParser.MulDivExpContext):
        if expression.TIMES():
            return _binary_exp(expression, operator.mul)
        elif expression.DIVIDE():
            return _binary_exp(expression, operator.truediv)
    elif isinstance(expression, QuilParser.AddSubExpContext):
        if expression.PLUS():
            return _binary_exp(expression, operator.add)
        elif expression.MINUS():
            return _binary_exp(expression, operator.sub)
    elif isinstance(expression, QuilParser.SignedExpContext):
        if expression.sign().PLUS():
            return _expression(expression.expression())
        elif expression.sign().MINUS():
            return -1 * _expression(expression.expression())
    elif isinstance(expression, QuilParser.FunctionExpContext):
        return _apply_function(expression.function(), _expression(expression.expression()))
    elif isinstance(expression, QuilParser.AddrExpContext):
        return _addr(expression.addr())
    elif isinstance(expression, QuilParser.NumberExpContext):
        return _number(expression.number())
    elif isinstance(expression, QuilParser.VariableExpContext):
        return _variable(expression.variable())

    raise RuntimeError("Unexpected expression type:" + expression.getText())