ºÃÎĵµ - רҵÎÄÊéд×÷·¶ÎÄ·þÎñ×ÊÁÏ·ÖÏíÍøÕ¾

Ô¤²â·ÖÎöËã·¨µÄÉè¼ÆÓëʵÏÖ 

ÓÉ ÌìÏ ·ÖÏí ʱ¼ä£º ¼ÓÈëÊÕ²Ø ÎÒҪͶ¸å µãÔÞ

.

Ô¤²â·ÖÎöËã·¨µÄÉè¼ÆÓëʵÏÖ

³ÌÐò´úÂë:

#include \#include \

#define MaxRuleNum 8 #define MaxVnNum 5 #define MaxVtNum 5 #define MaxStackDepth 20 #define MaxPLength 20 #define MaxStLength 50

struct pRNode /*²úÉúʽÓÒ²¿½á¹¹*/ {

int rCursor;

struct pRNode *next; };

struct pNode {

int lCursor;

int rLength; /*ÓÒ²¿³¤¶È*/

struct pRNode *rHead; /*ÓÒ²¿½áµãÍ·Ö¸Õë*/ };

char Vn[MaxVnNum + 1]; /*·ÇÖÕ½á·û¼¯*/ int vnNum;

char Vt[MaxVtNum + 1]; /*ÖÕ½á·û¼¯*/ int vtNum;

struct pNode P[MaxRuleNum]; int PNum;

char buffer[MaxPLength + 1];

1 / 24'.

.

char ch;

char st[MaxStLength]; /*Òª·ÖÎöµÄ·ûºÅ´®*/

struct collectNode {

int nVt;

void ShowAT();/*Êä³ö·ÖÎö±í*/ void Identify(char *st); void InitStack(); void ShowStack(); void Pop(); void Push(int r);

int main() {

char todo,ch; Init(); InputVn(); InputVt(); InputP(); getchar(); FirstFollow();

printf(\ËùµÃfirst¼¯Îª£º\ ShowCollect(first);

printf(\ËùµÃfollow¼¯Îª£º\ ShowCollect(follow); CreateAT(); ShowAT(); todo = 'y';

while('y' == todo) {

printf(\ÊÇ·ñ¼ÌÐø½øÐоäÐÍ·ÖÎö£¿(y / n):\ todo = getchar();

while('y' != todo && 'n' != todo) {

printf(\ todo = getchar(); }

2 / 24'.

.

if('y' == todo) { int i; InitStack();

printf(\ÇëÊäÈë·ûºÅ´®(ÒÔ#½áÊø) : \ ch = getchar(); i = 0;

while('#' != ch && i < MaxStLength) {

st[i] = ch; Identify(st); } else

printf(\ÊäÈë³ö´í£¡\\n\ } }

getchar(); }

void Init() {

int i,j; vnNum = 0; vtNum = 0; PNum = 0;

for(i = 0; i <= MaxVnNum; i++) Vn[i] = '\\0';

for(i = 0; i <= MaxVtNum; i++) Vt[i] = '\\0';

for(i = 0; i < MaxRuleNum; i++) {

P[i].lCursor = NULL; P[i].rHead = NULL; P[i].rLength = 0; }

PNum = 0;

for(i = 0; i <= MaxPLength; i++) }

3 / 24'.

.

}

int IndexCh(char ch) { int n;

n = 0; /*is Vn?*/

while(ch != Vn[n] && '\\0' != Vn[n]) n++;

if('\\0' != Vn[n]) return 100 + n; n = 0; /*is Vt?*/

while(ch != Vt[n] && '\\0' != Vt[n]) n++;

if('\\0' != Vt[n]) return n; return -1; }

/*Êä³öVn»òVtµÄÄÚÈÝ*/

void ShowChArray(char* collect) {

int k = 0;

while('\\0' != collect[k]) {

printf(\ }

printf(\}

/*ÊäÈë·ÇÖÕ½á·û*/ void InputVn() { {

Vn[n++] = '\\0'; } n = 0;

while(('#' != ch) && (n < MaxVnNum)) {

if(' ' != ch && '\\n' != ch && -1 == IndexCh(ch)) {

4 / 24'.

.

Vn[n++] = ch; vnNum++; }

ch = getchar(); }

Vn[n] = '#'; /*ÒÔ\±êÖ¾½áÊøÓÃÓÚÅжϳ¤¶ÈÊÇ·ñºÏ·¨*/ k = n; if('#' != ch) {

if( '#' != (ch = getchar())) {

while('#' != (ch = getchar())) ;

printf(\·ûºÅÊýÄ¿³¬¹ýÏÞÖÆ£¡\\n\ inErr = 1; continue; } {

printf(\ÊäÈëÕýÈ·È·ÈÏ?(y/n):\ }

scanf(\ }

if('n' == ch) {

printf(\¼Èë´íÎóÖØÐÂÊäÈ룡\\n\ inErr = 1; } else {

inErr = 0; } } }

/*ÊäÈëÖÕ½á·û*/ void InputVt() {

int inErr = 1; int n,k;

5 / 24'.

Ô¤²â·ÖÎöËã·¨µÄÉè¼ÆÓëʵÏÖ 

.Ô¤²â·ÖÎöËã·¨µÄÉè¼ÆÓëʵÏÖ³ÌÐò´úÂë:#include\#include\#defineMaxRuleNum8#defineMaxVnNum5#defineMaxVtNum5#defineMaxStackDepth20#defineMaxPLength20#defineM
ÍÆ¼ö¶È£º
µã»÷ÏÂÔØÎĵµÎĵµÎªdoc¸ñʽ
1udi3733in7yqpo85se79mzf00wrvr00ivk
ÁìÈ¡¸£Àû

΢ÐÅɨÂëÁìÈ¡¸£Àû

΢ÐÅɨÂë·ÖÏí