Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective: Build a compiler for Jack -- a modern, object-based, Java-like language. The compiler construction spans two projects: 10 (Syntax Analysis) and 11 (Code Generation).

Objective: Build a compiler for Jack -- a modern, object-based, Java-like language. The compiler construction spans two projects: 10 (Syntax Analysis) and 11 (Code Generation). In this project we build a syntax analyzer that parses programs according to the Jack grammar, producing an XML file that reflects the program's structure. Resources: The main tool in this project is the programming language in which you will implement the syntax analyzer. You will also need the TextComparer utility (available in your tools directory, assuming that you've installed the TECS software suite), which allows comparing the output files generated by your analyzer to the compare files supplied by us. You may also want to inspect the generated and supplied output files using an XML viewer (any standard web browser should do the job). All the test files necessary for this project are available in project 10.zip. Start by creating a directory named projects/10 on your computer, then extract this file into it (preserving the directory structure embedded in the zip file). files in the zip are:

main txt file:

// This file is part of the materials accompanying the book

// "The Elements of Computing Systems" by Nisan and Schocken,

// MIT Press. Book site: www.idc.ac.il/tecs

// File name: projects/10/ArrayTest/Main.jack

/** Computes the average of a sequence of integers. */

class Main {

function void main() {

var Array a;

var int length;

var int i, sum;

let length = Keyboard.readInt("HOW MANY NUMBERS? ");

let a = Array.new(length);

let i = 0;

while (i < length) {

let a[i] = Keyboard.readInt("ENTER THE NEXT NUMBER: ");

let i = i + 1;

}

let i = 0;

let sum = 0;

while (i < length) {

let sum = sum + a[i];

let i = i + 1;

}

do Output.printString("THE AVERAGE IS: ");

do Output.printInt(sum / length);

do Output.println();

return;

}

}

and the other one;

main T:

-

class

Main

{

function

void

main

(

)

{

var

Array

a

;

var

int

length

;

var

int

i

,

sum

;

let

length

=

Keyboard

.

readInt

(

HOW MANY NUMBERS?

)

;

let

a

=

Array

.

new

(

length

)

;

let

i

=

0

;

while

(

i

<

length

)

{

let

a

[

i

]

=

Keyboard

.

readInt

(

ENTER THE NEXT NUMBER:

)

;

let

i

=

i

+

1

;

}

let

i

=

0

;

let

sum

=

0

;

while

(

i

<

length

)

{

let

sum

=

sum

+

a

[

i

]

;

let

i

=

i

+

1

;

}

do

Output

.

printString

(

THE AVERAGE IS:

)

;

do

Output

.

printInt

(

sum

/

length

)

;

do

Output

.

println

(

)

;

return

;

}

}

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

Advances In Spatial And Temporal Databases 8th International Symposium Sstd 2003 Santorini Island Greece July 2003 Proceedings Lncs 2750

Authors: Thanasis Hadzilacos ,Yannis Manolopoulos ,John F. Roddick ,Yannis Theodoridis

2003rd Edition

3540405356, 978-3540405351

More Books

Students also viewed these Databases questions

Question

1. Are my sources credible?

Answered: 1 week ago

Question

3. Are my sources accurate?

Answered: 1 week ago

Question

1. Is it a topic you are interested in and know something about?

Answered: 1 week ago