Skip to content

Commit

Permalink
Fix: Missing $ instead of EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadsalimi committed Dec 10, 2021
1 parent 54aa521 commit 274d3a2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cminus/parser/dfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def transition(self, token: Token) -> Tuple['State', Node, Token]:
if epsilon_transition is None or not epsilon_transition.parent_dfa.in_follow(token): # syntax error
if all(isinstance(transition, (TerminalTransition, EpsilonTransition)) for transition in self.current_state.transitions):
error_lexeme = self.current_state.transitions[0].value \
or self.current_state.transitions[0].token_type.name
or self.current_state.transitions[0].token_type.value
ParserErrorLogger.instance.missing_token(token.lineno, error_lexeme)
raise ParserError(ParserErrorType.MissingTerminal)

Expand Down
2 changes: 1 addition & 1 deletion cminus/parser/error_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def missing_token(self, lineno: int, lexeme: str):
def illegal_token(self, token: Token):
lexeme = token.lexeme \
if token.type not in [TokenType.ID, TokenType.NUM] \
else token.type.name
else token.type.value
self.__log(token.lineno, _ErrorType.IllegalToken, lexeme)

def unexpected_eof(self, lineno: int):
Expand Down
14 changes: 7 additions & 7 deletions cminus/scanner/dfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class TokenType(Enum):
"""
TokenType class
"""
ID = 1
KEYWORD = 2
SYMBOL = 3
NUM = 4
COMMENT = 5
WHITESPACE = 6
EOF = 7
ID = 'ID'
KEYWORD = 'KEYWORD'
SYMBOL = 'SYMBOL'
NUM = 'NUM'
COMMENT = 'COMMENT'
WHITESPACE = 'WHITESPACE'
EOF = '$'


TTransitionToken = TypeVar('TTransitionToken')
Expand Down
2 changes: 1 addition & 1 deletion cminus/scanner/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Token:
def __str__(self) -> str:
if self.type == TokenType.EOF:
return self.lexeme
return f'({self.type.name}, {self.lexeme})'
return f'({self.type.value}, {self.lexeme})'


class Scanner:
Expand Down

0 comments on commit 274d3a2

Please sign in to comment.