digitalmars.D - Extending syntax
- Ivan Senji (42/42) Sep 30 2004 I am writing a preprocessor for D that can add new syntaxes to D,
- h3r3tic (11/17) Sep 30 2004 Cool, so I'm not the only one, I've done a preprocessor in Python to
- Ivan Senji (9/26) Sep 30 2004 Cool! Isn't it great how people all over the world can get simillar
- Walter (4/9) Oct 01 2004 I think your preprocessor idea is a great way for experimenting with new
- Ivan Senji (5/15) Oct 01 2004 I thought so too. :) But I am not sure if preprocessor is the right word
- Walter (4/21) Oct 02 2004 Technically, that would be called a 'translator'. RATFOR and Cfront are
- Ivan Senji (10/32) Oct 02 2004 2.0
- Walter (3/6) Oct 03 2004 Yes.
- Andy Friesen (11/14) Oct 03 2004 With respect to that...
- Ivan Senji (6/20) Oct 04 2004 to
- J Thomas (4/28) Jul 29 2005 hey is there any chance i can get this c2d.py from someone?
- J C Calvarese (8/11) Jul 29 2005 Well, Andy's URL is now http://aegisknight.org/~andy/d/, but I'm not sur...
- Sjoerd van Leent (5/57) Sep 30 2004 Great work!
- Burton Radons (25/49) Sep 30 2004 If this is literally what your preprocessor produces, then it should
- Ivan Senji (11/60) Sep 30 2004 :) I had a feeling i should use foreach
- Ant (5/6) Oct 10 2004 so can we do ctor() instead of this()?
- Ivan Senji (6/12) Oct 10 2004 Well i like this so the first answer is no ;)-
- X (5/47) Oct 11 2004 This is very cool! A substitute for array arith ops till 2.0 maybe :) ?...
- Ivan Senji (7/11) Oct 11 2004 Lots
I am writing a preprocessor for D that can add new syntaxes to D, and have implemented noreturn statement that basically throws an exception int func(int x) { if(x>0){} else if(x<0){} noreturn; //or noreturn("Some message"); } and another iterating construct i call each, It is used like this: int[] numbers; (each numbers)++; and translated to for(int index=0;index<numbers.length; index++) { numbers[index]++; } You can also specify an index: (each[int i] numbers) = i*i; === for(int i=0;i<numbers.length; i++) { numbers[i]=i*i; } Or use it in function calls writef("\n",(each numbers)); But now my brain has stopped and i can't figure out how this should work for a multidimensional case? int[][] a; //initialized somwhere sum += (each[int x,int y] a); //or should it be each[int y,int x] This should translate to what? for(int y=0;y<a.length; y++) { for(int x=0;x<a[y].length;x++) { sum+= a[x][y]; } } Is this correct or did i get the indexes wrong? Should x and y be the other way around? Comments?
Sep 30 2004
Ivan Senji wrote:I am writing a preprocessor for D that can add new syntaxes to DCool, so I'm not the only one, I've done a preprocessor in Python to allow for some aspect oriented programming yet it's very limited ATM and kinda slowish (gonna rewrite in D and add functionality). I hope these 'modifications' can eventually find their way in D 2.0But now my brain has stopped and i can't figure out how this should work for a multidimensional case? int[][] a; //initialized somwhere sum += (each[int x,int y] a); //or should it be each[int y,int x]Are you sure this should be done like this for more than 1 dimension ? I think it would be relatively simple to do sth like int[][] a; sum += (each(each a)); or something along these lines :] Tom
Sep 30 2004
"h3r3tic" <foo bar.baz> wrote in message news:cjhqqh$1hbe$1 digitaldaemon.com...Ivan Senji wrote:Cool! Isn't it great how people all over the world can get simillar ideas!I am writing a preprocessor for D that can add new syntaxes to DCool, so I'm not the only one, I've done a preprocessor in Python to allow for some aspect oriented programming yet it's very limited ATM and kinda slowish (gonna rewrite in D and add functionality).I hope these 'modifications' can eventually find their way in D 2.0I'm not hoping for anything like this, just playing around, although it would be very nice.Well, it looks nice but it would break how things work :( I only expect one each in a statement, so it will generate a loop for only th first each and some strange looking code.But now my brain has stopped and i can't figure out how this should work for a multidimensional case? int[][] a; //initialized somwhere sum += (each[int x,int y] a); //or should it be each[int y,int x]Are you sure this should be done like this for more than 1 dimension ? I think it would be relatively simple to do sth like int[][] a; sum += (each(each a));or something along these lines :] Tom
Sep 30 2004
"Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:cjitk8$s0$1 digitaldaemon.com..."h3r3tic" <foo bar.baz> wrote in message news:cjhqqh$1hbe$1 digitaldaemon.com...I think your preprocessor idea is a great way for experimenting with new syntactical forms.I hope these 'modifications' can eventually find their way in D 2.0I'm not hoping for anything like this, just playing around, although it would be very nice.
Oct 01 2004
"Walter" <newshound digitalmars.com> wrote in message news:cjk1er$pdu$1 digitaldaemon.com..."Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:cjitk8$s0$1 digitaldaemon.com...I thought so too. :) But I am not sure if preprocessor is the right word because it sound like C preprocessor, but it is actually parsing code and creating the syntax tree with which i am playing."h3r3tic" <foo bar.baz> wrote in message news:cjhqqh$1hbe$1 digitaldaemon.com...I think your preprocessor idea is a great way for experimenting with new syntactical forms.I hope these 'modifications' can eventually find their way in D 2.0I'm not hoping for anything like this, just playing around, although it would be very nice.
Oct 01 2004
"Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:cjk4kg$se5$1 digitaldaemon.com..."Walter" <newshound digitalmars.com> wrote in message news:cjk1er$pdu$1 digitaldaemon.com...Technically, that would be called a 'translator'. RATFOR and Cfront are particularly famous examples of the genre."Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:cjitk8$s0$1 digitaldaemon.com...I thought so too. :) But I am not sure if preprocessor is the right word because it sound like C preprocessor, but it is actually parsing code and creating the syntax tree with which i am playing."h3r3tic" <foo bar.baz> wrote in message news:cjhqqh$1hbe$1 digitaldaemon.com...I think your preprocessor idea is a great way for experimenting with new syntactical forms.I hope these 'modifications' can eventually find their way in D 2.0I'm not hoping for anything like this, just playing around, although it would be very nice.
Oct 02 2004
"Walter" <newshound digitalmars.com> wrote in message news:cjmhr2$2ju9$1 digitaldaemon.com..."Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:cjk4kg$se5$1 digitaldaemon.com...2.0"Walter" <newshound digitalmars.com> wrote in message news:cjk1er$pdu$1 digitaldaemon.com..."Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:cjitk8$s0$1 digitaldaemon.com..."h3r3tic" <foo bar.baz> wrote in message news:cjhqqh$1hbe$1 digitaldaemon.com...I hope these 'modifications' can eventually find their way in DnewI'm not hoping for anything like this, just playing around, although it would be very nice.I think your preprocessor idea is a great way for experimenting withandsyntactical forms.I thought so too. :) But I am not sure if preprocessor is the right word because it sound like C preprocessor, but it is actually parsing codeThanks, translator is the word i have been looking for. I have to add that D is a great language to translate to. Thanks for that! BTW: I am not that great at understanding licenses, and i was wondering if the license would permit translating D's lexer to D and changing it to fit my needs? (The lexer i use is really idiotic)creating the syntax tree with which i am playing.Technically, that would be called a 'translator'. RATFOR and Cfront are particularly famous examples of the genre.
Oct 02 2004
"Ivan Senji" <ivan.senji public.srce.hr> wrote in message news:cjmnps$2nsm$1 digitaldaemon.com...BTW: I am not that great at understanding licenses, and i was wondering if the license would permit translating D's lexer to D and changing it to fit my needs? (The lexer i use is really idiotic)Yes.
Oct 03 2004
Ivan Senji wrote:BTW: I am not that great at understanding licenses, and i was wondering if the license would permit translating D's lexer to D and changing it to fit my needs? (The lexer i use is really idiotic)With respect to that... awhile ago, I wrote a little Python script to convert a certain subset of C++ (that which is used by DMD) to D. It handles most everything I've tested it on. (#ifdef, pointers, arrays, etc) To use it, just pass the name of the .c/.h pair as an argument, eg: python c2d.py expression It will parse expression.c and expression.h, and produce expression.d. Maybe it will save you some time. :) <http://andy.tadan.us/d/c2d.py> -- andy
Oct 03 2004
"Andy Friesen" <andy ikagames.com> wrote in message news:cjpb7g$170u$1 digitaldaemon.com...Ivan Senji wrote:toBTW: I am not that great at understanding licenses, and i was wondering if the license would permit translating D's lexer to D and changing itThanks. I am sory that i don't have more time so i can explore python because i have never used it before, so when i do get some free time i think it will be easier for me to convert Walter's lexer from C++ to D.fit my needs? (The lexer i use is really idiotic)With respect to that... awhile ago, I wrote a little Python script to convert a certain subset of C++ (that which is used by DMD) to D. It handles most everything I've tested it on. (#ifdef, pointers, arrays, etc) To use it, just pass the name of the .c/.h pair as an argument, eg: python c2d.py expression It will parse expression.c and expression.h, and produce expression.d. Maybe it will save you some time. :) <http://andy.tadan.us/d/c2d.py>-- andy
Oct 04 2004
hey is there any chance i can get this c2d.py from someone? http://andy.tadan.us/d/c2d.py the site longer exists Andy Friesen wrote:Ivan Senji wrote:BTW: I am not that great at understanding licenses, and i was wondering if the license would permit translating D's lexer to D and changing it to fit my needs? (The lexer i use is really idiotic)With respect to that... awhile ago, I wrote a little Python script to convert a certain subset of C++ (that which is used by DMD) to D. It handles most everything I've tested it on. (#ifdef, pointers, arrays, etc) To use it, just pass the name of the .c/.h pair as an argument, eg: python c2d.py expression It will parse expression.c and expression.h, and produce expression.d. Maybe it will save you some time. :) <http://andy.tadan.us/d/c2d.py> -- andy
Jul 29 2005
In article <dcdr7u$1vcq$1 digitaldaemon.com>, J Thomas says...hey is there any chance i can get this c2d.py from someone? http://andy.tadan.us/d/c2d.py the site longer existsWell, Andy's URL is now http://aegisknight.org/~andy/d/, but I'm not sure if that particular file is there since I'm having trouble reaching his website right now. I don't know if the server is overloaded or if the server is just ticked off at me. If the file isn't at the new website, I should have it burned onto a CD at home. If I remember, I'll try to find it this weekend. jcc7
Jul 29 2005
Ivan Senji wrote:I am writing a preprocessor for D that can add new syntaxes to D, and have implemented noreturn statement that basically throws an exception int func(int x) { if(x>0){} else if(x<0){} noreturn; //or noreturn("Some message"); } and another iterating construct i call each, It is used like this: int[] numbers; (each numbers)++; and translated to for(int index=0;index<numbers.length; index++) { numbers[index]++; } You can also specify an index: (each[int i] numbers) = i*i; === for(int i=0;i<numbers.length; i++) { numbers[i]=i*i; } Or use it in function calls writef("\n",(each numbers)); But now my brain has stopped and i can't figure out how this should work for a multidimensional case? int[][] a; //initialized somwhere sum += (each[int x,int y] a); //or should it be each[int y,int x] This should translate to what? for(int y=0;y<a.length; y++) { for(int x=0;x<a[y].length;x++) { sum+= a[x][y]; } } Is this correct or did i get the indexes wrong? Should x and y be the other way around? Comments?Great work! Work on Aspect Oriented development. This would be a nice addition to D. Regards, Sjoerd
Sep 30 2004
Ivan Senji wrote: [snip]You can also specify an index: (each[int i] numbers) = i*i; === for(int i=0;i<numbers.length; i++) { numbers[i]=i*i; }If this is literally what your preprocessor produces, then it should produce this instead: foreach (size_t i, inout typeof (*(numbers)) __item; numbers) { __item = i * i; } Your code requires a bounds check every iteration, and might require evaluating numbers every iteration.Or use it in function calls writef("\n",(each numbers)); But now my brain has stopped and i can't figure out how this should work for a multidimensional case? int[][] a; //initialized somwhere sum += (each[int x,int y] a); //or should it be each[int y,int x]I think it would be less confusing if it were "each[int x][int y]" because comma-separated indices have special meaning in operator overloading. Declarations are read from left to right; expressions are read from right to left. So: char [x] [y] value; value [y] [x] = 0;This should translate to what? for(int y=0;y<a.length; y++) { for(int x=0;x<a[y].length;x++) { sum+= a[x][y]; } }Similarly this should be: foreach (size_t y, inout typeof (*a) __item0; a) { foreach (size_t x, inout typeof (*__item0) __item1; __item0) { sum += __item1; } }
Sep 30 2004
"Burton Radons" <burton-radons smocky.com> wrote in message news:cjhvlu$1v4f$1 digitaldaemon.com...Ivan Senji wrote: [snip]You can also specify an index: (each[int i] numbers) = i*i; === for(int i=0;i<numbers.length; i++) { numbers[i]=i*i; }If this is literally what your preprocessor produces, then it should produce this instead:foreach (size_t i, inout typeof (*(numbers)) __item; numbers):) I had a feeling i should use foreach but this will have to be (i think) foreach (indexTypeGivenByUser i, inout typeof (numbers[i]) __item; numbers){ __item = i * i; }So i could even (maybe) iterate asociative arrays this way.Your code requires a bounds check every iteration, and might require evaluating numbers every iteration.100% right and a good point, thanks!I know but i think this is what i tried first and got an ambiguous grammar, i'll try it again.Or use it in function calls writef("\n",(each numbers)); But now my brain has stopped and i can't figure out how this should work for a multidimensional case? int[][] a; //initialized somwhere sum += (each[int x,int y] a); //or should it be each[int y,int x]I think it would be less confusing if it were "each[int x][int y]" because comma-separated indices have special meaning in operator overloading.Declarations are read from left to right; expressions are read from right to left. So: char [x] [y] value; value [y] [x] = 0;Thanks! Again, this doesnt look bad at all. I will only have to replace *a with a[y] and *__item0 with __itemo0[x]!This should translate to what? for(int y=0;y<a.length; y++) { for(int x=0;x<a[y].length;x++) { sum+= a[x][y]; } }Similarly this should be: foreach (size_t y, inout typeof (*a) __item0; a) { foreach (size_t x, inout typeof (*__item0) __item1; __item0) { sum += __item1; } }
Sep 30 2004
On Thu, 30 Sep 2004 22:07:50 +0200, Ivan Senji wrote:I am writing a preprocessor for D that can add new syntaxes to D,so can we do ctor() instead of this()? and the postfix var.cast(TYPE) ? ;) Ant
Oct 10 2004
"Ant" <duitoolkit yahoo.ca> wrote in message news:pan.2004.10.10.16.18.26.147697 yahoo.ca...On Thu, 30 Sep 2004 22:07:50 +0200, Ivan Senji wrote:Well i like this so the first answer is no ;)- I'm going to do the postfix cast these days. And add it to dsource, it will be part of lr-lalr project. So anyone can add things.I am writing a preprocessor for D that can add new syntaxes to D,so can we do ctor() instead of this()? and the postfix var.cast(TYPE) ?;) Ant
Oct 10 2004
In article <cjhp3l$1coi$1 digitaldaemon.com>, Ivan Senji says...I am writing a preprocessor for D that can add new syntaxes to D, and have implemented noreturn statement that basically throws an exception int func(int x) { if(x>0){} else if(x<0){} noreturn; //or noreturn("Some message"); } and another iterating construct i call each, It is used like this: int[] numbers; (each numbers)++; and translated to for(int index=0;index<numbers.length; index++) { numbers[index]++; } You can also specify an index: (each[int i] numbers) = i*i; === for(int i=0;i<numbers.length; i++) { numbers[i]=i*i; } Or use it in function calls writef("\n",(each numbers)); But now my brain has stopped and i can't figure out how this should work for a multidimensional case? int[][] a; //initialized somwhere sum += (each[int x,int y] a); //or should it be each[int y,int x] This should translate to what? for(int y=0;y<a.length; y++) { for(int x=0;x<a[y].length;x++) { sum+= a[x][y]; } } Is this correct or did i get the indexes wrong? Should x and y be the other way around? Comments?This is very cool! A substitute for array arith ops till 2.0 maybe :) ? Lots of other cool uses Im sure. Where can we get it ? X
Oct 11 2004
"X" <X_member pathlink.com> wrote in message news:ckebi9$1msk$1 digitaldaemon.com...This is very cool! A substitute for array arith ops till 2.0 maybe :) ?Lotsof other cool uses Im sure.Thanks. Each looks like a good substitute for array ops.Where can we get it ?It will be added to lr-lalr parser project on dsource in a couple of days but it is still mostly a toy because i don't have much time to conect it to a real lexer (like Walter's).X
Oct 11 2004