Computer Science Canada

Simple While program

Author:  Necromancer [ Thu Aug 26, 2004 9:28 am ]
Post subject:  Simple While program

Is this right, I think it is but there seems to be something I cant put my finger on, it's a restrited form of a while program, is the syntax correct compared with the grammar??

WHILEPROG ::= while(BOOLEXPR) {STATEMENT}
STATEMENT ::= SINGLESTMT|SEQUENCE
SEQUENCE ::= STATEMENT ; STATEMENT
SINGLESTMT ::= ASSIGNMENT|WHILEPROG
ASSIGNMENT ::= VAR:= NUMEXPR;
VAR ::= u|v|v|w|x|y|z
NUMEXPR ::= VAR|INT|CALCULATION
INT ::= 0|1|2|3|4|5|6|7|8|9
CALCULATION ::= (NUMEXPR + NUMEXPR)
CALCULATION ::= (NUMEXPR - NUMEXPR)
BOOLEXPR ::= ATOMICBOOL|COMPOSIT
ATOMICBOOL ::= (NUMEXPR < NUMEXPR)
ATOMICBOOL ::= (NUMEXPR > NUMEXPR)
COMPOSIT ::= (BOOLEXPR AND BOOLEXPR)
COMPOSIT ::= (BOOLEXPR OR BOOLEXPR)
COMPOSIT ::= NOT(BOOLEXPR)


while((1 > 1) or (2 > 1))
{x :=(7+(6-3));
x:=x+8;
while(x>0)
{u :=x+4;
x:=x+1;}
y:=((u+x)-(u-1));}

Any responce would be appreciated, thanks

Author:  Dan [ Thu Aug 26, 2004 2:06 pm ]
Post subject: 

This is in java?????

I have never seen some one define what an int is or var like this in java nor use := and ::= quite like that in java. Ethere this is somting way behond me or it is not standered sun java.

Also i am not shure of the logic behind the code, it seems to me that all the varbiles will be the same and it will make a infent loop.

Is there more code u are not show us? (b/c the one while loop is not closed)

Also are u shure this is java, b/c u posted this in the java help section...

Author:  wtd [ Thu Aug 26, 2004 2:18 pm ]
Post subject: 

Java uses "=" for assignment, rather than ":=". Otherwise the posted code is correct.
"

Author:  Cervantes [ Thu Aug 26, 2004 3:20 pm ]
Post subject: 

Hacker Dan wrote:
Also are u shure this is java, b/c u posted this in the java help section...


err, this was originally in the Turing Help section, so I guess a mod moved it, and deleted zster's reply. Anywho, I don't think necromancer posted it in the Java forum himself.

Author:  Dan [ Thu Aug 26, 2004 3:48 pm ]
Post subject: 

wtd wrote:
Java uses "=" for assignment, rather than ":=". Otherwise the posted code is correct.
"


and the or in the while loop Rolling Eyes


It kind of looks like a mix between java and turing. But even if it is i still do not see how/why INT and VAR and all that stuff at the top is being declaered or why the while loops are there and not just a normal loop if it the values will allways be the same....

Author:  Tony [ Thu Aug 26, 2004 3:51 pm ]
Post subject: 

wow, I'm lost
Quote:

while((1 > 1) or (2 > 1))
?? what the... Shocked
code:

while(true)
perhaps? Laughing

Author:  Necromancer [ Mon Sep 06, 2004 9:49 am ]
Post subject: 

Cervantes wrote:
Hacker Dan wrote:
Also are u shure this is java, b/c u posted this in the java help section...


err, this was originally in the Turing Help section, so I guess a mod moved it, and deleted zster's reply. Anywho, I don't think necromancer posted it in the Java forum himself.


I realised what I did then I posted it in Java, and yes it is Java

tony wrote:
??what the... Shocked

Doh, yeah pretty obvious, most things are when their pointed out
So apart from not being closed and the possibility that there is no need for a while loop when a normal loop will suffice?? It's ok right, the declerations aside, because well there confusing

Author:  rizzix [ Mon Sep 06, 2004 12:00 pm ]
Post subject: 

The declarations are NOT java. The assignements are NOT java. What ever language your using is most certainly not java. it appears to be delphi or something.. (but i would not know,, its alien to me anyways) but its definately not java.

---
btw you can;t challenge us on this fact.. cuz we've been programming java for quite sometime and continue to do so.. we know all the new and latest modifications to the java language.. but what you have posted up there is just simply not java.

Author:  wtd [ Mon Sep 06, 2004 1:36 pm ]
Post subject: 

rizzix wrote:
The declarations are NOT java. The assignements are NOT java. What ever language your using is most certainly not java. it appears to be delphi or something.. (but i would not know,, its alien to me anyways) but its definately not java.

---
btw you can;t challenge us on this fact.. cuz we've been programming java for quite sometime and continue to do so.. we know all the new and latest modifications to the java language.. but what you have posted up there is just simply not java.


What he posted first was a BNF grammar. It describes the syntax of a programming language. The latter was quasi-Java, just using the Pascal-esque ":=" and "or" instead of "=" and "||".

Author:  rizzix [ Mon Sep 06, 2004 1:52 pm ]
Post subject: 

o i c.. BNF!! shooot!! that explains those assignments.


but in any case he did ask me if it was java.. dosent matter if he's trying to describe the java grammar. its definately not java now is it? his descriptions are slightly wrong here and there.

Author:  Dan [ Mon Sep 06, 2004 3:07 pm ]
Post subject: 

so i think what he ment was:

code:

while(true)
{
    int x = 18;
   
    while(x>0)
    {
        int u = x+4;
        x++;
    }
     
    int y = ((u+x)-(u-1));
}


that is simplfing the staments down since they will allways be that no matter what. The y = part will never run b/c it is out side of the 2nd infent loop so x and u will keep going up intill u/x over loads the memory and then will ether crash the app or go to the negtives, if java dose go to negtives then the 2nd loop will exit and y will get a realy messed up number. then the 1st loop will start agaen and x will be reset back to 18 and u back x+4. And this will keep going on forever and y will allways have the same value.


Edit: P.S. if the lang only has the values for 0-9 for ints then it will crash at the 1st decleration of the x b/c 18 is not one of thos numbers....

Author:  wtd [ Mon Sep 06, 2004 3:42 pm ]
Post subject: 

The gammar, unless I'm really rusty, says that numbers can be composed of any digits between 0 and 9. It doesn't say it can only be one of those.

For what it's worth, I really like Ada/Ruby integers, where _ is an acceptable character.

code:
my_int = 1_000_000


Or

code:
My_Int : Integer := 1_000_000;


Vs.

code:
int myInt = 1000000;


Ada's syntax for different bases is nice too. Wink

code:
My_Binary_Number : Integer := 2#10101101#;

Author:  rizzix [ Mon Sep 06, 2004 4:15 pm ]
Post subject: 

wtd wrote:

Ada's syntax for sidderent bases is nice too. Wink

code:
My_Binary_Number : Integer := 2#10101101#;


what do u mean? heh sorry i dunt understand

but if its what i think it is.. turing supports that too. lol.. hmm so does java, c++/c but not base2 only 8 and 16 i think.. hmm perl supports base2.

Author:  Dan [ Mon Sep 06, 2004 6:07 pm ]
Post subject: 

wtd wrote:
The gammar, unless I'm really rusty, says that numbers can be composed of any digits between 0 and 9. It doesn't say it can only be one of those.


Ah ic, it is me that is most likey wrong, i miss undestud what it ment but still u will get the overflow problem in that progam b/c of the inf loop...

Author:  wtd [ Mon Sep 06, 2004 6:07 pm ]
Post subject: 

rizzix wrote:
wtd wrote:

Ada's syntax for sidderent bases is nice too. Wink

code:
My_Binary_Number : Integer := 2#10101101#;


what do u mean? heh sorry i dunt understand

but if its what i think it is.. turing supports that too. lol.. hmm so does java, c++/c but not base2 only 8 and 16 i think.. hmm perl supports base2.


Sorry... typo in the original. Edited now.

Basically numbers can be in the form:

code:
base#value#


So you can specify arbitrary number bases.

code:
16#DEADBEEF#


For instance. Smile

Author:  rizzix [ Mon Sep 06, 2004 8:04 pm ]
Post subject: 

Shocked are u serious what if a want a 1000000000 base.. from where do i get the characters to represet all those numbers Confused

Author:  wtd [ Mon Sep 06, 2004 8:59 pm ]
Post subject: 

rizzix wrote:
Shocked are u serious what if a want a 1000000000 base.. from where do i get the characters to represet all those numbers Confused


Theoretically yes. Smile

code:
My_Really_Big_Int : Integer := 1_000_000_000#42#;

Author:  zylum [ Mon Sep 06, 2004 9:16 pm ]
Post subject: 

ok so for base 1000000000, how would you represent 999999999?

Author:  wtd [ Mon Sep 06, 2004 9:19 pm ]
Post subject: 

To respresent that many possibilities in one digit you'd have to dig into pretty much every written language on Earth for letters.

The key word is "theoretical". Wink

Author:  Necromancer [ Thu Sep 09, 2004 8:27 am ]
Post subject: 

Thanks for all the input guys, just one more question for anyone that might know, COMPOSIT (BNF grammar), does it simply mean composition?? this is my last question in this rather strange topic, thanks


: