예제 #1
0
파일: parse.py 프로젝트: isidentical/oil
 def push(self, typ, opaque, newdfa, newstate):
     # type: (int, Token, dfa_t, int) -> None
     """Push a nonterminal.  (Internal)"""
     top = self.stack[-1]
     newnode = PNode(typ, opaque, [])
     self.stack[-1].state = newstate
     self.stack.append(_StackItem(newdfa, 0, newnode))
예제 #2
0
파일: parse.py 프로젝트: isidentical/oil
 def shift(self, typ, opaque, newstate):
     # type: (int, Token, int) -> None
     """Shift a token.  (Internal)"""
     top = self.stack[-1]
     newnode = PNode(typ, opaque, None)
     top.node.children.append(newnode)
     self.stack[-1].state = newstate
예제 #3
0
파일: parse.py 프로젝트: isidentical/oil
    def setup(self, start):
        # type: (int) -> None
        """Prepare for parsing.

        This *must* be called before starting to parse.

        The optional argument is an alternative start symbol; it
        defaults to the grammar's start symbol.

        You can use a Parser instance to parse any number of programs;
        each time you call setup() the parser is reset to an initial
        state determined by the (implicit or explicit) start symbol.
        """
        newnode = PNode(start, None, [])
        # Each stack entry is a tuple: (dfa, state, node).
        self.stack = [_StackItem(self.grammar.dfas[start], 0, newnode)]
        self.rootnode = None  # type: Optional[PNode]