璇嶆硶鍒嗘瀽绋嬪簭鐨勮璁′笌瀹炵幇

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了璇嶆硶鍒嗘瀽绋嬪簭鐨勮璁′笌瀹炵幇相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/http' title='http'>http   缁撴灉   ++   鏍囪瘑   缁撴瀯   ica   txt   ble   das   

璇嶆硶鍒嗘瀽绋嬪簭锛?em>Lexical Analyzer锛夎姹傦細

- 浠庡乏鑷冲彸鎵弿鏋勬垚婧愮▼搴忕殑瀛楃娴?/p>

-  璇嗗埆鍑烘湁璇嶆硶鎰忎箟鐨勫崟璇嶏紙Lexemes锛?/p>

-  杩斿洖鍗曡瘝璁板綍锛堝崟璇嶇被鍒紝鍗曡瘝鏈韩锛?/p>

-  婊ゆ帀绌烘牸

-  璺宠繃娉ㄩ噴

-  鍙戠幇璇嶆硶閿欒

 

绋嬪簭缁撴瀯锛?/p>

杈撳叆锛氬瓧绗︽祦锛堜粈涔堣緭鍏ユ柟寮忥紝浠€涔堟暟鎹粨鏋勪繚瀛橈級

澶勭悊锛?/p>

–閬嶅巻锛堜粈涔堥亶鍘嗘柟寮忥級

–璇嶆硶瑙勫垯

杈撳嚭锛氬崟璇嶆祦锛堜粈涔堣緭鍑哄舰寮忥級

–浜屽厓缁?/p>

婧愮▼搴忓涓嬶細

  1 #include<stdio.h>
  2 #include<conio.h>
  3 #include<math.h>
  4 #include<string.h>
  5 #include<stdlib.h>
  6 
  7 int i, row = 0, line = 0;
  8 char test[1000];  //test鏂囦欢涓殑瀛楃 
  9 int number[100];    //甯告暟琛?
 10 char mark[100][5];   //鏍囪瘑绗﹁〃
 11 
 12 //璇嶆硶鍒嗘瀽
 13 int wordanalysis()
 14 {
 15     //鏍囪瘑绗﹀拰淇濈暀瀛?/span>
 16     if ((test[i] >= 鈥?/span>A鈥?/span>&&test[i] <= 鈥?/span>Z鈥?/span>)||(test[i]>=鈥?/span>a鈥?/span>&&test[i]<=鈥?/span>z鈥?/span>))  
 17     {
 18         char word[10];
 19         //淇濈暀瀛楄〃
 20         char pro[100][100] = { "PROGRAM", "BEGIN", "END", "VAR", "INTEGER", "WHILE",
 21                                  "IF", "THEN", "ELSE", "DO", "PROCEDURE" ,"char",
 22                                 "int","if","else","var" ,"return","break",
 23                                 "do","while","for","double","float","short"}; 
 24 
 25         int n = 0;
 26         word[n++] = test[i++];
 27         while ((test[i] >= 鈥?/span>A鈥?/span>&&test[i] <= 鈥?/span>Z鈥?/span>) || (test[i] >= 鈥?/span>0鈥?/span> && test[i] <= 鈥?/span>9鈥?/span>)||(test[i]>=鈥?/span>a鈥?/span>&&test[i]<=鈥?/span>z鈥?/span>))
 28         {
 29             word[n++] = test[i++];
 30         }
 31         word[n] = 鈥?/span>鈥?/span>;
 32         i--;
 33 
 34         //鍒ゆ柇璇ユ爣璇嗙鏄惁涓轰繚鐣欏瓧
 35         for (n = 0; n < 100; n++)
 36         {
 37             if (strcmp(word, pro[n]) == 0)
 38             {
 39                 printf(">> %s	(%d,-) 淇濈暀瀛梊n", pro[n], n + 1);
 40                 return 3;
 41             }
 42         }
 43 
 44         //鍒ゆ柇璇ユ爣璇嗙鏄惁鍦ㄦ爣璇嗙琛ㄤ腑
 45         int m = 0;
 46         if (line != 0)
 47         {
 48             int q = 0;
 49             while (q<line)
 50             {
 51                 if (strcmp(word, mark[q++]) == 0)
 52                 {
 53                     printf(">> %s	(10,%d) 鏍囪瘑绗n", word, q);
 54                     return 3;
 55                 }
 56             }
 57 
 58         }
 59 
 60         //灏嗚鏍囪瘑绗︿繚瀛樺埌鏍囪瘑绗﹁〃涓?/span>
 61         strcpy(mark[line], word);
 62         
 63         printf(">> %s	(10, %d) 鏍囪瘑绗n", word, line + 1);
 64         line++;
 65         return 3;
 66 
 67     }
 68     //鏁板瓧 
 69     else if (test[i] >= 鈥?/span>0鈥?/span> && test[i] <= 鈥?/span>9鈥?/span>)  
 70     {
 71         char x[100];
 72         int n = 0;
 73         x[n++] = test[i++];
 74         
 75         while (test[i] >= 鈥?/span>0鈥?/span> && test[i] <= 鈥?/span>9鈥?/span>)
 76         {
 77             x[n++] = test[i++];
 78         }
 79         x[n] = 鈥?/span>鈥?/span>;
 80         i--;
 81         int num = atoi(x); //灏嗗瓧绗︿覆杞崲鎴恑nt鍨?
 82         
 83         //鍒ゆ柇璇ュ父鏁版槸鍚﹀瓨鍦ㄤ簬甯告暟琛ㄤ腑
 84         if (row != 0)
 85         {   
 86             
 87             for(int y=0;y<row;y++)
 88             {
 89                 if(number[y]==num)
 90                 {
 91                     printf(">> %d	(11,%d)
", num, y + 1);
 92                     return 3;
 93                 }
 94             }
 95         }
 96         
 97         //灏嗚甯告暟淇濆瓨鍒版爣璇嗙琛ㄤ腑
 98         number[row]=num;
 99         
100 
101         int line = row;
102         printf(">> %d	(11,%d)
", num, line + 1);
103         row++;
104 
105         return 3;
106     }
107     
108     //鍚勭绗﹀彿
109     else                      
110         switch (test[i])
111     {
112         case 鈥?/span> 鈥?/span>:
113         case 鈥?/span>
鈥?/span>:
114             return -1;
115         case 鈥?/span>#鈥?/span>: return 0;
116         case 鈥?/span>=鈥?/span>:printf(">> =	(25,-)
"); return 3;
117         case 鈥?/span><鈥?/span>:
118             i++;
119             if (test[i] == 鈥?/span>=鈥?/span>)
120             {
121                 printf(">> <= 	(21,-)
");
122                 return 3;
123             }
124             else if (test[i] == 鈥?/span>>鈥?/span>)
125             {
126                 printf(">> <>	(22,-)
");
127                 return 3;
128             }
129             else
130             {
131                 i--;
132                 printf(">> <	(20,-)
");
133                 return 3;
134             }
135         case 鈥?/span>>鈥?/span>:
136             i++;
137             if (test[i] == 鈥?/span>=鈥?/span>)
138             {
139                 printf(">> >=	(24,-)
");
140                 return 3;
141             }
142             else
143             {
144                 i--;
145                 printf(">> >	(23,-)
");
146                 return 3;
147             }
148         case 鈥?/span>+鈥?/span>: printf(">> +	(13,-)
"); return 3;
149         case 鈥?/span>-鈥?/span>: printf(">> -	(14,-)
"); return 3;
150         case 鈥?/span>*鈥?/span>: printf(">> *	(15,-)
"); return 3;
151         case 鈥?/span>/鈥?/span>: 
152             i++;
153             if(test[i]!=鈥?/span>/鈥?/span>){
154                 i--;
155                 printf(">> /	(16,-)
"); return 3;
156             }
157 
158             else{
159 
160                 while(1){
161                     if(test[i++]==鈥?/span>
鈥?/span>)
162                         return -1;
163                 }
164                 printf(">> //	(37,-)
");return 3;
165 
166             }
167 
168         case 鈥?/span>:鈥?/span>: printf(">> :	(17,-)
"); return 3;
169         case 鈥?/span>;鈥?/span>: printf(">> ;	(26,-)
"); return 3;
170         case 鈥?/span>(鈥?/span>: printf(">> (	(27,-)
"); return 3;
171         case 鈥?/span>)鈥?/span>: printf(">> )	(28,-)
"); return 3;
172 
173     }
174 
175 }
176 
177 int main()
178 {
179 
180     int c = 0;
181     int m;
182     i = 0;
183     FILE *fp;
184     fp=fopen(".	est.txt","r");
185     if (fp == NULL)
186     {
187         printf("can鈥榯 open file!
");
188         exit(0);
189     }
190 
191     while (!feof(fp))
192     {
193         test[c++] = fgetc(fp);
194     }
195     test[c] = 鈥?/span>#鈥?/span>;
196     do
197     {
198         m = wordanalysis();
199 
200         switch (m)
201         {
202         case -1:i++; break;
203         case 0: i++; break;
204         case 3: i++; break;
205         }
206     } while (m != 0);
207 
208 
209     return 0;
210 }

 娴嬭瘯浠g爜鏂囦欢濡備笅锛?/p>

include <stdio.h>
int main(void)
{
	int a[3][4]={{1,3,5,7},
	{9,11,13,15},
	{17,19,21,23}
	
	};
	
int *p,line;

for(line=0;line<3;line++)
{
	for(p=a[line];p<a[line]+4;p++)
		printf("%4d",*p);
	putchar(鈥榎n鈥?;
}
return 0;
} 

銆€銆€

 杩愯缁撴灉锛?/p>

鎶€鏈浘鐗? src=

 

以上是关于璇嶆硶鍒嗘瀽绋嬪簭鐨勮璁′笌瀹炵幇的主要内容,如果未能解决你的问题,请参考以下文章

鎵嬫捀Spring妗嗘灦锛岃璁′笌瀹炵幇璧勬簮鍔犺浇鍣紝浠嶴pring.xml瑙f瀽鍜屾敞鍐孊ean瀵硅薄

鏁版嵁鍒嗘瀽濡備綍鍔╁姏淇濋櫓琛屼笟瀹炵幇鐪熸鐨勨€滄寜闇€鈥濇湇鍔★紵

澶╃尗棣栭〉UI灞傛涓庣被璁捐鍒嗘瀽

鏂规璁捐锛氬熀浜嶪DEA鎻掍欢寮€鍙戝拰瀛楄妭鐮佹彃妗╂妧鏈紝瀹炵幇鐮斿彂浜や粯璐ㄩ噺鑷姩鍒嗘瀽

鍩虹绠楁硶鍒嗘瀽