www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [documentation] new expression

reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
Where is the grammar that explains:
float[] fl = new float[100];
For this to be posible Declarator should be able to be ; but it can't.
NewExpression:
		new BasicType Stars [ AssignExpression ] Declarator
Jan 26 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Ivan Senji wrote:
 Where is the grammar that explains:
 float[] fl = new float[100];
 For this to be posible Declarator should be able to be ; but it can't.
Wrong. If that were it, it would have to be float[] f1 = new float[100];;
 NewExpression:
 		new BasicType Stars [ AssignExpression ] Declarator
That states exactly nothing about what Declarator can be. But it looks plain wrong to me - surely it should be simply NewExpression: new BasicType Stars [ AssignExpression ] Or am I missing something? Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jan 26 2005
parent reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message
news:ct7uov$1e8a$1 digitaldaemon.com...
 Ivan Senji wrote:
 Where is the grammar that explains:
 float[] fl = new float[100];
 For this to be posible Declarator should be able to be ; but it can't.
Wrong. If that were it, it would have to be float[] f1 = new float[100];;
Yor are right.
 NewExpression:
 new BasicType Stars [ AssignExpression ] Declarator
That states exactly nothing about what Declarator can be.
Ofcourse it doesn't. But this does: Declarator: BasicType2 Declarator Identifier ( Declarator ) Identifier DeclaratorSuffixes ( Declarator ) DeclaratorSuffixes And none of those can be nothing.
 But it looks plain wrong to me - surely it should be simply

      NewExpression:
          new BasicType Stars [ AssignExpression ]
It is better (maybe i am missing something too), but what about float[][] f = new float[][10]; All i know is that this D grammar is driving me crazy, but i need it very much so i can't give up.
 Or am I missing something?

 Stewart.

 --
 My e-mail is valid but not my primary mailbox.  Please keep replies on
 the 'group where everyone may benefit.
Jan 26 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Ivan Senji wrote:
 "Stewart Gordon" <smjg_1998 yahoo.com> wrote in message
 news:ct7uov$1e8a$1 digitaldaemon.com...
<snip>
 But it looks plain wrong to me - surely it should be simply

     NewExpression:
         new BasicType Stars [ AssignExpression ]
It is better (maybe i am missing something too), but what about float[][] f = new float[][10];
<snip> Oh yes. And it would also seem to exclude such declarations as float[5]*[] f = new float[5]*[20]; (Does DMD accept this?) But here's one that would seem to follow the pattern: NewExpression: BasicNewExpression BasicNewExpression ( ArgumentList ) BasicNewExpression: new BasicType BasicNewExpression * BasicNewExpression [ AssignExpression ] (is the Stars nonterminal really necessary?) Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jan 26 2005
next sibling parent reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message
news:ct87n3$1omm$1 digitaldaemon.com...
 Ivan Senji wrote:
 "Stewart Gordon" <smjg_1998 yahoo.com> wrote in message
 news:ct7uov$1e8a$1 digitaldaemon.com...
<snip>
 Oh yes.  And it would also seem to exclude such declarations as

      float[5]*[] f = new float[5]*[20];

 (Does DMD accept this?)
Yes it does :) And also this: float*[5]**[] f = new float*[5]**[20];
 But here's one that would seem to follow the pattern:

      NewExpression:
          BasicNewExpression
          BasicNewExpression ( ArgumentList )

      BasicNewExpression:
          new BasicType
          BasicNewExpression *
          BasicNewExpression [ AssignExpression ]
I'll try it.
 (is the Stars nonterminal really necessary?)
Probably not, i copied this part of the grammar from the docs and left it as is.
 Stewart.

 --
 My e-mail is valid but not my primary mailbox.  Please keep replies on
 the 'group where everyone may benefit.
Jan 26 2005
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Ivan Senji wrote:
 "Stewart Gordon" <smjg_1998 yahoo.com> wrote in message
 news:ct87n3$1omm$1 digitaldaemon.com...
<snip>
     BasicNewExpression:
         new BasicType
         BasicNewExpression *
         BasicNewExpression [ AssignExpression ]
<snip> Oops ... forgot BasicNewExpression [ ] to allow float*[]**[] f = new float*[]**[20]; or even float*[]**[]* f = new float*[]**[]; Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jan 26 2005
prev sibling parent reply "news.digitalmars.com" <ivan.senji public.srce.hr> writes:
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message 
news:ct87n3$1omm$1 digitaldaemon.com...
 But here's one that would seem to follow the pattern:

     NewExpression:
         BasicNewExpression
         BasicNewExpression ( ArgumentList )

     BasicNewExpression:
         new BasicType
         BasicNewExpression *
         BasicNewExpression [ AssignExpression ]
Believe it or not, it works! Thanks a lot Stewart! This has enabled my translator to progress. What do you say about this code: int main (char [][] args) { float[][] floats; floats = new float[][10]; //create rows of the 2D array each floats = new float[10]; //floats[i][j] = (i+1)/(j+1) foreach i and j (each[int i,int j] floats) = (i+1)/(j+1); //printf each float in a new row writefln("Float %d",index,each[int index] floats); //also in beta is something from c-omega int[] ints = new int[10]; //increment ints from 3 .. 5 ints[3..5].{it++;}; //printf each int to screen and then multiply it by 2 ints.{writef(it); it*=2;}; //this is also going to work soon: floats.{ it.{writef(it);}; writefln(); }; //meaning... floats.{ //foreach row... it.{ //printf each elemenet in row writef(it); }; //and then newline writefln(); }; //and new postfix casting : float f = 3.14; int x = f.cast(int); } int func(inout int x) { if(x>0){x++; return;} if(x<0){x--; return;} noreturn; //means this mustn't be reached or exception will be thrown } Extending D syntax is real fun. But geting the grammar to work is extreamly hard. The biggest thing missing right now are initializers and they are going to be difficult to write. Thanks again for your help :)
 Stewart.

 -- 
 My e-mail is valid but not my primary mailbox.  Please keep replies on the 
 'group where everyone may benefit. 
Jan 26 2005
parent "ivan senji" <ivan.senji public.srce.hr> writes:
"news.digitalmars.com" <ivan.senji public.srce.hr> wrote in message 
news:ct9635$2uju$1 digitaldaemon.com...

OOps! Where did my name go. Stupid Outlook Express. (or stupid me) 
Jan 26 2005