Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_char():
- global character_class
- global next_char
- global fp
- next_char = fp.read(1)
- if next_char.isalpha():
- character_class = LETTER
- elif next_char.isdigit():
- character_class = DIGIT
- else:
- character_class = UNKNOWN
- def get_non_blank():
- while next_char.isspace():
- get_char()
- # Constants
- # Character Classes
- LETTER = 0
- DIGIT = 0
- UNKNOWN = 99
- # Token Codes
- INT_LIT = 10
- IDENT = 11
- ASSIGN_OP = 20
- ADD_OP = 21
- SUB_OP = 22
- MULT_OP = 23
- DIV_OP = 24
- LEFT_PAREN = 25
- RIGHT_PAREN = 26
- # Initialize Global Variables
- character_class = -1
- lexeme = -1
- next_char = -1
- lex_length = -1
- token = -1
- next_token = -1
- # Get the name of the input file from the user.
- file_name = input("Input file name: ")
- # Open the file and read the first char.
- # NOTE: error handling needs to be added later.
- try:
- with open(file_name, "r") as fp:
- get_char()
- while next_char:
- print(next_char)
- get_non_blank()
- except OSError:
- print("Unable to open file")
- quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement