This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Extending GNU C extensions


Hi there,

I'd like to extend the syntax of GNU C with few basic constructs.
Their main purpose is to simplify the use of repetitive statements and to add
some syntax sugar (but not to much).
All the new constructs can be converted to normal GNU C.

The idea is to use a translator that converts the new syntax to the GNU C one,
in this way, it can be compatible to gcc.

What is the best way to achieve this?
Using flex&bison, M4, the sources of gcc, perl regexp, a specific tool?

What I'm looking for is a simple way to translate this new simple syntax to
GNU C, without rewriting a compiler.


These are some of the new syntax constructs:

-  Struct

element<-struct = value;	  ==>	struct->element = value;

element<`struct = value;	  ==>	struct.element = value;
struct`>element = value;	  ==>	struct.element = value;

- High Level Boolean Logic

A &|| B	      ==>    (A && B) || (A || B)
In english it's the same of: A and/or B

(A && |B, C, D, E|)     ==>   (A && B) || (A && C) || (A && D) || (A && E)
(A || |B, C, D, E|)     ==>   (A || B) || (A || C) || (A || D) || (A || E)
					  ==>  A || B || C || D || E 

(A || &B, C, D, E&)     ==>   (A || B) && (A || C) && (A || D) && (A || E)
(A && &B, C, D, E&)     ==>   (A && B) && (A && C) && (A && D) && (A && E)  
					  ==> A && B && C && D && E

(X <= &A, B&)	     ==>   A <= X && X <= B
(X >= &A, B&)	     ==>   A <= X && X <= B
A < X < B 	     ==>   A < X && X < B
A > X > B 	     ==>   A > X && X > B

- If

(condition)? { 
	CODE
} : (elseif_condition)? {
	CODE
} : (elseif_condition2)? {
	CODE
} : {
	CODE
}

  ==>

if(condition) {
	CODE
} else if(elseif_condition) {
	CODE
} else if(elseif_condition2) {
	CODE
} else {
	CODE
}

- GNU C extensions, extended in the body

struct.{ .y = yvalue, .x = xvalue };
  ==>
struct.y=yvalue; struct.x=xvalue;

array[[1]=value1, [4] = value4];
  ==>
array[1]=value1; array[4]=value4;

struct.{ .y, .x } = value;
  ==>
struct.y = struct.x = value;

array[1, 4, 5, 9...12] = value;
  ==>
array[1]=array[4]=array[5]=array[9]=value;
int _tmp_i; for(_tmp_i=9, _tmp_i<=12, _tmp_i++) array[_tmp_i]=value;

do_something( (struct_type) { .y=yv, .x=xv } );
  ==>
struct struct_type _tmp_struct = { .y=yv, .x=xv};
do_something(_tmp_struct);

mystruct = (struct_type) { .y = yvalue, .x = xvalue }; /* all the other elements
							aren't initialized */
  ==>
struct struct_type _tmp_struct = { .y = yvalue, .x = xvalue };
mystruct = _tmp_struct;

array = (array_type) { [1] = 23. [4] = 9, [10 ... 99] = 2 };
  ==>
#define NMEMB(x)                (sizeof((x))/sizeof(typeof((x)[0])))
array_type _tmp_array[NMEMB(array)] = { [1] = 23. [4] = 9, [10 ... 99] = 2 };
memcpy(array, _tmp_array, sizeof(array));

struct = { 0 };
  ==>
memset(&struct, 0, sizeof(struct));

array = { 0 };
  ==>
memset(&array, 0, sizeof(array));


-- 
:wq!
"I don't know nothing" The One Who reached the Thinking Matter   '.'

[ Alpt --- Freaknet Medialab ]
[ GPG Key ID 441CF0EE ]
[ Key fingerprint = 8B02 26E8 831A 7BB9 81A9  5277 BFF8 037E 441C F0EE ]


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]