1 # tokenise the input file
3 function parse_error(msg) {
4 printf("PARSE ERROR: %s\nLine "NR" : "$0"\n", msg);
8 # ignore multi-line C comments.
10 if (t = index($0, "/*")) {
12 tmp = substr($0, 1, t - 1)
15 u = index(substr($0, t + 2), "*/")
21 if (u <= length($0) - 2)
22 $0 = tmp substr($0, t + u + 3)
34 split($0,a,"[ \t;]*");
35 parse_define(a[2], a[3]);
45 {if (module!="") parse_error("you can only specify one module name");}
50 {if (module=="") parse_error("you must specify the module name first");}
57 /^[ \t]*typedef struct.*\{/ {
58 {if (current_struct!="") parse_error("you cannot have nested structures");}
64 {if (current_struct!="") parse_error("you cannot have nested structures");}
69 /^[ \t]*typedef union.*\{/ {
70 {if (current_struct!="") parse_error("this cannot appear inside a structure");}
71 split($0,a,"[ \t;()]*");
72 start_union_encap(a[4], a[6], a[7], a[8]);
77 {if (current_struct!="") parse_error("you cannot have nested structures");}
78 split($0,a,"[ \t;()]*");
79 start_function(a[2], a[3]);
84 /^[ \t]*STATUS.*\(|^[ \t]*void.*\(/ {
85 {if (current_struct!="") parse_error("you cannot have nested structures");}
86 split($0,a,"[ \t;()]*");
87 start_function(a[2], a[3]);
88 return_result="STATUS";
92 {if (current_struct=="") parse_error("this must appear inside a structure");}
95 {if (current_union!="") parse_error("you cannot have nested unions");}
100 /^[ \t]*\[switch_is.*union.*\{/ {
101 {if (current_union!="") parse_error("you cannot have nested unions");}
102 split($0,a,"[ \t;()]*");
103 start_union_notencap(a[3]);
108 {if (current_union=="") parse_error("this must appear inide a union");}
109 split($0,a,"[ \t;]*");
110 parse_case(a[3],a[4],a[5]);
114 /^[ \t]*\[case(.*)\].*;/ {
115 {if (current_union=="") parse_error("this must appear inide a union");}
116 split($0,a,"[ \t;()[\]]*");
117 parse_case(a[6],a[8],a[9]);
122 {if (current_union=="") parse_error("this must appear inside a union");}
128 if (current_union!="") {
129 split($2,a,"[ \t;]*");
135 {if (current_union!="") parse_error("this cannot appear inside a union");}
143 split($2,a,"[ \t;]*");
154 /^.*size_is.*\*.*;/ {
155 split($0,a,"[ \t;()]*");
156 add_sizeis_array(a[3], a[5], a[6]);
161 split($0,a,"[ \t;]*");
162 add_struct_elem(a[2], a[3]);
171 split($0,a,"[ \t;]*");
172 split(a[4], b, "[,]");
173 add_function_param(a[2], a[3], b[1]);
178 parse_error("Unknown construct.");