From 1d943da0cf9154e7ce78ce867cdbb91531c5d78e Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Tue, 25 Jul 2023 14:58:33 -0700 Subject: initial dietc commit --- docs/LANGUAGE.txt | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 docs/LANGUAGE.txt (limited to 'docs/LANGUAGE.txt') diff --git a/docs/LANGUAGE.txt b/docs/LANGUAGE.txt new file mode 100644 index 0000000..124e100 --- /dev/null +++ b/docs/LANGUAGE.txt @@ -0,0 +1,88 @@ +# Full language reference for dietC + +(Some of these may be a bit out-of-date; let me know if you find something +inaccurate!) + +Literals: + ints & floats as output by printf + chars, but no escaping (special characters are encoded as ints) + +File layout: + #include "/path/to/dietc/scripts/dietc_helpers.h" + [type defining lines] + [global declarations & definitions] + +Type defining lines: + struct Struct_%d { Type_%d [ident] ; Type_%d [ident] ; [...] } ; + union Union_%d { Type_%d [ident] ; Type_%d [ident] ; [...] } ; + typedef basic_type Type_%d ; + typedef Type_%d * Type_%d ; + typedef Type_%d Type_%d [ %d ] ; + typedef struct Struct_%d Type_%d ; + typedef union Union_%d Type_%d ; + typedef Type_%d Type_%d ( Type_%d , Type_%d , [...] ) ; + typedef Type_%d Type_%d ( Type_%d , Type_%d , ... ) ; + +global declarations & definitions: + extern Type_%d [ident] ; + static Type_%d [ident] = [globlit] ; + Type_%d [ident] = [globlit] ; + Type_%d [ident] ( Type_%d , [...] ) {\n[body]\n} + Type_%d [ident] ( Type_%d , ... ) {\n[body]\n} + +globlit: + [literal] + { [globlit] , [...] } + ( void * ) ( & [ident] ) + [literal] + ( void * ) [int literal] + +body: + [declaration] + [declaration] + [...] + [instruction] + [instruction] + [...] + [return] + +return: + _L_RETURN : + return [ident] ; + or + _L_RETURN : + return ; + +declaration: + Type_%d [ident] ; + +instruction: + MEMZERO ( [ident] ) ; + MEMCPY ( [ident] , [ident] ) ; + [ident] : + if ( [ident] ) goto [ident] ; + goto [ident] ; + [ident] = [ident] ; + [ident] = [literal] ; + * [ident] = [ident] ; + [ident] = [preop] [ident] ; + [ident] = ( Type_%d ) [ident] ; + ( Type_%d ) [ident] ; + // ^ only when (void)x; left in for autoconf + [ident] = BINARY ( [ident] , [binop] , [ident] ) ; + [ident] = [ident] ( [ident] , [...] ) ; + [ident] ( [ident] , [...] ) ; + [ident] = FIELDPTR ( [ident] , [fname] ) ; + +preop: + !, ~, *, & + +binop: + +, -, *, /, %, &, |, ^, ==, !=, <, <=, <<, >> + +Other guarantees: + instructions in function bodies, and *only* those instructions, are indented + with one tab character + all tokens are space-separated; you can tokenize by splitting each line on + space characters + all instructions are one-line + MEMZERO and MEMCPY are always called on globals & locals; never the heap -- cgit v1.2.3