Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Consider the following grammar for lisp expressions: lisp : num SEMI num: NUMBER num: LPAREN PLUS num num RPAREN num: LPAREN MINUS num num
1. 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: seg 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) (1 84));. (* (car (2 4 (+ 2 4) 8)) (1 27 9)); (+ (car (2 3 4)) (car (cdr (cdr (9 8 7 6))))); a. Write a "left-most" derivation for (* (car (24 (+ 2 4) 8)) (1 27 9)); b. Draw the parse tree for (* (car (2 4 (+ 2 4) 8)) (1 27 9)); 1. 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: seg 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) (1 84));. (* (car (2 4 (+ 2 4) 8)) (1 27 9)); (+ (car (2 3 4)) (car (cdr (cdr (9 8 7 6))))); a. Write a "left-most" derivation for (* (car (24 (+ 2 4) 8)) (1 27 9)); b. Draw the parse tree for (* (car (2 4 (+ 2 4) 8)) (1 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