亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? theparsingprocessofwordsandsyntaxincompilerbymyself.txt

?? 我自己寫的一個C - 語言的詞法分析與語法分析兩個編譯步驟
?? TXT
字號:
  int main()    {
	if( ( fp = fopen("c:\\test.txt","r") )==NULL) {
	  printf("Failed to open the file ! ");     return 0;
	}	
out=fopen("test_out.txt","w");  
	convertGrammar();
	   getFirstSet();	
	   getFollowSet();
	   initParSetable();
	   createTree();	    
    fclose(fp);
    fclose(out);		
    return 0;
}
枚舉類型的定義:
enum Symbol
{
	    ERROR,//0	錯誤
		ENDF,//1	文件結(jié)束
		ELSE,//2	else
		IF,//3		if
		INT,//4		int 整數(shù)
		RETURN,//5	返回
		VOID,//6	空型
		WHILE,//7	while循環(huán)
		DIGIT,//8	數(shù)字
		ID, //9		標(biāo)識
		PLUS, //10	+
		MINUS, //11	-
		MUL, //12	*
		DIV, //13	/
		LT, //14		<
		LTEQ, //15	<=
		GT, // 16		>
		GTEQ, //17	>=	
		EQ, //18		==
		NEQ, //19	!=
		ASSIGN, //20	=
		SEMI, //21	;分號
		COMMA, //22	,逗號
		LPAREN, //23	(
		RPAREN, //24	)
		LMIDPAREN, //25	[
		RMIDPAREN, //26	]
		LMAXPAREN, //27	{
		RMAXPAREN, //28	}
		empty, //29
     //  grammar terminals and nonterminals
		program, //30
		declaration_list, //31
		declaration_list_1, //32
		declaration, //33
		declaration_1, //34
		type_specifier, //35
        var_declaration, //36
		var_declaration_1, //37
        params,//36
		params_1, //38
		params_2, //39
		param_list,//40
		param_list_1,//41
     	param,//42
		param_1,//43
		compound_stmt,//44
		local_declarations,//45
		local_declarations_1,//46
		statement_list,//47
		statement_list_1,//48		
		statement,//49
		expression_stmt,//50
		selection_stmt,//51
		selection_stmt_1,//52
		iteration_stmt,//53
		return_stmt,//54
		return_stmt_1,//55
		expression,//56
		expression_1,//57
		expression_2,//58
		expression_3,//59
		var,//60
		var_1,//61
		simple_expression,//62
		simple_expression_1,//63
        relop,//64
     	additive_expression,//65
		additive_expression_1,//66	
		addop, //67
		term, //68
		term_1, //69
		mulop, //70
		factor, //71
		factor_1, //72
		call, //73
		args, //74
		arg_list, //75
		arg_list_1, //76
		OVER, //77   $ 堆棧初始化時的棧頂元素		
 } ;


將文本文件中記錄的文法轉(zhuǎn)換為整數(shù)型并在內(nèi)存中表示的函數(shù)實現(xiàn):
   void convertGrammar()
{
	/* read grammar from text file in disc and convert it into memory */
  int rowIndex=0,columnIndex=0;
  char grammarFactor[20];
  FILE *f=fopen("c:\\grammar.txt","r");
  int i=0, typeValue=0;
  char ch;
  ch=fgetc(f);
  while( ch!= EOF ) {
      if(ch!=' ' && ch != '\n')    {
	  grammarFactor[i]=ch; 
	  i++;
	  ch=fgetc(f);
	  continue;
	 }
      grammarFactor[i+1] = '\0';
	 
	  if(ch==' ')   {
	     if( strcmp( grammarFactor, "->")==0 )    {  
	     ch=fgetc(f);   i=0;
		 continue;
		 }
        else   {
		   typeValue = convert(grammarFactor);
		   Grammar[rowIndex][columnIndex] = typeValue;
        columnIndex++;
		}
	 }    else        /*  ch='\n'  */    {
     typeValue = convert(grammarFactor);
	    Grammar[rowIndex][columnIndex]=typeValue;
     Grammar[rowIndex][columnIndex+1]=-1;
	    ch=fgetc(fp);
	   rowIndex++;
    columnIndex=0;
	   i=0;
	 }  }   }

基于轉(zhuǎn)換后的文法求每個符號的first集合:
  void getFirstSet()  /* construct first set */
{
	 bool  sequel;
	 int i,j,k;
	 for( i=0; i<30; i++)  /* initial the terminal's firstst to be itself  */ 	 {
		FirstSet[i].item[0] = i;
		FirstSet[i].Length = 1;
	 for( j=1; j<30; j++ )     {
	  FirstSet[i].item[j] = -1;
		}
	}
	for( i =30; i < 86; i++ )    /*initial the nonterminal's firstst to be empty */ 	{
		for( j=0; j < 30; j++ ) {
		FirstSet[i].item[j]=-1;
		}
		FirstSet[i].Length = 0;
/***************************************************************************/
	}
	changed = true;
	 while( changed )    {
		changed=false;
	   for( i=0; i < 86; i ++){
			sequel = true;    k = 1 ;  
   while( sequel && ( Grammar[i][k] != -1  ) )   {
	       setMerge( &FirstSet[ Grammar[i][0] ], &FirstSet[ Grammar[i][k] ], false );
			 if( ! Index( &FirstSet[ Grammar[i][k] ], empty ) )   {
					  sequel = false;
				       k ++;
					}
		   }
		 if( sequel == true )   /* add empty into the first set */
		      setMerge ( &FirstSet[ Grammar[i][0] ], &EP, true );  
		}
	}
	}
對文法中的非終結(jié)符求fellow集合的源代碼:
       void getFollowSet()
{
	int num=0;
	int i,j,k;
	/* Initialize all the follow set of nonterminals to be empty */  
	 /*  48 nonterminal exist in the grammar   */
	for( i=0 ; i < 48; i++)      {
		for( j=0; j < 30; j++)    {
			FollowSet[i].item[j]=-1;
		}
		FollowSet[i].Length=0;
	}
	/* '$' is add into the follow set of the 'program' nonterminal */ 
	   FollowSet[0].item[0] = OVER ;
	   FollowSet[0].Length ++ ;
	/*****************************************************************/
	 bool isEmpty;     /* indicating whether empty is existed in the first set */
	 changed = true;
	 while( changed )  	 {
		num ++;
		changed = false;
		for( i=0; i < 86; i++)    {           
			if( Grammar[i][2] == -1 )   {
				if( Grammar[i][1] < 30
 )  /* if the right side of a production is only one terminal , ignore it */
			    continue;
 setMerge(  &FollowSet[ Grammar[i][1]-30 ], &FollowSet[ Grammar[i][0]-30 ], false);
			}      
    /* if the right side of a production is only a nonterminal, add the follow set of the left part */
 	/* to the follow set of the right nonterminal . */
			else        {
				  k = 1;
				while( Grammar[i][k+1] != -1 )    {
				 	if( Grammar[i][k] < 30 ) 
   /*  with more than one elements on the right side of the production,*/
						{                       /* terminal is ignored */
						   k++;    continue;
						}
					isEmpty = true;
					for( j=k+1; isEmpty && Grammar[i][j] != -1; j++ )    {
						if( !Index( &FirstSet[ Grammar[i][j] ], empty ) )
							  isEmpty = false;                    
        /* empty is not exist in the first set */
				setMerge( &FollowSet[ Grammar[i][k]-30 ], &FirstSet[ Grammar[i][j] ], false);				         /* add first(Xi+1Xi+2....Xn)- empty to follow(Xi) */ 
					 }
	if(  isEmpty )    /* if empty is in first(Xi+1Xi+2...Xn)  then add follow(A) to Follow(Xi)*/
			{
			setMerge(&FollowSet[ Grammar[i][k]-30 ], &FollowSet[ Grammar[i][0]-30 ], false );
				}
			 k++;
				}	  
      if( Grammar[i][k] >= 30 )   /*  The last elemrnt of a production is a nonterminal  */
			      /* add the follow set of the left side to the follow set of the last nonterminal */
		  setMerge(  &FollowSet[ Grammar[i][k]-30 ], &FollowSet[ Grammar[i][0]-30 ] , false );	    	}				
		}
	}
}
在first集合與follow集合的基礎(chǔ)上構(gòu)建LL(1)文法的分析表代碼:
   void initParseTable()
{
   // int table[48][28];
   int i,j,k, temp[50];
   bool isEmpty = false;
      for (i=0 ; i<48; i++ )
	for (j=0; j<28; j++)
			 table[i][j] = -1;
    for (i=0; i<50; i++)
	    temp[i] = -1;
///////////////////////////////////////////////////////////////////////
   for (i=0; i<86; i++)    {
      for (j=1; Grammar[i][j] != -1; j++)   {
		    if ( Grammar[i][j] < 30 )
			{         /* add A-> ... to the entry M[A,a] */
               if (table[ Grammar[i][0] - 30 ][ Grammar[i][j] -2] == -1)
			        table[ Grammar[i][0] - 30 ][ Grammar[i][j] -2] = i;
               else 
                   printf(" ambuguity occurs! \n");
			}    
			else  {        //Grammar[i][j]>=30 means nonterminals
			   for( k=0; k < FirstSet[ Grammar[i][j] ].Length; k++)
			           if ( FirstSet[ Grammar[i][j]].item[k] == empty ) 
			                    isEmpty = true ;
			      if ( isEmpty == false )    {
                     for ( k=0; k < FirstSet[ Grammar[i][j]].Length ; k++)
					 {
						 if ( table[ Grammar[i][0]-30 ][ Grammar[i][j] -2 ]  == -1)
							   table[ Grammar[i][0]-30 ][ Grammar[i][j] -2 ] = i;
						 else
							 printf("Ambuguity occurs!\n");
					 }
				  }
 	 			 else    {                   // isEmpty==true    
				 for ( k=0; k < FirstSet[ Grammar[i][j]].Length ; k++)   {
					 if ( table[ Grammar[i][0]-30 ][ Grammar[i][j] -2 ]  == -1)
							   table[ Grammar[i][0]-30 ][ Grammar[i][j] -2 ] = i;
						 else
							 printf("Ambuguity occurs!\n");
     /* if empty is in first(...), for each element 'a' of follow(A)(a token or $). add A->.. to M[A,a] */                   
                  for ( k=0; k < FollowSet[ Grammar[i][j]].Length; k++ )
                      if (table[Grammar[i][0] -30][ Grammar[i][j] -2] == -1)
							table[Grammar[i][0] -30][ Grammar[i][j] -2] = i;                          
			 }
	     }
    }
}
}
文法分析和構(gòu)造分析樹的源程序:
bool  createTree()
{
     int stack[200], production[10];
	 int *bottom, *top , i = 0, j=0, next, location, length;
     TreeNode *current, *fresh;
	 bottom = top= stack; 
	 TreeNode *Trace[20];   /* record the location of generated nonterminal nodes */
	 int tracePointer=0;
	 stack[0]= OVER;
	 top++;
	 *top = program;
     for ( i=0 ; i<10; i++)
			 production[i]=-1;
	 head = new TreeNode;
     current = head;
	 initTreeNode(current);
	 Trace[tracePointer]=current;
	 tracePointer ++;
	 strcpy( head->stringValue, getName(*top));   
     
	 while ( next=getToken( token ) != ENDF)
	 {
       if ( *top >=30)   {
	   	location = table[*top - 30][next];     /* look up the parse table */
			if (location == -1)    {
			    printf("Syntax Error!\n");
				return false;
			}    
for ( i = 0; Grammar[location][i+1] != -1; i++ )  /* count the right part's length of production */
			length++;
   		    current = Trace[tracePointer]; 
		    tracePointer--;
			current->childNum = length;
while( length != 0)     /* push the production into stack and generate the son node of current nonterminal */
			 {                     
                 top++;
                *top = Grammar[location][length];
                 fresh = new TreeNode;
				  initTreeNode(fresh);
                 current->child[j] = fresh;        
                 strcpy( fresh->stringValue, getName( Grammar[location][length] ) );
			      current->typeValue = Grammar[location][i];
                  if ( *top >= 30 )
				  {
                   Trace[tracePointer] = fresh;
				    tracePointer++;
				  }
				 length--;
			  }
		}
	    if( *top < 30 )  {
		   if ( *top == next )  { /*  match  */
		     if ( *top==OVER )    {
			    printf("Accept!\n");
				 return true;
			 }
			 else {
			  printf(" match !\n" );
             top--;
			 }
		   }
       else { 
	    printf("Error at line %d!\n",line);
         return false;
	      }
	   } 
	 }
	return true;
}             
對每個新生成的結(jié)點的初始化函數(shù):
void initTreeNode(TreeNode *p)
{
  int i;
  for (i=0; i<10; i++)
	  p->child[i]=NULL;
  p->childNum=0;
  p->typeValue=-1;
  i=0;
  while(i<20)
  {
      p->stringValue[1]='\0';
      i++;  
  }
}
在生成集合的過程中用到的輔助函數(shù)的定義為:
bool Index (Set *pointer,int target)    /* query target in the pointer set  */  
{                             /* if target is existed in the set then return true. */
	int i=0;
	while(i < pointer->Length)
	{
		if(pointer->item[i] == target)
			 return true;
		 i++;
	}
	return false;
}

void addItem(Set *pointer,int key)  /*  add key into pointed set  */
 {	
	 int i;
	 i= pointer->Length;
	 pointer->item[i] = key;
	 i++;
	 pointer->Length = i;
    changed = true;
 }
  void setMerge( Set * destinationSet, Set * sourceSet, bool type )    
{
	  int i = 0;                    /* Elements in source set are all add into destination set,*/
	 while( i < sourceSet -> Length )                       /* whether empty element shall be added is determined by type value.*/
	 {                  /* if type equals to 'false', empty is not allowed to add into.*/
         if( sourceSet -> item[i] == empty && type ==false) /* type equals to 'true', empty is allowed to add into.  */   
		 {
		    i++;
		    continue;
		 }
        if( ! Index( destinationSet , sourceSet -> item[i] ) )
		 {
		    addItem( destinationSet, sourceSet -> item[i] );	
			i++;		
		 }
	 }
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩国产a| 午夜成人免费电影| 午夜精品视频在线观看| 国产剧情av麻豆香蕉精品| 欧美性大战久久久| 国产免费观看久久| 日韩在线观看一区二区| 99在线视频精品| 久久久久久久久久看片| 日韩成人一区二区三区在线观看| 成人免费观看男女羞羞视频| 精品精品国产高清a毛片牛牛| 亚洲免费资源在线播放| 国产成人在线视频网站| 日韩欧美视频在线| 日韩综合小视频| 欧美在线不卡视频| 亚洲六月丁香色婷婷综合久久| 国内成人免费视频| 精品国产免费一区二区三区四区| 亚洲电影视频在线| 在线观看国产日韩| 一二三区精品视频| 在线观看av一区二区| 成人免费在线观看入口| caoporm超碰国产精品| 国产清纯白嫩初高生在线观看91| 久久不见久久见免费视频1| 欧美日韩免费观看一区三区| 亚洲一区自拍偷拍| 欧美丝袜第三区| 亚洲一级二级三级| 欧美日韩综合色| 亚洲1区2区3区4区| 欧美精品色一区二区三区| 香蕉成人啪国产精品视频综合网| 色婷婷激情一区二区三区| 亚洲精品中文在线| 一本色道久久综合亚洲91| 一区二区在线观看av| 在线精品观看国产| 午夜视频在线观看一区二区三区| 欧美日韩精品系列| 日韩国产一二三区| 精品美女一区二区三区| 国产一区二区看久久| 日本一区二区三区dvd视频在线| 粉嫩一区二区三区性色av| 国产精品福利电影一区二区三区四区| 国产成人免费在线观看不卡| 18欧美亚洲精品| 欧美日韩在线三级| 美女网站一区二区| 久久久精品黄色| 色综合色狠狠综合色| 亚洲午夜久久久久久久久久久| 欧美日韩国产色站一区二区三区| 美日韩一区二区| 国产亚洲欧美日韩日本| 色婷婷久久99综合精品jk白丝| 婷婷国产v国产偷v亚洲高清| 精品久久久久久久久久久久包黑料| 国产一区二区按摩在线观看| 国产性做久久久久久| 成人丝袜高跟foot| 中文字幕在线一区| 日本国产一区二区| 日韩专区中文字幕一区二区| 日韩一区二区免费视频| 日本不卡一区二区| 久久女同互慰一区二区三区| 成人美女在线视频| 亚洲综合丁香婷婷六月香| 欧美麻豆精品久久久久久| 美国十次综合导航| 欧美激情在线看| 色综合视频在线观看| 亚洲另类在线视频| 日韩精品一区二区三区在线| 国产毛片精品视频| 亚洲最新视频在线播放| 欧美一区二区三区思思人| 国产在线精品一区二区三区不卡| 中文字幕一区二区三区乱码在线| 欧美亚洲综合色| 美腿丝袜在线亚洲一区| 亚洲综合视频网| 精品99一区二区三区| 色综合久久久久综合| 麻豆精品一区二区三区| 国产精品乱人伦一区二区| 在线观看日韩国产| 韩国在线一区二区| 亚洲欧美偷拍另类a∨色屁股| 精品国产乱码久久久久久久久| 99re视频这里只有精品| 美女网站色91| 一个色在线综合| 国产欧美精品国产国产专区| 欧美日韩中文另类| voyeur盗摄精品| 国产在线精品不卡| 日韩高清一区二区| 日韩美女视频一区| 亚洲精品一区二区三区蜜桃下载 | 国产精华液一区二区三区| 一个色综合av| 国产精品乱人伦中文| 精品国产乱码久久久久久影片| 成人av网址在线| 美国三级日本三级久久99| 一区二区三区精品久久久| 欧美极品aⅴ影院| 欧美一区二区大片| 欧美日韩午夜精品| 91在线丨porny丨国产| 国产一区二区免费看| 国产精品无人区| 欧美xxxx在线观看| 欧美高清激情brazzers| 91老司机福利 在线| 国产成人综合视频| 精品一区二区三区免费毛片爱 | 精品精品欲导航| 欧美久久一二区| 91小视频在线免费看| 国产一区免费电影| 日本中文字幕一区二区有限公司| 亚洲激情六月丁香| 亚洲视频图片小说| 亚洲天堂福利av| 亚洲视频在线一区二区| 亚洲色图一区二区三区| 欧美精品一区二区三区蜜桃视频 | 精品亚洲aⅴ乱码一区二区三区| 亚洲成人tv网| 丝袜美腿亚洲综合| 国产乱子伦一区二区三区国色天香| 日韩av中文字幕一区二区| 中文字幕一区二区不卡| 中文字幕高清不卡| 中文字幕一区二区三区四区不卡| 中文成人综合网| 亚洲视频在线观看三级| 亚洲女性喷水在线观看一区| 亚洲精品免费在线观看| 亚洲一区视频在线观看视频| 一区二区免费在线播放| 日本麻豆一区二区三区视频| 裸体歌舞表演一区二区| 国产成人综合亚洲网站| 91免费看片在线观看| 欧美私人免费视频| 51精品视频一区二区三区| 日韩亚洲欧美高清| 综合电影一区二区三区| 亚洲国产一区视频| 久久99久久99| 99久久精品免费看国产 | 国产精品卡一卡二| 亚洲欧美另类图片小说| 亚洲成人免费电影| 老色鬼精品视频在线观看播放| 国产精品一二二区| 欧美日韩成人一区二区| 久久中文娱乐网| 国产精品久久久久久久久久久免费看| 亚洲免费在线视频一区 二区| 亚洲444eee在线观看| 日韩avvvv在线播放| 国产成人精品免费看| 一本一道久久a久久精品综合蜜臀| 欧美视频一区二区三区在线观看| 欧美电影免费观看高清完整版在线| 中文字幕高清一区| 亚洲一区二区四区蜜桃| 99国产一区二区三精品乱码| 欧美一级二级三级蜜桃| 亚洲视频一区二区在线| 麻豆久久一区二区| 成人app网站| 国产日韩欧美精品在线| 婷婷开心久久网| 99亚偷拍自图区亚洲| 精品少妇一区二区三区| 亚洲精品视频一区二区| 国产一区美女在线| 在线欧美日韩国产| 久久久精品天堂| 蜜桃免费网站一区二区三区| 99久久免费视频.com| 精品美女在线播放| 天堂一区二区在线| 91麻豆视频网站| 欧美激情一区在线观看| 久久99国产精品久久| 欧美韩国日本一区| 日本欧美肥老太交大片| 国产iv一区二区三区| 国产亚洲一区二区在线观看|