HW 3 Problem 2 Solution

$24.99 $18.99

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…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

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

Provided test cases:

  1. Input: “bc”

Print: “Input is valid”

  1. Input: “acd”

Print: “Syntax error at character position 2”

  1. Input: “aaad”

Print: “Input is valid”

  1. Input: “c”

Print: “Input is valid”

  1. Input: “2yz”

Print: “Syntax error at character position 0”

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

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

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

  1. Input: “b”

Print: “Syntax error at character position 0”

  1. Input: “aaaa”

Print: “Syntax error at character position 3”

  1. Input “bbbb”

Print: “Syntax error at character position 1”

  1. Input: “cc”

Print: “Syntax error at character position 1”

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

HW 3 Problem 2 Solution
$24.99 $18.99