View the step-by-step solution to:

Could you code this assignment?

Could you code this assignment?
Guide lines are here.
---------------------------------------------
Implement the "read" function in C++, which can recognize expressions defined as follows.

<s-expr> := '(' {<s-expr> | <term>} ')'
<term> := ID | integer | '+' | '-' | '*' | '/'
The output of the function is a parse tree specified as follows. ID is any string of digits and letters that starts with a letter. Here "integer" is any string of digits whose first digit is nonzero.

Example

(a 1 2 (b 3 (+ 4 cx2) 5) 6 (7 8))
<E1> => (a 1 2 <E2> 6 <E4>)
<E2> => (b 3 <E3> 5)
<E3> => (+ 4 cx2)
<E4> => (7 8)
An <s-expr> is represented as <E#>. The expression number (#) starts from 1, and is determined by the order of appearance in the input expression. Print the expressions one per line, in the increasing order of the expression number.

Example in action

$ ./solb
> (a 1 2 (b 3 (+ 4 cx2) 5) 6 (7 8))
<E1> => (a 1 2 <E2> 6 <E4>)
<E2> => (b 3 <E3> 5)
<E3> => (+ 4 cx2)
<E4> => (7 8)
> [Ctrl-D]
$
Sign up to view the entire interaction

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question