Skip to content

Instantly share code, notes, and snippets.

@sanxiyn
Created July 22, 2015 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanxiyn/3ca529b458cd1c73d9aa to your computer and use it in GitHub Desktop.
Save sanxiyn/3ca529b458cd1c73d9aa to your computer and use it in GitHub Desktop.
Lexer
string = '''
interface NamedEntity {
name: String
}
'''
state = 0
index = 0
for position in range(len(string)):
character = string[position]
if state == 0:
if 'A' <= character <= 'Z' or 'a' <= character <= 'z':
state = 1
index = position
elif character == ' ' or character == '\n':
pass
else:
state = 2
index = position
elif state == 1:
if 'A' <= character <= 'Z' or 'a' <= character <= 'z':
pass
elif character == ' ' or character == '\n':
print string[index:position]
state = 0
else:
print string[index:position]
state = 2
index = position
else:
if 'A' <= character <= 'Z' or 'a' <= character <= 'z':
print string[index:position]
state = 1
index = position
elif character == ' ' or character == '\n':
print string[index:position]
state = 0
else:
print string[index:position]
state = 2
index = position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment