------------------------------------------------------------------------- C-- Specification EECS 483 Compiler Construction Fall 2004 ------------------------------------------------------------------------- C-- is a subset of the C programming language. Thus for anything not specified below, you can assume standard ansi C syntax. Most of the major constructs are present, but there are also many limitations. ==Preprocessor Macros== No macros are allowed in C--. This precludes the use of #includes, thus all library functions must be extern-defined with the return type specified. ==Primitives== The only primitives are integers, characters, void and their pointers. Pointers in C-- allow for only ONE level of indirection. Thus, one would never see: char **my_var; There are no floating-point or double-precision floating-point primitives. ==Constants== The only allowed constants in C-- are integers and double-quoted strings. Please note that single-quoted characters are NOT allowed. Note also that your lexer should support multi-line string constants. ==Keywords== C-- recognizes ONLY the following keywords: int char void if else for while extern return The following reserved words are NOT VALID in C--: auto break case default do double volatile entry float goto long short sizeof register struct switch typedef union enum const unsigned static continue Note that the above listing implies the absence of constructs such as switch statement and structs in C--. ==Braces in Conditionals & Loops== In addition, all conditionals and loops must have followed by a set of braces. This means that while if(a > 0) { printf("Hello world\n"); } is valid, if(a > 0) printf("Hellow world\n"); is not. The short-circuit operators (? :) are not used in C--. ==Declarations== C-- also forbids multiple variable declarations in the same statement. Thus int a; int b; is valid, while int a, b; is not recognized. Initialization is also prohibited in a variable declaration. Thus, int a = 0; is not recognized. Arrays may only be initialized in one dimension and can only have their sizes specified using a single integer constants. For example: int a[30]; All function prototypes and extern defines must be ansi style. That is, a prototype must be of the form int foo(int x, int y, ...); and an extern defined function of the form extern char bar(int a, char z,...); You MUST support var args in your grammar. ==Assignments== Once again, assignments are forbidden in variable declarations. Furthermore, C-- does not allow multiple assignments in the same statement. Thus, a = 4, b = 3; is NOT a valid C-- statement. While individual array elements can be accessed, an array may not be instantiated by giving a list of elements in braces. That is, the following is not allowed: int a[3] = {4, 5, 6}; ==Return Statements== Just as a reminder, C-- should recognize return statements with and without values. e.g. return 0; and return; ==Operators== The bit-wise operators are not supported in C--. That means no | & ^