Exemplo n.º 1
0
    def ActID(self,value,reg=False):
        if __debug__:
            if reg:
                assert isinstance(value,lexer.Type) or \
                isinstance(value,lexer.Unrecognized), \
                    "%s 'value' argument must be an instance of lexer.Type: %s" \
                        % (fsm.eloc(self,"ActID",module=this_module),value)
            else:
                assert isinstance(value,lexer.Token),\
                    "%s 'value' argument must be an instance of lexer.Token: %s" \
                        % (fsm.eloc(self,"ActID",module=this_module))

        return value.tid
Exemplo n.º 2
0
    def ActID(self,value,reg=False):
        if __debug__:
            if reg:
                assert isinstance(value,lexer.Type) or \
                isinstance(value,lexer.Unrecognized), \
                    "%s 'value' argument must be an instance of lexer.Type: %s" \
                        % (fsm.eloc(self,"ActID",module=this_module),value)
            else:
                assert isinstance(value,lexer.Token),\
                    "%s 'value' argument must be an instance of lexer.Token: %s" \
                        % (fsm.eloc(self,"ActID",module=this_module))

        return value.tid
Exemplo n.º 3
0
    def unstack(self,trace=None):
        assert len(self._stack)>0,"%s stack is empty" \
            % fsm.eloc(self,"unstack",module=this_module)
        assert self._unstacked is None,"%s ustacked token already queued for machine"\
            % fsm.eloc(self,"unstack",module=this_module)

        self._unstacked=self._stack.pop(-1)
        
        if __debug__:
            if trace is not None:
                print("FSM:%s [%s] token unstacked: %s" \
                    % (self.name,self.current(),token))

        return
Exemplo n.º 4
0
    def unstack(self,trace=False):
        assert len(self._stack)>0,"%s stack is empty" \
            % fsm.eloc(self,"unstack",module=this_module)
        assert self._unstacked is None,"%s ustacked token already queued for machine"\
            % fsm.eloc(self,"unstack",module=this_module)

        self._unstacked=self._stack.pop(-1)
        
        if __debug__:
            if trace:
                print("FSM:%s [%s] token unstacked: %s" \
                    % (self.name,self.current(),self._unstacked))

        return
Exemplo n.º 5
0
    def context(self,name,gscope=None,scope=None):
        if __debug__:
            if self._trace:
                print("FSM:%s [%s] context(name=%s,gscope=%s,scope=%s)" \
                    % (self.name,self.current(),name,gscope,scope))
        try:
            ctx=self.ctxs[name]
        except KeyError:
            raise ValueError("%s can not switch to an undefined parser context: %s" \
                % (fsm.eloc(self,"context",module=this_module),name)) from None

        if gscope:
            gs=gscope
        else:
            gs=self.scope()
        cs=self._init_cscope(ctx,scope)
        gs.cscope=cs

        if __debug__:
            if self._trace:
                print("FSM:%s [%s] global scope=%s" % (self.name,self.current(),gs))
                print("FSM:%s [%s] context scope=%s" % (self.name,self.current(),cs))
                print("FSM:%s [%s] new context '%s' using lexical context '%s'" \
                    % (self.name,self.current(),ctx.name,ctx.lexctx))

        self.lex.context(ctx.lexctx)   # Set the lexer context here too
        self.ctx_name=name             # Remember the parser context too
Exemplo n.º 6
0
    def context(self,name,gscope=None,scope=None,trace=False):
        if __debug__:
            if self._trace or trace:
                print("FSM:%s [%s] context(name=%s,gscope=%s,scope=%s)" \
                    % (self.name,self.current(),name,gscope,scope))
        try:
            ctx=self.ctxs[name]
        except KeyError:
            raise ValueError("%s can not switch to an undefined parser context: %s" \
                % (fsm.eloc(self,"context",module=this_module),name)) from None

        if __debug__:
            if self._trace:
                cs=None

        if not ctx.gbl:
            if gscope:
                gs=gscope
            else:
                gs=self.scope()
            cs=self._init_cscope(ctx,scope)
            gs.cscope=cs
        else:
            gs=gscope
            cs=None

        if __debug__:
            if self._trace:
                print("FSM:%s [%s] global scope=%s" % (self.name,self.current(),gs))
                print("FSM:%s [%s] context scope=%s" % (self.name,self.current(),cs))
                print("FSM:%s [%s] new context '%s' using lexical context '%s'" \
                    % (self.name,self.current(),ctx.name,ctx.lexctx))

        self.lex.context(ctx.lexctx)   # Set the lexer context here too
        self.ctx_name=name             # Remember the parser context too
Exemplo n.º 7
0
 def ctx(self,name,lexctx=None,ccls=None):
     ctxo=Context(name,lexctx=lexctx,ccls=ccls)
     try:
         self.ctxs[ctxo.name]
         raise ValueError("%s Context object already defined: %s" \
             % (fsm.eloc(self,"ctx",module=this_module),ctxo.name))
     except KeyError:
         pass
     self.ctxs[ctxo.name]=ctxo   
Exemplo n.º 8
0
 def ctx(self,name,lexctx=None,gbl=False,ccls=None):
     ctxo=Context(name,lexctx=lexctx,gbl=gbl,ccls=ccls)
     try:
         self.ctxs[ctxo.name]
         raise ValueError("%s Context object already defined: %s" \
             % (fsm.eloc(self,"ctx",module=this_module),ctxo.name))
     except KeyError:
         pass
     self.ctxs[ctxo.name]=ctxo   
Exemplo n.º 9
0
    def __init__(self,lex,scls=None,external=None,init="init",trace=False):
        super().__init__(trace=trace)
        assert isinstance(lex,(lexer.Lexer,lexer.CSLA)),\
            "%s 'lex' argument must be an instance of lexer.Lexer or lexer.CSLA: %s" \
                % (fsm.eloc(self,"__init__",module=this_module),lex)

        self.lex=lex              # Lexical analyzer used for parsing
        self.scopecls=scls        # Class to create for my scope
        self.external=external    # External assistance object
        self._stack=[]            # A holding place for potential look aheads
        self._unstacked=None      # Queued token from stack for input to FSM

        self.init(init)  # Establish FSM start state
Exemplo n.º 10
0
    def __init__(self,lex,scls=None,external=None,init="init",trace=False):
        super().__init__(trace=trace)
        assert isinstance(lex,(lexer.Lexer,lexer.CSLA)),\
            "%s 'lex' argument must be an instance of lexer.Lexer or lexer.CSLA: %s" \
                % (fsm.eloc(self,"__init__",module=this_module),lex)

        self.lex=lex              # Lexical analyzer used for parsing
        self.scopecls=scls        # Class to create for my scope
        self.external=external    # External assistance object
        self._stack=[]            # A holding place for potential look aheads
        self._scope_stack=[]      # Scope stack for pushing/popping scope
        self._unstacked=None      # Queued token from stack for input to FSM

        self.init(init)  # Establish FSM start state
Exemplo n.º 11
0
 def unstack(self,trace=None):
     cls_str="%s - %s.unstack():" % (this_module,self.__class__.__name__)
     raise NotImplementedError("%s unstack() method not supported" \
         % fsm.eloc(self,"unstack",module=this_module))
Exemplo n.º 12
0
 def stack(self,token,trace=None):
     raise NotImplementedError("%s stack() method not supported" \
         % fsm.eloc(self,"stack",module=this_module))
Exemplo n.º 13
0
 def unstack(self, trace=None):
     cls_str = "%s - %s.unstack():" % (this_module, self.__class__.__name__)
     raise NotImplementedError("%s unstack() method not supported" \
         % fsm.eloc(self,"unstack",module=this_module))
Exemplo n.º 14
0
 def stack(self, token, trace=None):
     raise NotImplementedError("%s stack() method not supported" \
         % fsm.eloc(self,"stack",module=this_module))