예제 #1
0
 def compileItem(self):
     c = self.readToken()
     startPosition = self.tokenStartIndex
     if c == '(':
         fsa = self.compileExpr()
         if self.readToken() != ')':
             raise ParseError("unmatched '('", startPosition)
     elif c == '~':
         fsa = FSA.complement(self.compileItem())
     else:
         positions = None
         if self.recordSourcePositions:
             positions = range(startPosition, self.index)
         fsa = FSA.singleton(c, arcMetadata=positions)
     while self.peekChar() and self.peekChar() in '?*+':
         c = self.readChar()
         if c == '*':
             fsa = FSA.closure(fsa)
         elif c == '?':
             fsa = FSA.union(fsa, FSA.EMPTY_STRING_FSA)
         elif c == '+':
             fsa = FSA.iteration(fsa)
         else:
             raise 'program error'
     return fsa
예제 #2
0
 def compileItem(self):
     startPosition = self.index
     c = self.readToken()
     if c == '(':
         fsa = self.compileExpr()
         if self.readToken() != ')':
             raise "missing ')'"
     elif c == '~':
         fsa = FSA.complement(self.compileItem())
     else:
         fsa = FSA.singleton(c, arcMetadata=self.recordSourcePositions and [startPosition])
     while self.peekChar() and self.peekChar() in '?*+':
         c = self.readChar()
         if c == '*':
             fsa = FSA.closure(fsa)
         elif c == '?':
             fsa = FSA.union(fsa, FSA.EMPTY_STRING_FSA)
         elif c == '+':
             fsa = FSA.iteration(fsa)
         else:
             raise 'program error'
     return fsa
예제 #3
0
 def compileItem(self):
     startPosition = self.index
     c = self.readToken()
     if c == '(':
         fsa = self.compileExpr()
         if self.readToken() != ')':
             raise "missing ')'"
     elif c == '~':
         fsa = FSA.complement(self.compileItem())
     else:
         fsa = FSA.singleton(c,
                             arcMetadata=self.recordSourcePositions
                             and [startPosition])
     while self.peekChar() and self.peekChar() in '?*+':
         c = self.readChar()
         if c == '*':
             fsa = FSA.closure(fsa)
         elif c == '?':
             fsa = FSA.union(fsa, FSA.EMPTY_STRING_FSA)
         elif c == '+':
             fsa = FSA.iteration(fsa)
         else:
             raise 'program error'
     return fsa
예제 #4
0
import FSA

guard = FSA.singleton("Pass Guard" 
, "There is a guard blocking your entrance")

leave = FSA.singleton("Leave Main Area"
, "Go past the guard, who's asleep")

office = FSA.singleton("To office"
, "There's a door to an office")

exitoffice = FSA.singleton("Leave office"
, "Back to the entrance")

seePlane = FSA.singleton("To plane"
, "In the office, you see a plane")

leavePlane = FSA.singleton("Leave plane"
, "Back to the office")

test = FSA.minimize((FSA.closure (FSA.concatenation (seePlane,leavePlane) ) ))
test2 = FSA.minimize(FSA.preInterleave(everything,test))

entrance = FSA.minimize(FSA.concatenation(leave, guard))
everything = FSA.minimize(FSA.closure(FSA.concatenation(guard,(FSA.closure(FSA.preinterleave(test, (FSA.concatenation(office, exitoffice)))), leave)))


#everything.view()
test2.view()

예제 #5
0
# Example.py
# 20070920 LHK: created

# load the FSA module
import FSA

# Create two basic FSAs with labels 'a' and 'b' ...
a = FSA.singleton('a')
b = FSA.singleton('b')

# ... combine them through concatenation ...
ab = FSA.concatenation(a,b)

# ... and add a Kleene star!
ab_star = FSA.closure(ab)

#########################################
##   Please note that ab_star models   ##
##   the following regular expression: ##
##                                     ##
##          (a b)*                     ##
#########################################

# Now show 'a' ...
raw_input('Please press <enter> to see "a"')
a.view()

# ... show 'b' ...
raw_input('Please press <enter> to see "b"')
b.view()
예제 #6
0
# intro.py

#load the FSA module
import FSA

#Create Appleton A and Appleton B -- Question 1
a = FSA.singleton('Enter AT')
b = FSA.singleton('Leave AT')

ba = FSA.concatenation(b,a)
ab_star = FSA.closure(ba)
at_door = FSA.concatenation(a,ab_star)

min_at_door = FSA.minimize(at_door)
#min_at_door.view()

show1 = min_at_door.checkQ1()
#print(show1)

#Coffee_and_Notes -- Question 2
c = FSA.singleton('Pick up lecture notes')
d = FSA.singleton('Return lecture notes')
e = FSA.singleton('Have a coffee')

cd = FSA.concatenation(c,d)
cd_star = FSA.closure(cd)
e_star = FSA.closure(e)

coffee = FSA.concatenation(e_star, c)
dcoffee = FSA.concatenation(d,coffee)
예제 #7
0
"""Module PatternScanner -- methods that construct grammars, and that use them
예제 #8
0
"""Module PatternScanner -- methods that construct grammars, and that use them
예제 #9
0
exitoffice = FSA.singleton("Leave office"
, "Back to the entrance")

seePlane = FSA.singleton("To plane"
, "In the office, you see a plane")

leavePlane = FSA.singleton("Leave plane"
, "Back to the office")

inspectPlane = FSA.singleton("Inspect plane"
, "You need a key to operate this")

askGuard = FSA.singleton("Ask Guard a question"
, "There is a key in the office...snore...")

takeKey = FSA.singleton("Take the key"
, "You thief!")

flyPlane = FSA.singleton("Fly the plane"
, "Whoosh!")

test = FSA.minimize(FSA.closure( 

level1 = FSA.minimize(FSA.closure(FSA.concatenation(FSA.closure(askGuard),guard,(FSA.closure(FSA.concatenation(FSA.closure(FSA.concatenation(office,exitoffice)), office, FSA.concatenation( FSA.closure(FSA.concatenation(seePlane,FSA.closure(inspectPlane), leavePlane, ))), FSA.preInterleave(takeKey, FSA.concatenation( (FSA.closure(FSA.concatenation(seePlane,FSA.closure(inspectPlane), leavePlane, ))), exitoffice))))), leave)))

levelb = FSA.minimize(FSA.closure(FSA.concatenation(FSA.closure(askGuard),guard,(FSA.closure(FSA.concatenation(FSA.closure(FSA.concatenation(office,exitoffice)), office, FSA.preInterleave(takeKey, FSA.concatenation( (FSA.closure(FSA.concatenation(seePlane,FSA.closure(inspectPlane), leavePlane, ))), exitoffice)), FSA.concatenation( FSA.closure(FSA.concatenation(seePlane,FSA.closure(inspectPlane), leavePlane, )))))), leave)))


level1.view()
#levelb.view()