semi-new language & compiler for test.

Programming, for all ages and all languages.
Post Reply
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

semi-new language & compiler for test.

Post by blackoil »

hi

i made another vector c-like language compiler recently, and port it to my os. it seems work fine.

little language brief:

int main()
{
int[4] * p;

(*p)[2]=100;
}
Attachments
win32.zip
(31.88 KiB) Downloaded 69 times
whowhatwhere
Member
Member
Posts: 199
Joined: Sat Jun 28, 2008 6:44 pm

Re: semi-new language & compiler for test.

Post by whowhatwhere »

Sorry to rain on your parade, but I don't see the advantage of this. Putting the size of the subsequent array beside the type name instead of the identifier seems like a bad idea. For one, it means that each declaration ends up being ambiguous or creating using stack space in excess for no reason. It creates confusion for the reader and adds extra complexity to the compiler. It's basically the same as C, except that array size is placed beside the type instead of after the identifier. You can accomplish the exact same thing in C by dereferencing 'p' combined with an displacement offset like this:

Code: Select all

int *p[4];
*(p+2) = 100; /* or */
(*p)[2] = 100;
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: semi-new language & compiler for test.

Post by qw »

I guess that "int[4] * p;" defines a pointer to an array of four ints, not an array of four pointers to an int.

Nevertheless I do not see the advantage over C, and moreover, the pointer isn't initialized so "(*p)[2]=100;" is trashing memory.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: semi-new language & compiler for test.

Post by blackoil »

yes, it's a pointer of int[4]. It functions just like traditional C, but in clean syntax.

declaration syntax: typelist variablelist;

int*(int*)* p_function; // a function pointer, function itself return pointer, its argument is a pointer too

vector int [4] vi; // vector int128, operate sse instruction directly

typedef mytype int*[4]* // define new type
User avatar
Lithorien
Member
Member
Posts: 59
Joined: Tue Oct 27, 2009 1:40 pm
Location: Hanover, PA

Re: semi-new language & compiler for test.

Post by Lithorien »

blackoil wrote:yes, it's a pointer of int[4]. It functions just like traditional C, but in clean syntax.
...Where "clean syntax" means "completely unreadable by people who understand C conventions"?

C works. Leave it alone.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: semi-new language & compiler for test.

Post by blackoil »

Lithorien wrote:
blackoil wrote:yes, it's a pointer of int[4]. It functions just like traditional C, but in clean syntax.
...Where "clean syntax" means "completely unreadable by people who understand C conventions"?

C works. Leave it alone.
well, how difficult to understand?

you can understand something like
int*(*f)(int*p);
but you can not understand otherthing like
int*(int*)* f;

convention is man-made, it doesn't mean it could not be changed.
I am not here to replace C language.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: semi-new language & compiler for test.

Post by qw »

Like I said, I don't see the advantage, but I don't see why you shouldn't design your own language either. I wish you good luck. Post some documentation if you like.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: semi-new language & compiler for test.

Post by blackoil »

Hobbes wrote:Like I said, I don't see the advantage, but I don't see why you shouldn't design your own language either. I wish you good luck. Post some documentation if you like.
the most difference is the declaration syntax.
typelist variablelist;
left side is type declarator, right side is identifier. pretty simple.

I haven't finished any documents yet. but the compiler has finished for 1 year, with x86 mips ppc cross compilation available.
Post Reply