Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Anybody familiar with the Triangle Comipiler?

Reply
Thread Tools

Anybody familiar with the Triangle Comipiler?

 
 
Diphay Z
Guest
Posts: n/a
 
      12-08-2004
The triangle compiler, which was described in the "Programming
Language Processors In Java" --by Watt & Brown. Could anybody discuss
with me?

One of my exercise needs me to extend the compiler to support the
following statement:

for I from E1 to E2 do C, where I is an identifier, E1 and E2 are
expressions will be evaluated as integers, C is a command.

The difficult part of this expansion was in the code generator part.
This statement is hard to formulate a template.
e.g.
For a while command: while E do C
the template can be written as follows:
JUMP h
g: excute C
h: evaluate E
JUMP(1) g

but for the ForCommand, I cannot find out a method to formulate its
template. Anybody can help me? Thanks a lot
 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Daniel_Sj=F6blom?=
Guest
Posts: n/a
 
      12-08-2004
Diphay Z wrote:
> The triangle compiler, which was described in the "Programming
> Language Processors In Java" --by Watt & Brown. Could anybody discuss
> with me?
>
> One of my exercise needs me to extend the compiler to support the
> following statement:
>
> for I from E1 to E2 do C, where I is an identifier, E1 and E2 are
> expressions will be evaluated as integers, C is a command.
>
> The difficult part of this expansion was in the code generator part.
> This statement is hard to formulate a template.
> e.g.
> For a while command: while E do C
> the template can be written as follows:
> JUMP h
> g: excute C
> h: evaluate E
> JUMP(1) g
>
> but for the ForCommand, I cannot find out a method to formulate its
> template. Anybody can help me? Thanks a lot


You haven't specified the exact semantics of the for loop, but assuming
that E1 and E2 will be evaluated only once, and I will be incremented by
one after each iteration, and the loop will continue until I > value of E2:

init:
i <- eval E1
j <- eval E2
jmp test
next:
do C
i <- i + 1
test:
cmp i, j
jna next

But really, you need to tell us what exactly the for statement is
supposed to do.

--
Daniel Sj÷blom
Remove _NOSPAM to reply by mail
 
Reply With Quote
 
 
 
 
Diphay Z
Guest
Posts: n/a
 
      12-08-2004
Firstly, thanks for you reply. As described on the textbook, the for
loop is executed as follows. First, the expressions E1 and E2 are
evaluated, yielding the integers m and n (say), respectively. Then the
subcommand C is executed repeatedly, with identifier I bound in
successive iterations to each integer in the range m through n. If m >
n, C is not executed at all. (The scope of I is C, which may use the
value of I but may not update it. The types of E1 and E2 must be
Integer.) Here is an example:
for n from 2 to m do
if prime(n) then
putint(n)

thx!

 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      12-08-2004
Diphay Z wrote:
> Firstly, thanks for you reply. As described on the textbook, ...


Homework questions are not appropriate to this newsgroup. If your
professor or TA can't help then they're not doing their job, eh?

--
Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.

 
Reply With Quote
 
=?ISO-8859-1?Q?Daniel_Sj=F6blom?=
Guest
Posts: n/a
 
      12-08-2004
Diphay Z wrote:
> Firstly, thanks for you reply. As described on the textbook, the for
> loop is executed as follows. First, the expressions E1 and E2 are
> evaluated, yielding the integers m and n (say), respectively. Then the
> subcommand C is executed repeatedly, with identifier I bound in
> successive iterations to each integer in the range m through n. If m >
> n, C is not executed at all. (The scope of I is C, which may use the
> value of I but may not update it. The types of E1 and E2 must be
> Integer.)


In that case, the for loop can be compiled as I specified in my previous
post. Obviously, the syntax may differ in your particular code generator.

--
Daniel Sj÷blom
Remove _NOSPAM to reply by mail
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Anybody familiar with this RAW converter software Denny B Digital Photography 4 02-15-2007 05:51 AM
anybody familiar with this crowd? eugene Digital Photography 12 03-31-2006 07:35 PM
Is anybody here familiar with the Java certification program? JK Java 1 09-27-2004 11:01 PM
2x2950 + 3745 in triangle Bartek Cisco 1 11-01-2003 08:07 PM
Sample config. for 827 on Sympatico HighSpeed or Golden Triangle? Brad Cisco 0 07-11-2003 03:44 AM



Advertisments