Starting from:
$30

$24

HW 3 Problem 2 Solution

Question: Write a simple parser for the following EBNF grammar:


-

Provided test cases:

    1. Input: "bc"

Print: "Input is valid"

    2. Input: "acd"

Print: "Syntax error at character position 2"

    3. Input: "aaad"

Print: "Input is valid"

    4. Input: "c"

Print: "Input is valid"

    5. Input: "2yz"

Print: "Syntax error at character position 0"

    6. Input: "" (empty)

Print: "Syntax error at character position 0"

Note: First language is Python

Algorithm/Pseudo code:

Actual Code:
































Syntax Error:

    • When I raise an exception, I need to convert self.char_pos to a string when I create the error message
Working Code


































Debugging

    1. Did not increment char_pos before calling self.fun_x() in line 12. To fix:




















-
    2. 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












-

    3. Need to catch error involving multiple repeating “b”s









-
Add Documentation

Extra Test Cases Used for Debugging:

    1. Input: “abd”

Print: “Syntax error at character position 1”

    2. Input: “b”

Print: “Syntax error at character position 0”

    3. Input: “aaaa”

Print: “Syntax error at character position 3”

    4. Input “bbbb”

Print: “Syntax error at character position 1”

    5. Input: “cc”

Print: “Syntax error at character position 1”

    6. Input: “3”

Print: “Syntax error at character position 0”
Note: Second language is Rust

Actual Code:





















Syntax Error:

    1. Whenever I am indexing the input string, I need to convert self.char_pos to usize using self.char_pos as usize


Working Code


Debugging

    1. 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

More products