forked from IBM/Project_CodeNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.awk
executable file
·86 lines (75 loc) · 1.71 KB
/
filter.awk
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
#!/usr/bin/awk -f
# Copyright (c) 2020 International Business Machines Corporation
# Prepared by: Geert Janssen <[email protected]>
# Expects a tokenizer generated csv file as input.
# Filters out certain operators and keywords and encodes them
# as numbers in the range [0:16], one per line.
# Hiroki Ohashi, Yutaka Watanobe,
# "Convolutional Neural Network for Classification of Source Codes,"
# 2019 IEEE 13th Int. Symp. on Embedded Multicore/Many-core Systems-on-Chip
BEGIN {
# Assignment operator
encode["="]=0
encode["+"]=1
encode["-"]=1
encode["*"]=1
encode["/"]=1
encode["%"]=1
# Bitwise Operators
encode["&"]=2
encode["|"]=2
encode["^"]=2
encode["~"]=2
encode["<<"]=2
encode[">>"]=2
# Compound arithmetic assignment operators
encode["+="]=3
encode["-="]=3
encode["*="]=3
encode["/="]=3
encode["%="]=3
encode["++"]=3
encode["--"]=3
# Compound bitwise assignment operators
encode["&="]=4
encode["|="]=4
encode["^="]=4
encode["<<="]=4
encode[">>="]=4
# Comparison operators
encode["=="]=5
encode["!="]=5
encode["<"]=5
encode["<="]=5
encode[">"]=5
encode[">="]=5
# Logical operators
encode["&&"]=6
encode["||"]=6
encode["!"]=6
# Others
encode["if"]=7
encode["else"]=8
encode["for"]=9
encode["while"]=10
encode["("]=11
encode[")"]=12
encode["{"]=13
encode["}"]=14
encode["["]=15
encode["]"]=16
FS=","
}
{
# read csv
# check for operator and keyword in column 3 (class)
if ($3 == "operator" || $3 == "keyword") {
# look up field value of column 4 (token)
if ($4 in encode) {
code=encode[$4]
#print $4
print code
}
}
}
END {}