summaryrefslogtreecommitdiff
path: root/source3/aparser/token.awk
blob: d0703439e99daf724980e8f499a27713251b5794 (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
89
90
91
# tokenise the input file

function parse_error(msg) {
	printf("PARSE ERROR: %s\nLine "NR" : "$0"\n", msg);
	exit 1;
}

# ignore blank lines
/^[ \t]*$/ {
	next;
}

/^\#define.*;/ {
	split($0,a,"[ \t;]*");
	parse_define(a[2], a[3]);
	next;
}

# ignore comments
/^[ \t]*\#/ {
	next;
}

# ignore C comments
/^[ \t]*\/\*.*\*\// {
	next;
}

/^[ \t]*module/ {
	{if (module!="") parse_error("you can only specify one module name");}
	start_module($2);
	next;
}

{if (module=="") parse_error("you must specify the module name first");}

/^[ \t]*typedef struct.*\{/ {
	{if (current_struct!="") parse_error("you cannot have nested structures");}
	start_struct($3);
	next;
}

/^[ \t]*struct.*\{/ {
	{if (current_struct!="") parse_error("you cannot have nested structures");}
	start_struct($2);
	next;
}

{if (current_struct=="") parse_error("this must appear inside a structure");}

/^[ \t]*union.*\{/ {
	{if (current_union!="") parse_error("you cannot have nested unions");}
	start_union($2);
	next;
}

/^[ \t]*case.*;/ {
	{if (current_union=="") parse_error("this must appear inide a union");}
	split($0,a,"[ \t;]*");
	parse_case(a[3],a[4],a[5]);
	next;
}

/^[ \t]*\}$/ {
	{if (current_union=="") parse_error("this must appear inside a union");}
	end_union();
	next;
}

{if (current_union!="") parse_error("this cannot appear inside a union");}

/^[ \t]*\};/ {
	end_struct("");
	next;
}

/^[ \t]*\} .*;/ {
	split($2,a,"[ \t;]*");
	end_struct(a[1]);
	next;
}

/^.*;/ {
	split($0,a,"[ \t;]*");
	add_struct_elem(a[2], a[3]);
	next;
}

{
	parse_error("Unknown construct.");
}