<s> """<STR_LIT>""" <EOL> import sys <EOL> import ellyChar <EOL> import ellyException <EOL> import featureSpecification <EOL> catid = { } <EOL> def scan ( strg ) : <EOL> """<STR_LIT>""" <EOL> n = <NUM_LIT:0> <EOL> for c in strg : <EOL> if c == '<STR_LIT:.>' or ellyChar . isLetterOrDigit ( c ) : n += <NUM_LIT:1> <EOL> else : break <EOL> else : <EOL> return n <EOL> c = strg [ n ] <EOL> if c == '<STR_LIT:U+0020>' : return n <EOL> if c != '<STR_LIT:[>' : return <NUM_LIT:0> <EOL> k = featureSpecification . scan ( strg [ n : ] ) <EOL> return n + k if k > <NUM_LIT:0> else <NUM_LIT:0> <EOL> class SyntaxSpecification ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , syms , spec ) : <EOL> """<STR_LIT>""" <EOL> self . catg = - <NUM_LIT:1> <EOL> self . synf = None <EOL> if spec == None : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> raise ellyException . FormatFailure <EOL> s = spec . lower ( ) <EOL> n = <NUM_LIT:0> <EOL> for c in s : <EOL> if not ellyChar . isLetterOrDigit ( c ) and c != '<STR_LIT:.>' : break <EOL> n += <NUM_LIT:1> <EOL> if n == <NUM_LIT:0> : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> raise ellyException . FormatFailure <EOL> typs = s [ : n ] <EOL> catg = syms . getSyntaxTypeIndexNumber ( typs ) <EOL> s = s [ n : ] . strip ( ) <EOL> if len ( s ) == <NUM_LIT:0> : <EOL> synf = featureSpecification . FeatureSpecification ( syms , None ) <EOL> elif typs == '<STR_LIT>' : <EOL> raise ellyException . FormatFailure <EOL> else : <EOL> if len ( s ) > <NUM_LIT:3> and typs in catid and catid [ typs ] != s [ <NUM_LIT:1> ] : <EOL> print >> sys . stderr , '<STR_LIT>' , typs . upper ( ) , '<STR_LIT>' , catid [ typs ] , s [ <NUM_LIT:1> ] <EOL> raise ellyException . FormatFailure <EOL> catid [ typs ] = s [ <NUM_LIT:1> ] <EOL> synf = featureSpecification . FeatureSpecification ( syms , s ) <EOL> self . catg = catg <EOL> self . synf = synf <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> fs = '<STR_LIT>' if self . synf == None else str ( self . synf ) <EOL> return '<STR_LIT>' + str ( self . catg ) + '<STR_LIT:U+0020>' + fs <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import symbolTable <EOL> stb = symbolTable . SymbolTable ( ) <EOL> stb . getSyntaxTypeIndexNumber ( '<STR_LIT>' ) <EOL> stb . getSyntaxTypeIndexNumber ( '<STR_LIT:end>' ) <EOL> stb . getSyntaxTypeIndexNumber ( '<STR_LIT>' ) <EOL> stb . getSyntaxTypeIndexNumber ( '<STR_LIT>' ) <EOL> spcl = sys . argv [ <NUM_LIT:1> : ] if len ( sys . argv ) > <NUM_LIT:1> else [ '<STR_LIT>' ] <EOL> for spc in spcl : <EOL> ns = scan ( spc ) <EOL> sx = spc [ : ns ] <EOL> print ns , '<STR_LIT>' <EOL> try : <EOL> ss = SyntaxSpecification ( stb , sx ) <EOL> except ellyException . FormatFailure : <EOL> print >> sys . stderr , '<STR_LIT>' , sx , '<STR_LIT:]>' <EOL> continue <EOL> print '<STR_LIT>' , sx , '<STR_LIT:=>' , ss </s>
