-
Notifications
You must be signed in to change notification settings - Fork 0
/
indent_dedent_rule.txt
85 lines (77 loc) · 3.05 KB
/
indent_dedent_rule.txt
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
/*
%{
if(isEmpty(myStack)) {
push(&myStack,0);
}
%} */
/* ^[ \t]* { */
/*
* Handle indentation as described in Python docs linked above.
* Note that this pattern treats leading spaces and leading tabs
* equivalently, which could cause some unexpected behavior if
* they're combined in a single line. For the purposes of this
* project, that's OK.
*/
/* if (peek(myStack) < (int)yyleng) { */
/*
* If the current indentation level is greater than the
* previous indentation level (stored at the top of the stack),
* then emit an INDENT and push the new indentation level onto
* the stack.
*/
/* push(&myStack,yyleng);
printf("INDENT\n");
return INDENT;
} else { */
/*
* If the current indentation level is less than or equal to
* the previous indentation level, pop indentation levels off
* the stack until the top is equal to the current indentation
* level. Emit a DEDENT for each element popped from the stack.
*/
/* while (!isEmpty(myStack) && peek(myStack) != (int)yyleng) {
pop(&myStack);
printf("DEDENT\n");
return DEDENT;
} */
/*
* If we popped everythin g off the stack, that means the
* current indentation level didn't match any on the stack,
* which is an indentation error.
*/
/* if (isEmpty(myStack)) {
printf("Error: Incorrect indentation on line %d"
,yylineno);
return 1;
}
}
} */
/* ^[^ \t\n]+ { */
/*
* If we find a line that's not indented, pop all indentation
* levels off the stack, and emit a DEDENT for each one. Then,
* call REJECT, so the next rule matching this token is also
* applied.
*/
/* while(peek(myStack) != 0) {
pop(&myStack);
printf("DEDENT\n");
return DEDENT;
}
REJECT;
}
\r?\n { */
/* printf("NEWLINE\n");
return NEWLINE;
}
<<EOF>> { */
/*
* If we reach the end of the file, pop all indentation levels
* off the stack, and emit a DEDENT for each one.
*/
/* while(peek(myStack) != 0) {
pop(&myStack);
printf("DEDENT\n");
return DEDENT;
}
} */