Skip to content

Commit

Permalink
Merge pull request CodieTamida#98 from CodieTamida/fixe/r19_return_bug
Browse files Browse the repository at this point in the history
Fixe/r19 return bug
  • Loading branch information
NLTN authored Mar 30, 2024
2 parents 2da5ae2 + 460ea96 commit a326c7d
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions components/syntax_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def __r12_declaration(self):
Applies the grammar rule 12:
<Declaration> ::= <Qualifier > <IDs>
"""
self.debug_print("<Declaration> ::= <Qualifier > <IDs>")
self.debug_print_current_token()
self.__r8_qualifier()
self.__r13_ids()
Expand Down Expand Up @@ -462,17 +463,12 @@ def __r19_return(self):
R` = <Return Prime>
"""

if self.__current_token.lexeme == "return":
self.debug_print_current_token()
expression = f'<Return> -> return <Return Prime>'
self.debug_print(expression)

self.__match(self.__current_token.lexeme)

self.__r19_return_b_prime()
else:
self.debug_print(f"Expecting return keyword, but read {self.__current_token.lexeme}")


self.debug_print_current_token()
self.__match("return")
self.debug_print(f"<Return> -> return <Return Prime>")
self.__r19_return_b_prime()

def __r19_return_b_prime(self):
"""
R' --> ; | E
Expand All @@ -489,15 +485,15 @@ def __r19_return_b_prime(self):


# Check to see if <Expression>, after left-recursion, leads E -> TE'

else:
self.debug_print(f"<Return Prime> -> <Expression>;")
self.__r25a_expression()
self.__match(';')


def __r20_print(self):
self.debug_print(f"<Print> -> print ( <Expression> );")
self.__match("print")
self.debug_print_current_token()
self.__match('(')
self.__r25a_expression()
self.debug_print_current_token()
Expand Down

0 comments on commit a326c7d

Please sign in to comment.