📄 main.c
字号:
ch = readchar();
line1++;
if(ch == '=') {
sp = "0x110";
flow.site = 29;
}
else {
sp = "0x119";
flow.site = 28;
}
}
else {
sp = "0x119";
flow.site = 26 + i;
untread();
}
}
else {
sp = "0x118";
flow.site = 24 + i;
untread();
}
strcpy(flow.attribute,sp);
total++;
linetotal++;
writefile();
}
void op4(char a) {
char *sp;
line1++;
line2 = line1;
total++;
linetotal++;
switch (a) {
case '?':
sp = "0x111";
flow.site = 34;
break;
case ':':
sp = "0x111";
flow.site = 35;
break;
case '~':
sp = "0x11c";
flow.site = 36;
break;
case '[':
sp = "0x11d";
flow.site = 37;
break;
case ']':
sp = "0x11d";
flow.site = 38;
break;
case '(':
sp = "0x11d";
flow.site = 39;
break;
case ')':
sp = "0x11d";
flow.site = 40;
break;
case ',':
sp = "0x120";
flow.site = 42;
break;
case '{':
sp = "0x121";
flow.site = 43;
break;
case '}':
sp = "0x121";
flow.site = 44;
break;
case ';':
sp = "0x122";
flow.site = 45;
break;
}
strcpy(flow.attribute,sp);
writefile();
}
//扫描主函数
void scan() {
char ch,*sp;
int i;
ch = readchar();
character = ch; //
switch (ch) {
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
key();
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':
number();
break;
case '$':
case '_':
identifier();
break;
case '\n':
row++;
line1 = 0;
linetotal = 0;
break;
case ' ':
sp = "0x102";
strcpy(flow.attribute,sp);
flow.site = 46; //
line1++;
line2 = line1;
writefile();
break;
case '\'':
line1++;
line2 = line1;
sp = "0x106";
strcpy(flow.attribute,sp);
flow.site = 0;
total++;
linetotal++;
writefile();
ch = readchar();
instring[0] = ch;
line1++;
line2 = line1;
if( (ch = readchar()) == '\'') {
line1++;
instring[1] = '\0';
total++;
linetotal++;
writefile();
}
else { //只有一个单引号为错误单词
instring[1] = instring[0];
instring[0] = '\'';
instring[2] = '\0';
line1++;
error(instring);
}
line2 = line1;
total++;
linetotal++;
instring[0] = '\'';
instring[1] = '\0';
writefile();
break;
case '"':
line1++;
line2 = line1;
sp = "0x109";
strcpy(flow.attribute,sp);
i = 0;
total++;
linetotal++;
flow.site = 0;
writefile();
line2++;
while( (ch = readchar()) != '"') {
line1++;
instring[i] = ch;
i++;
if(ch == ' ' || ch == '\n') { //以空格和回车符作为单词结束的标志
linetotal++;
total++;
instring[i-1] = '\0';
strcpy(strings[count7],instring);
flow.site = count7;
writefile();
i = 0;
count7++;
line2 = line1;
line2++;
if(ch == '\n') {
linetotal = 0;
line1 = 0;
row++;
}
}
if(i == 50) { //字符串最多有50个单词
printf("the string is too long,please write more blank space.");
exit(0) ;
}
}
line1++;
linetotal++;
total++;
instring[i] = '\0';
strcpy(strings[count7],instring);
flow.site = count7;
writefile();
count7++;
line2 = line1;
flow.site = 0;
writefile();
break;
case '=':
line1++;
line2 = line1;
ch = readchar();
if(ch == '=') {
flow.site = 0;
sp = "0x117";
}
else {
sp = "0x110";
flow.site = 1;
untread();
}
strcpy(flow.attribute,sp);
total++;
linetotal++;
writefile();
break;
case '+':
case '-':
op1(ch);
break;
case '*':
case '/':
case '%':
case '&':
case '^':
case '|':
op2(ch);
break;
case '>':
case '<':
op3(ch);
break;
case '?':
case ':':
case '~':
case '[':
case ']':
case '(':
case ')':
case ',':
case '{':
case '}':
case ';':
op4(ch);
break;
case '\t':
line1 += 4;
break;
}
}
//主函数
int main() {
int i = 0;
char ch1,sp;
char filename[20] ={"scanner_output.txt"};
initi();
readin1();
readin2();
readin1();
character = 'a';
while(character != EOF) {
scan();
}
fp = fopen(filename,"r");
ch1 = fgetc(fp);
while(ch1 != EOF) {
putchar(ch1);
ch1 = fgetc(fp);
}
fclose(fp);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -