Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The project for this term is the implement the following project in three different languages: Java Interpreter Project This project will be to write an

The project for this term is the implement the following project in three different languages: Java

Interpreter Project

This project will be to write an interpreter for a minimal form of Julia. This minimal form of Julia has only 1 data type, integer, and the only identifiers are single letters.

The interpreter will parse a Julia program and build some intermediate data structures. These data structures will then be interpreted to execute the program. All tokens in this language are separated by white space. The parsing algorithm should detect any syntactical or semantic error. The first such error discovered should cause an appropriate error message to be printed, and then the interpreter should terminate. Run-time errors should also be detected with appropriate error messages being printed.

Grammar for the language

Parser

function id ( ) end

|

| | | |

if else end

while end

-> id

-> for id = end

print ( )

:

le_operator | lt_operator | ge_operator | gt_operator | eq_operator | ne_operator

| |

add_operator | sub_operator | mul_operator | div_operator | mod_operator | exp_operator | rev_div_operator

Lexical Analyzer

id letter

literal_integer digit literal_integer | digit

assignment_operator =

le_operator <=

lt_operator <

ge_operator >=

gt_operator >

eq_operator = =

ne_operator !=

add_operator +

sub_operator -

mul_operator *

div_operator /

mod_operator %

rev_div_operator \

exp_operator ^

------------------------------------------

input.txt ------------------------------------------

function f ( ) x = 2 y = 3 z = + x y print ( z ) end

function x ( ) x = 7 if < x 4 print ( x ) else print ( * x 2 ) end end

function w ( ) r = 5 while <= r 10 print ( r ) r = + r 1 end print ( 89 ) end

function a ( ) for i = 3 : 5 if != i 4 print ( i ) else print ( 333 ) end end end

-----------------

Output

-----------------

5

14

5

6

7

8

9

10

89

3

333

5

r: 11

x: 7

y: 3

i: 5

z: 5

Please Help:

(Create a Java program which has a parsing algorithm that should detect any syntactical or semantic error based on the grammer for the language. If a error is discovered then it should cause an appropriate error message to be printed, and then the program should terminate. Parsing algorithm should use the input.txt file I provided and it should parse accordingly and also give back results. Expected output is also given, which should be correct).

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions

Question

Find the Product of sum 1) x(yz+x) 2) (x+y)( x+y' )

Answered: 1 week ago

Question

What is order of reaction? Explain with example?

Answered: 1 week ago

Question

Derive expressions for the rates of forward and reverse reactions?

Answered: 1 week ago

Question

Write an expression for half-life and explain it with a diagram.

Answered: 1 week ago

Question

What do you mean by underwriting of shares ?

Answered: 1 week ago

Question

5. Do you have any foreign language proficiency?

Answered: 1 week ago