def main(sourceText): global f f = open(outputFilename, "w") writeln("Here are the characters returned by the scanner:") writeln(" line col character") Scanner.initialize(sourceText) character = Scanner.get() while True: writeln(character) if character.cargo == Scanner.ENDMARK: break character = Scanner.get() f.close()
def getChar(): """ get the next character """ global c1, c2, character character = scanner.get() c1 = character.cargo #--------------------------------------------------------------- # Every time we get a character from the scanner, we also # lookahead to the next character and save the results in c2. # This makes it easy to lookahead 2 characters. #--------------------------------------------------------------- c2 = c1 + scanner.lookahead(1)
def main(sourceText): global f f = open(outputFilename, "w") # open the ouput file writeln("Here are the characters returned by the scanner:") writeln(" line col character") # create a scanner (an instance of the Scanner class) scanner.initialize(sourceText) #------------------------------------------------------------------ # Call the scanner's get() method repeatedly # to get the characters in the sourceText. # Stop when we reach the ENDMARK. #------------------------------------------------------------------ character = scanner.get() # getfirst Character object from the scanner while True: writeln(character) if character.cargo == scanner.ENDMARK: break character = scanner.get() # getnext f.close() # close the output file
def main(sourceText): global f f = open(outputFilename, "w") # open the ouput file #fragment start core writeln("Here are the characters returned by the scanner:") writeln(" line col character") # create a scanner (an instance of the Scanner class) scanner.initialize(sourceText) #------------------------------------------------------------------ # Call the scanner's get() method repeatedly # to get the characters in the sourceText. # Stop when we reach the ENDMARK. #------------------------------------------------------------------ character = scanner.get() # getfirst Character object from the scanner while True: writeln(character) if character.cargo == scanner.ENDMARK: break character = scanner.get() # getnext #fragment stop core f.close() # close the output file