summaryrefslogtreecommitdiff
path: root/docs/LANGUAGE.txt
diff options
context:
space:
mode:
Diffstat (limited to 'docs/LANGUAGE.txt')
-rw-r--r--docs/LANGUAGE.txt88
1 files changed, 88 insertions, 0 deletions
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
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback