Description
Question: Write a simple parser for the following EBNF grammar:
–
Provided test cases:
-
Input: “bc”
Print: “Input is valid”
-
Input: “acd”
Print: “Syntax error at character position 2”
-
Input: “aaad”
Print: “Input is valid”
-
Input: “c”
Print: “Input is valid”
-
Input: “2yz”
Print: “Syntax error at character position 0”
-
Input: “” (empty)
Print: “Syntax error at character position 0”
Note: First language is Python
Algorithm/Pseudo code:
Syntax Error:
-
When I raise an exception, I need to convert self.char_pos to a string when I create the error message
Debugging
-
Did not increment char_pos before calling self.fun_x() in line 12. To fix:
-
Did not account for the fact that we can have multiple “A”s in a row. Added a while loop to account for multiple “A”s
–
-
Need to catch error involving multiple repeating “b”s
–
Extra Test Cases Used for Debugging:
-
Input: “abd”
Print: “Syntax error at character position 1”
-
Input: “b”
Print: “Syntax error at character position 0”
-
Input: “aaaa”
Print: “Syntax error at character position 3”
-
Input “bbbb”
Print: “Syntax error at character position 1”
-
Input: “cc”
Print: “Syntax error at character position 1”
-
Input: “3”
Print: “Syntax error at character position 0”
Actual Code:
Syntax Error:
-
Whenever I am indexing the input string, I need to convert self.char_pos to usize using self.char_pos as usize
Working Code
-
Threw errors using custom error, but I never caught the error. To fix, I need to add a match statement at the end of fun_s()
–
Add Documentation