无符号数的识别new.docVIP

  • 6
  • 0
  • 约3.73千字
  • 约 5页
  • 2016-06-07 发布于重庆
  • 举报
无符号数的识别new

当前状态 扫视字符 语义处理操作或接受动作 后继状态 0 d {n=0;p=0;e=1;w=d} 1 · { w=0;n=0;p=0;e=1} 3 other 识别失败 NULL 1 d {w=w*10+d} 1 · 2 E 4 other {回送整常数ICON=w} 结束 2 d {n++;w=w*10+d} 2 E 4 Other {回送实常数FCON=w*pow(10,e*p-n)} 结束 3 d {n++;w=w*10+d;} 2 Other 识别失败 NULL 4 d {p=p*10+d} 6 + 5 - {e=-1;} 5 other 识别失败 NULL 5 d {p=p*10+d;} 6 other 识别失败 NULL 6 d {p=p*10+d;} 6 other {回送实常数FCON=w*pow (10,e*p-n) } 结束 1 #include<stdio. h> 2 #include<ctype. h> 3 #include<math. h> 4 #define LETTER 0 5 #define DIGIT 1 6 #define POINT 2 7 #define OTHER 3 8 #define POWER 4 9 #define PLUS 5 10 #defineMINUS 6 11 #define ClassNo 100 //Suppose the class of number is 100 12 #define ClassOther 200 13 #define EndState -1 14 int w, n, p, e, d; 15 int Class; //Used to indicate class of the word 16 int ICON; 17 float FCON; 18 static int CurrentState; //Used to present current state, the initial value:0 19 20 int GetChar( void ); 21 int EXCUTE( int, int ); 22 int LEX( void ) 23 int HandleWord ( void ) 24 { return ClassOther; 25 } 26 int HandleError ( void ) 27 { printf ( 〃Error! \n〃); return 0;} 28 29 int GetChar ( void ) 30 { 31 int c; 32 c=getchar ( ); 33 if ( isdigit ( c ) ) {d=c-‘0′; return DIGIT ; } 34 if ( c= =′.′) return POINT ; 35 if ( c= =′E′|| c= =′e′) return POWER; 36 if ( c= =′+′) return PLUS ; 37 if ( c= =′-′) return MINUS ; 38 return OTHER; 39 } 40 int EXCUTE ( int state, int symbol ) 41 { 42 swithch ( state ) 43 { 44 case 0: switch ( symbol ) 45 { 46 case DIGIT:n=0;p=0;e=1;w=d;CurrentState=1;Class=CalssNo;break; 47 case POINT:w=0;n=0;p=0;e=1;CurrentState=3;Class=CalssNo;break; 48 default :HandleError( );Class=ClassOther; 49 CurrentState=EndState; 50 } 51 break; 52 case 1:switch ( symbol ) 53 { 54 case DIGIT:w=w*10+d;break; //CurrentState=1 55 ca

文档评论(0)

1亿VIP精品文档

相关文档