Beispiel #1
0
def get_keyword(s):
    machine = char(s[0])
    for a in s[1:]:
        machine = concat(machine, char(a))
    return machine
Beispiel #2
0
def get_char():
    quote = char("'")
    quote2 = char("'")
    inside = char(ANYBUTSINGLEQUOTE)
    return concat(quote, concat(inside, quote2))
Beispiel #3
0
def get_string():
    quote = char('"')
    quote2 = char('"')
    inside = star(char(ANYBUTQUOTE))
    return concat(quote, concat(inside, quote2))
Beispiel #4
0
def get_number():
    dmachine = char(DIGIT)
    dmachine2 = char(DIGIT)
    return concat(dmachine, star(dmachine2))
Beispiel #5
0
def get_ident():
    lmachine = char(LETTER)
    lodmachine = char(LOD)
    return concat(lmachine, star(lodmachine))
Beispiel #6
0
                    current += 1
                    # accepting? if so, for what token?
                    isAccepting = False
                    for state in closure:
                        if state.accepting:
                            isAccepting = True
                            token = state.pertenency
                    visited[current] = State(name=current,
                                             accepting=isAccepting,
                                             pertenency=token)
                    Dstates.append(closure)
                    # add trans symbol, current
                    visited[index].addTransition(symbol, visited[current])
                else:
                    transition = Dstates.index(closure)
                    visited[index].addTransition(symbol, visited[transition])

        self.table = visited
        self.reset()


if __name__ == "__main__":
    scanner = ScannerTable(['a', 'b', 'c'])
    a = char('a')
    a.name = 'a'
    b = char('b')
    b.name = 'b'
    c = char('c')
    c.name = 'c'
    scanner.build([a, b, c])
    print(scanner.move('a'))