Created
July 22, 2015 12:06
-
-
Save sanxiyn/3ca529b458cd1c73d9aa to your computer and use it in GitHub Desktop.
Lexer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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