Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++ or PYTHON please Project Description: Design and implement an interpreter that executes the code written in LAO language. The statements in LAO language

IN C++ or PYTHON please

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Project Description: Design and implement an interpreter that executes the code written in LAO language. The statements in LAO language are: = = := PRINT PRINT PRINT PRINT Cread statement ::= READ := IF THEN END. Where: ::= := a-zA-Z := | Kunsign integer> := ::= | := -e E .=0|1|2|3|4|5|6789 :=+1- :=" - := .gt..It. .eq. -ge..le..ne. ::= .or..and..not. ::= | | 4 ----------- real vs. real real 2.0 .add. 2.0 -> 4.0 real vs. integer real 2.0 .add. 2 => 4.0 .add. string vs. string string. "ab" .add. "C" -> "abc" integer vs. string 3 .add. "ab" => "3ab" real vs. string string "ab" .add. 3.5 => "ab3.5" integer vs. integer integer 2 .sub. 2 => 0 --- ----------- .sub. real vs. real real 2.0 .sub. 2.0 => 0.0 --- real vs. integer real 2.0 .sub. 2 => 0.0 integer vs. integer integer 2 .mul. 2 -> 4 .mul. real vs. real real 2.0 .mul. 2.0 => 4.0 . -.. real vs. integer real 2.0 .mul. 2 -> 4.0 integer vs. integer... integer 2.div. 2 -> 1 ------- ----------------- .div. real vs. real real 2.0 .div. 2.0 => 1.0 ---- .................. real vs. integer real 2.0 .div. 2 -> 1.0 . .or The following table describes the associative and precedence of the logical, relational, and arithmetic operators: Operator Associative Precedence (low to high) left to right and left to right .not right to left .cq. ne. left to right .lt. le ut.ge left to right add sub left to right 6 .div. left to right 7 mul The two operands of a relational operator will be: o integer vs. integer o real vs. real o real vs. integer string vs. string The interpreter must read from a file the instructions of a program written in LAO. In case of an error in an instruction, the interpreter must stop and show: o the line number of the instruction that provoked the error o the instruction that provoked the error o the type of instruction that provoked the error, what is the error, and possible solution (the interpreter must only show unknown statement if the instruction does not match the beginning of any valid statement in the language LAO) Sample program in LAO language: W - "HOLA" Y- MUNDO" if 3 .gt. 2 then a - 2. add. 1. add. 3 .mul, 4 z - * .add. y print z print print if 2 .eq. "HOLA MUNDO" then print z CC - 0 c2 = 9 print print if c.eq. 4 then a - c. add. 3.div. 3 n - 3.0 .add. 2 .mul, c print "n- print n print print wa a = 3 .nul. c. add. 2 print "a - print a 10 w print print print. "ENTER AN INTEGER NUMBER: read b print print print print print "YOU ENTERED: " print print b print print print Print if b .gt. 7.and. b.le. 9.0r. b.eq. 8 then print "a = " if b .gt. 7.and. b.le. 9.or. b.eq. 8 then print a print print end. Project Description: Design and implement an interpreter that executes the code written in LAO language. The statements in LAO language are: = = := PRINT PRINT PRINT PRINT Cread statement ::= READ := IF THEN END. Where: ::= := a-zA-Z := | Kunsign integer> := ::= | := -e E .=0|1|2|3|4|5|6789 :=+1- :=" - := .gt..It. .eq. -ge..le..ne. ::= .or..and..not. ::= | | 4 ----------- real vs. real real 2.0 .add. 2.0 -> 4.0 real vs. integer real 2.0 .add. 2 => 4.0 .add. string vs. string string. "ab" .add. "C" -> "abc" integer vs. string 3 .add. "ab" => "3ab" real vs. string string "ab" .add. 3.5 => "ab3.5" integer vs. integer integer 2 .sub. 2 => 0 --- ----------- .sub. real vs. real real 2.0 .sub. 2.0 => 0.0 --- real vs. integer real 2.0 .sub. 2 => 0.0 integer vs. integer integer 2 .mul. 2 -> 4 .mul. real vs. real real 2.0 .mul. 2.0 => 4.0 . -.. real vs. integer real 2.0 .mul. 2 -> 4.0 integer vs. integer... integer 2.div. 2 -> 1 ------- ----------------- .div. real vs. real real 2.0 .div. 2.0 => 1.0 ---- .................. real vs. integer real 2.0 .div. 2 -> 1.0 . .or The following table describes the associative and precedence of the logical, relational, and arithmetic operators: Operator Associative Precedence (low to high) left to right and left to right .not right to left .cq. ne. left to right .lt. le ut.ge left to right add sub left to right 6 .div. left to right 7 mul The two operands of a relational operator will be: o integer vs. integer o real vs. real o real vs. integer string vs. string The interpreter must read from a file the instructions of a program written in LAO. In case of an error in an instruction, the interpreter must stop and show: o the line number of the instruction that provoked the error o the instruction that provoked the error o the type of instruction that provoked the error, what is the error, and possible solution (the interpreter must only show unknown statement if the instruction does not match the beginning of any valid statement in the language LAO) Sample program in LAO language: W - "HOLA" Y- MUNDO" if 3 .gt. 2 then a - 2. add. 1. add. 3 .mul, 4 z - * .add. y print z print print if 2 .eq. "HOLA MUNDO" then print z CC - 0 c2 = 9 print print if c.eq. 4 then a - c. add. 3.div. 3 n - 3.0 .add. 2 .mul, c print "n- print n print print wa a = 3 .nul. c. add. 2 print "a - print a 10 w print print print. "ENTER AN INTEGER NUMBER: read b print print print print print "YOU ENTERED: " print print b print print print Print if b .gt. 7.and. b.le. 9.0r. b.eq. 8 then print "a = " if b .gt. 7.and. b.le. 9.or. b.eq. 8 then print a print print end

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

More Books

Students also viewed these Databases questions