Question: 1 ) Below is the parser written in class for the grammar S aA | ; A bS: ( setf program ' ( ) )

1) Below is the parser written in class for the grammar S aA|; A bS:
(setf program '())
(defun get-tk ()(car program))
(defun accept-tk ()(setf program (cdr program)))
(defun S ()
(if (null program)
"Parsing successful"
(if (eq (get-tk)'a)
(progn (accept-tk)(A))
"unexpected token"
)
)
)
(defun A ()
(if (null program)
"Program ended unexpectedly"
(if (eq (get-tk)'b)
(progn (accept-tk)(S))
"unexpected token"
)
))
Modify the above parser for the following grammar, and demonstrate using non-trivial strings that the parser correctly parses valid and invalid strings allowed by the grammar:
S bA | c
A cS | d
Note #1: By correctly, it is meant as expected by flagging errors for invalid strings and displaying "success" for valid strings.
Note #2: By non-trivial string, it is meant a string other than a trivial string, examples of trivial strings are '(c),'(b d),'(), and '(e).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!