Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Rules In Database Systems Third International Workshop Rids 97 Sk Vde Sweden June 26 28 1997 Proceedings Lncs 1312

Authors: Andreas Geppert ,Mikael Berndtsson

1997th Edition

3540635165, 978-3540635161

More Books

Students also viewed these Databases questions