-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathppsyntax.c
More file actions
37 lines (35 loc) · 719 Bytes
/
ppsyntax.c
File metadata and controls
37 lines (35 loc) · 719 Bytes
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
# include <stdio.h>
# include <ctype.h>
char translit(char c)
{
switch(c)
{
case '+': return 'x';
case '-': return '_';
case '>': return 'b';
case '<': return 'd';
case '.': return 'w';
case ',': return 'r';
default: return 0;
}
}
int main(void)
{
int c, paren = 0;
const char *px = "";
while((c = getchar()) != EOF)
{
char b = translit(c);
if(b)
printf("%s%s%c", px, paren ? "(" : "", b), paren = 0, px = " ";
else if(c == ']')
printf(paren ? "L R" : ")"), paren = 0, px = " ";
else if(c == '[')
printf("%s%s", px, paren ? "(" : ""), paren = 1, px = "";
else if(isspace(c))
putchar(c), px = "";
}
if(paren)
printf("L\n");
return 0;
}