Question: Using ANTLR4 system, write an interpreter for the language of LISP expressions A LISP expression is defined as follows: 1. A nmber is a LISP
Using ANTLR4 system, write an interpreter for the language of "LISP expressions" A LISP expression is defined as follows: 1. A nmber is a LISP expression. (We can assume positive integers) 2. if E1 and E2 are LISP expressions then so are (+ E1 E2), (-E1 E2), (. E1 E2), and (E1 E2). 3. if L is a ListExpression (defined below) then (car L) is a LISP expression. A ListExpression is defined as follows: 1 if E1, E2, , En are LISP expressions where n>1 then (E1 E2 En) is a ListExpression. 2. if L is a ListExpression then (cdr L) is a ListExpression. Here are examples of valid LISP expressions: 34 (+ 20 30) (+ 1 2) 8 4)) (car (24 2 4) 8)) ( 27 9)) Here is a sample run: MacBook-Proilisp rajs java LISP LISP> 34: The value is 34.0 LISP> ( 20 30): The value is 50.0 LISP> + 1 2) (8 4)) The value is 6.0 LISP> (car (2 4 ( 2 4) 8)) ( 27 9)) The value is 6.0 The value is 9.0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
