source: proto/s2k/trunk/framework/input/test/s2k/proto/grep/grep_flow.s2k @ 3840

Last change on this file since 3840 was 3840, checked in by ksherdy, 5 years ago

Added sequential for support to grammar. Grammar cleanup.

File size: 3.3 KB
Line 
1/*
2struct Basis_bits{
3    stream bit_0;
4    stream bit_1;
5    stream bit_2;
6    stream bit_3;
7    stream bit_4;
8    stream bit_5;
9    stream bit_6;
10    stream bit_7;
11};
12*/
13
14struct Lex{
15    stream a;
16    stream p;
17    stream l;
18    stream e;
19    stream LF;
20};
21
22struct Output{
23    stream match_follows;
24    stream lines;
25    stream line_starts;
26    stream line_ends;
27};
28
29filter ClassifyBytes(struct Basis_bits basis_bits, struct Lex lex) {
30    stream temp1 = (basis_bits.bit_1 & (~ basis_bits.bit_0));
31    stream temp2 = (basis_bits.bit_2 & (~ basis_bits.bit_3));
32    stream temp3 = (temp1 & temp2);
33    stream temp4 = (basis_bits.bit_4 | basis_bits.bit_5);
34    stream temp5 = (basis_bits.bit_7 & (~ basis_bits.bit_6));
35    stream temp6 = (temp5 & (~ temp4));
36    lex.a = (temp3 & temp6);
37    stream temp7 = (basis_bits.bit_2 & basis_bits.bit_3);
38    stream temp8 = (temp1 & temp7);
39    stream temp9 = (basis_bits.bit_6 | basis_bits.bit_7);
40    stream temp10 = (temp4 | temp9);
41    lex.p = (temp8 & (~ temp10));
42    stream temp11 = (basis_bits.bit_4 & basis_bits.bit_5);
43    stream temp12 = (temp11 & (~ temp9));
44    lex.l = (temp3 & temp12);
45    stream temp13 = (basis_bits.bit_5 & (~ basis_bits.bit_4));
46    stream temp14 = (temp13 & temp5);
47    lex.e = (temp3 & temp14);
48    stream temp15 = (basis_bits.bit_0 | basis_bits.bit_1);
49    stream temp16 = (basis_bits.bit_2 | basis_bits.bit_3);
50    stream temp17 = (temp15 | temp16);
51    stream temp18 = (basis_bits.bit_4 & (~ basis_bits.bit_5));
52    stream temp19 = (basis_bits.bit_6 & (~ basis_bits.bit_7));
53    stream temp20 = (temp18 & temp19);
54    lex.LF = (temp20 & (~ temp17));
55}
56
57filter Match(struct Lex lex, struct Output output) {
58    stream cursor = flow.Advance(lex.a);
59    cursor = flow.Advance((cursor & lex.p));
60    cursor = flow.Advance((cursor & lex.p));
61    cursor = flow.Advance((cursor & lex.l));
62    cursor = flow.Advance((cursor & lex.e));
63    output.match_follows = cursor;
64}
65
66filter MatchLines(struct Lex lex, struct Output output) {
67    stream all_line_starts = (flow.ScanToFirst((~ lex.LF)) | (flow.Advance(lex.LF) & (~ lex.LF)));
68    stream all_line_ends = lex.LF;
69    stream last_line_start = flow.ScanToFirst(all_line_starts);
70    stream cursor = last_line_start;
71    while (flow.inFile(cursor)) {
72        if ((cursor & all_line_starts)) {
73            last_line_start = cursor;
74        }
75        if ((cursor & output.match_follows)) {
76            cursor = flow.ScanTo(cursor, lex.LF);
77            output.lines |= flow.InclusiveSpan(last_line_start, cursor);
78        }
79        cursor = flow.AdvanceThenScanTo(cursor, (all_line_starts | output.match_follows));
80    }
81    output.line_starts = (output.lines & all_line_starts);
82    output.line_ends = flow.ScanTo(output.line_starts, (output.lines & all_line_ends));
83}
84
85/*
86filter Demo(struct Output output) {
87        stream m = output.match_follows;
88        int c = 0;
89    foreach (stream s) in (stream m) {         
90        printf("%d", c);
91        c = c + 1;
92       
93    }   
94}
95*/
96 
97graph Main() {
98
99    // char * byte_data;
100    struct Basis_bits basis_bits;
101    struct Lex lex;
102    struct Output output;
103   
104    filter Transpose transpose;
105    filter ClassifyBytes classifyBytes;
106    filter Match match;
107    filter MatchLines matchLines;
108//    filter Demo demo;
109
110    transpose(byte_data, basis_bits);
111    classifyBytes(basis_bits, lex);
112    match(lex, output);
113    matchLines(lex, output);
114//    demo(output);
115   
116}
Note: See TracBrowser for help on using the repository browser.