Answered step by step
Verified Expert Solution
Link Copied!

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))))); 
  1. Write a "left-most" derivation for (* (car (2 4 (+ 2 4) 8)) (/ 27 9));
  2. 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

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

Students also viewed these Databases questions

Question

define what is meant by the term human resource management

Answered: 1 week ago