Skip to content

Commit

Permalink
Add separate tokens for class (types) names and identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian13579 committed Feb 28, 2021
1 parent 62b1426 commit db0fb34
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 71 deletions.
17 changes: 11 additions & 6 deletions src/lexing/lexing_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'ASSIGN',
'RET',
'ID',
'TYPE',
'STRING',
'INT',
'COMMENT',
Expand Down Expand Up @@ -60,14 +61,19 @@ def t_RET(t):
set_pos(t)
return t


def t_ID(t):
r'[a-zA-Z_][a-zA-Z_0-9]*'
def t_TYPE(t):
r'[A-Z][a-zA-Z_0-9]*'
set_pos(t)
lower_case = t.value.lower()
if lower_case in ('true', 'false') and t.value[0].isupper():
t.type = 'ID'
if lower_case in ('true', 'false'):
t.type = 'TYPE'
return t
t.type = reserved.get(lower_case, 'TYPE')
return t

def t_ID(t):
r'[a-z_][a-zA-Z_0-9]*'
set_pos(t)
t.type = reserved.get(t.value.lower(), 'ID')
return t

Expand Down Expand Up @@ -271,5 +277,4 @@ def t_ANY_error(t):


# TODO: Add separate tokens for class (types) names and identifiers
# TODO: Fix bug related to (line, col)-setting when the program contains comments
# TODO: Handle errors inside comments (unbalanced multiline comments delimeters)
Loading

0 comments on commit db0fb34

Please sign in to comment.