Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the following grammar for lisp expressions: lisp : num SEMI num: NUMBER num: LPAREN PLUS num num RPAREN num: LPAREN MINUS num num RPAREN
Consider the following grammar for "lisp" expressions:
lisp : num SEMI num: NUMBER num: LPAREN PLUS num num RPAREN num: LPAREN MINUS num num RPAREN num: LPAREN TIMES num num RPAREN num: LPAREN DIV num num RPAREN num: LPAREN CAR list RPAREN list: LPAREN seq RPAREN list: LPAREN CDR list RPAREN seq: num seq: seq num
This grammar derives valid LISP expressions from the start non-terminal lisp. You may assume NUMBER token matches any number. Other tokens are self-explanatory and CAR and CDR are keywords. Some valid LISP expressions are shown below:
34; (+ 20 30); (* (+ 1 2) (/ 8 4)); (* (car (2 4 (+ 2 4) 8)) (/ 27 9)); (+ (car (2 3 4)) (car (cdr (cdr (9 8 7 6)))));
- Write a "left-most" derivation for (* (car (2 4 (+ 2 4) 8)) (/ 27 9));
- Draw the parse tree for (* (car (2 4 (+ 2 4) 8)) (/ 27 9));
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started