📄 lexan.c
字号:
state = 14;
else
state = fail();
break;
case 14:c = nextchar();
if(isdigit(c))
state = 15;
else
state=fail();
break;
case 15:
c = nextchar();
if(isdigit(c))
state = 15;
else if(c == 'e'|| c == 'E')
state = 16;
else
state = fail();
break;
case 16:
c= nextchar();
if(isdigit(c))
state = 18;
else if(c == '+' || c == '-')
state = 17;
else state=fail();
break;
case 17:
c = nextchar();
if(isdigit(c))
state = 18;
else
state=fail();
break;
case 18:
c = nextchar();
if(isdigit(c))
state = 18;
else
state = 19;
break;
case 19:
back();
tokenValue=installSymbol(NUM);
adjustPos();
begin=forward+1;
return NUM;
case 20: /*开始匹配无符号数,有小数点*/
start=20;
c=nextchar();
if(isdigit(c)) state=21;
else state=fail();
break;
case 21:
c=nextchar();
if(isdigit(c))
state=21;
else if(c=='.')
state=22;
else
state=fail();
break;
case 22:
c=nextchar();
if(isdigit(c))
state=23;
else
state=fail();
break;
case 23:
c=nextchar();
if(isdigit(c))
state=23;
else
state=24;
break;
case 24:
back();
tokenValue=installSymbol(NUM);
adjustPos();
begin=forward+1;
return NUM;
case 25: /*开始匹配无符号整数*/
start=25;
c=nextchar();
if(isdigit(c))
state=26;
else state=fail();
break;
case 26:
c=nextchar();
if(isdigit(c)) state=26;
else state=27;
break;
case 27:
back();
tokenValue=installSymbol(NUM);
adjustPos();
begin=forward+1;
return NUM;
case 28: /*匹配符号*/
start=28;
c=nextchar();
if(c==':')
state=29;
else if(c=='{')
state=32;
else if(c=='\'')
state=35;
else if(c=='(')
state=38;
else if(c==';'||c==')'||c=='['||c==']'||c=='+'||c=='-'||c=='*'||c=='/'||c=='.')
state=44;
else
state=fail();
break;
case 29:
c=nextchar();
if(c=='='){
adjustPos(); /*state 30*/
begin=forward+1;
return ASSIGN;
}else{ /*state 31*/
back();
adjustPos();
begin=forward+1;
return COLON;
}
case 32:
c=nextchar();
if(c=='}'){ /*state 33*/
state=0,begin=forward+1;
}
else if(c==EOF){ /*state 34*/
adjustPos();
error(tokPos,"unterminited comment.");
return 0;
}
else if(c=='\n'){
adjustPos();
newLine();
state=32;
}
else
state=32;
break;
case 35:
c=nextchar();
if(c=='\'')
state=36;
else if(c=='\n')
state=37;
else
state=35;
break;
case 36:
tokenValue=installLiteral();
adjustPos();
begin=forward+1;
return LITERAL;
case 37:/*如果到行结束,仍未找到匹配的单引号,则给出错误信息,从下一行开始继续分析*/
adjustPos();
error(tokPos,"Missing terminating \' character.");
state=0;
begin=forward+1;
break;
case 38:
c=nextchar();
if(c=='*'){
state=39;break;
}
else{
back();
adjustPos(); /*state 43*/
begin=forward+1;
return LPAREN;
}
case 39:
c=nextchar();
if(c=='*')
state=40;
else if(c==EOF){
adjustPos(); /*state 42*/
error(tokPos,"Unterminited comment.");
return 0;/*直接到输入结束了return 0 */
}
else if(c=='\n'){
adjustPos();
newLine();
state=39;
}
else{
state=39;
}
break;
case 40:
c=nextchar();
if(c==')'){ /*state 41*/
state=0,begin=forward+1;
}else if(c==EOF){
adjustPos(); /*state 42*/
error(tokPos,"Unterminited comment.");
return 0;
}
else if(c=='\n'){
adjustPos();
newLine();
state=39;
}
else{
state=39;
}
break;
case 44:
adjustPos();
begin=forward+1;
switch(c){
case ';':return SEMICOLON;
case ')':return RPAREN;
case '[':return LBRACK;
case ']':return RBRACK;
case '+':return PLUS;
case '-':return MINUS;
case '.':return DOT;
case '*':return TIMES;
case '/':return DIVIDE;
default:break;
}
break;
case 45:
start=45; /*匹配错误字符或者结束*/
c=nextchar();
if(c==EOF){
printf("LEXICAL ANALYSIS FINISHED.\n");
return 0;
}else{
adjustPos();
error(tokPos,"Illegal character.");
begin=forward+1;
state=0;
}
break;
default:printf("UNKNOWN COMPILE ERROR\n");return 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -