Skip to content
Snippets Groups Projects
Commit eb475e4a authored by pycsham's avatar pycsham
Browse files

Added length 2 and 3 seperators transitions. added set for keywords that are...

Added length 2 and 3 seperators transitions. added set for keywords that are in java but not joos. removed and added some keywords
parent 759e89fb
No related branches found
No related tags found
No related merge requests found
...@@ -34,13 +34,13 @@ idToTokenDict = dict({ ...@@ -34,13 +34,13 @@ idToTokenDict = dict({
'instaceof': 'INSTANCEOF', 'instaceof': 'INSTANCEOF',
'int': 'INT', 'int': 'INT',
'native': 'NATIVE', 'native': 'NATIVE',
'new': 'NEW',
'package': 'PACKAGE', 'package': 'PACKAGE',
'protected': 'PROTECTED', 'protected': 'PROTECTED',
'public': 'PUBLIC', 'public': 'PUBLIC',
'return': 'RETURN', 'return': 'RETURN',
'short': 'SHORT', 'short': 'SHORT',
'static': 'STATIC', 'static': 'STATIC',
'String': 'STRING',
'this': 'THIS', 'this': 'THIS',
'void': 'VOID', 'void': 'VOID',
'while': 'WHILE', 'while': 'WHILE',
...@@ -57,6 +57,38 @@ def idsToTokens(tokens): ...@@ -57,6 +57,38 @@ def idsToTokens(tokens):
if t.lex in idToTokenDict: if t.lex in idToTokenDict:
t.name = idToTokenDict.get(t.lex) t.name = idToTokenDict.get(t.lex)
# a set that contains keywords that are in java but not in joos
wrongKeyWordDict = set(
'assert',
'break',
'case',
'catch',
'const',
'continue',
'default',
'do',
'double',
'enum',
'finally',
'float',
'goto',
'interface',
'long',
'new',
'private',
'strictfp',
'super',
'switch',
'synchronized',
'throw',
'throws',
'transient',
'try',
'volatile'
)
######################## DFA Stuff ################################### ######################## DFA Stuff ###################################
################# Joos DFA Tokens ################################### ################# Joos DFA Tokens ###################################
...@@ -77,7 +109,6 @@ JoosDFATokens = set([ ...@@ -77,7 +109,6 @@ JoosDFATokens = set([
'GT', # > 'GT', # >
'LT', # < 'LT', # <
'NOT', # ! 'NOT', # !
'TILDE', # ~
'QUESTION', # ? 'QUESTION', # ?
'COLON', # : 'COLON', # :
'ARROW', # -> 'ARROW', # ->
...@@ -143,8 +174,6 @@ def JoosTransition(input, state): ...@@ -143,8 +174,6 @@ def JoosTransition(input, state):
return 'LT' return 'LT'
if (input == '!'): if (input == '!'):
return 'NOT' return 'NOT'
if (input == '~'):
return 'TILDE'
if (input == '?'): if (input == '?'):
return 'QUESTION' return 'QUESTION'
if (input == ':'): if (input == ':'):
...@@ -250,15 +279,28 @@ def JoosTransition(input, state): ...@@ -250,15 +279,28 @@ def JoosTransition(input, state):
if (input == '|'): if (input == '|'):
return 'OR' return 'OR'
return None return None
# length 2/3 seperators
elif(state == 'COLON'):
if (input == ':'):
return 'DOUBLECO'
return None
elif(state == 'PERIOD'):
if(input == '.'):
return 'PERIOD2'
return None
elif(state == 'PERIOD2'):
if(input == '.'):
return 'ELLIPSIS'
return None
else: else:
return None return None
##################### Other DFA elements ############################## ##################### Other DFA elements ##############################
#TODO: add operand and separator characters to alphabet #TODO: add operand and separator characters to alphabet
specialChars = set(list(".;:,@{}()[]<>!?~+-*/&|^%=''\"\\")) specialChars = set(list(".;:,@{}()[]<>!?+-*/&|^%=''\"\\"))
JoosAccept = JoosDFATokens.union({'WHITESPACE', 'COMMENT'}) JoosAccept = JoosDFATokens.union({'WHITESPACE', 'COMMENT'})
JoosStates = JoosAccept.union({'START'}) #TODO: add intermediate states here JoosStates = JoosAccept.union({'START', 'PERIOD2'}) #TODO: add intermediate states here
JoosAlphabet = set(string.ascii_lowercase).union(set(string.ascii_uppercase)).union(set(string.digits)).union(specialChars) JoosAlphabet = set(string.ascii_lowercase).union(set(string.ascii_uppercase)).union(set(string.digits)).union(specialChars)
######################### DFA ####################################### ######################### DFA #######################################
...@@ -307,6 +349,7 @@ def scan(input): ...@@ -307,6 +349,7 @@ def scan(input):
tokens = SMM(input, JoosDFA) tokens = SMM(input, JoosDFA)
if (tokens): if (tokens):
# TODO: handle edge cases (e.g. check int range) # TODO: handle edge cases (e.g. check int range)
# TODO: handle cases where keywords in Java but not in joos appear (a false program)
idsToTokens(tokens) idsToTokens(tokens)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment