-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrules.c
136 lines (100 loc) · 4.09 KB
/
rules.c
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <stdio.h>
void rule_2_2_cpp_style_comments_not_allowed(int in_code,
int a[],
int line)
{
if (in_code and a[1]=='/' and a[0]=='/')
printf("%d:rule_2_2_cpp_style_comments_not_allowed()\n", line);
}
void rule_2_3_nested_comments_not_allowed(int in_comment,
int in_comment_old,
int line)
{
if (in_comment>=2 and in_comment_old!=in_comment)
printf("%d:rule_2_3_nested_comments_not_allowed()\n", line);
}
void rule_4_1_only_simple_escape_sequences_allowed(int in_quote,
int a[],
int line)
{
char simple_escape_sequences[] = "\'\"\\?abfnrtv0\n";
if (in_quote
and a[3]!='\\'
and a[2]=='\\'
and is_not_one_of(a[1], simple_escape_sequences))
//and (a[1]!='0' or (a[1]=='0' and is_one_of(a[0],DIGITS))))
printf("%d:rule_4_1_only_simple_escape_sequences_allowed()\n", line);
}
void rule_4_2_trigraphs_not_allowed(int a[], int line)
{
// Trigraphs are: ??= ??( ??/ ??) ??' ??< ??! ??> ??-
char trigraph_last_characters[] = "=()/'<!>-";
if (a[2]=='?' and a[1]=='?' and is_one_of(a[0], trigraph_last_characters))
printf("%d:rule_4_2_trigraphs_not_allowed()\n", line);
}
void rule_5_1_identifiers_longer_than_31_characters_not_allowed(int in_code,
int a[],
int line)
{
int n=1;
if (in_code
and is_not_one_of(a[32], IDENTIFIER_CHARACTERS)
and is_one_of(a[31], IDENTIFIER_FIRST_CHARACTERS))
for (int i=0; i<31; i++)
if (is_one_of(a[i], IDENTIFIER_CHARACTERS))
n++;
if (n==32)
printf("%d:rule_5_1_identifiers_longer_than_31_characters_not_allowed\n",
line);
}
void rule_7_1_octal_constants_and_escape_sequences_not_allowed(int in_code,
int in_quote,
int a[],
int line)
{
// Octal constants not allowed check:
if (in_code
and is_not_one_of(a[2], IDENTIFIER_CHARACTERS)
and a[1]=='0'
and is_one_of(a[0], DIGITS))
printf("%d:rule_7_1_octal_constants_and_escape_sequences_not_allowed\n",
line);
// Octal escape sequences not allowed check:
if (in_quote
and a[3]!='\\'
and a[2]=='\\'
and a[1]=='0'
and is_one_of(a[0], DIGITS))
printf("%d:rule_7_1_octal_constants_and_escape_sequences_not_allowed\n",
line);
}
void rule_14_4_goto_not_allowed(int in_code, int a[], int line)
{
if (in_code
and is_not_one_of(a[5], IDENTIFIER_CHARACTERS)
and is_in_buffer_at("goto", a, 4)
and is_not_one_of(a[0], IDENTIFIER_CHARACTERS))
printf("%d:rule_14_4_goto_not_allowed()\n", line);
}
void rule_14_5_continue_not_allowed(int in_code, int a[], int line)
{
if (in_code
and is_not_one_of(a[9], IDENTIFIER_CHARACTERS)
and is_in_buffer_at("continue", a, 8)
and is_not_one_of(a[0], IDENTIFIER_CHARACTERS))
printf("%d:rule_14_5_continue_not_allowed()\n", line);
}
void rule_19_6_undef_not_allowed(int in_code, int a[], int line)
{
if (in_code
and is_not_one_of(a[7], IDENTIFIER_CHARACTERS)
and is_in_buffer_at("#undef", a, 6)
and is_not_one_of(a[0], IDENTIFIER_CHARACTERS))
printf("%d:rule_19_6_undef_not_allowed()\n", line);
}
void rule_19_13_token_concatenation_not_allowed(int in_preprocessor_directive,
int a[], int line)
{
if (in_preprocessor_directive and a[0]=='#')
printf("%d:rule_19_13_token_concatenation_not_allowed()\n", line);
}