summaryrefslogtreecommitdiff
path: root/docs/LANGUAGE.txt
blob: 124e1008720705de9eb9df025544c1ba637e5219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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