91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

(1)輸入任意文法,消除左遞歸和公共左因子;   (2)打印文法的First和Follow集;   (3)判斷是否是LL(1)文法,如果是則打印其分析表;   (4)輸入一個(gè)句子,如果該句子合法則輸出與句子對(duì)應(yīng)的語法樹;    能夠輸出分析過程中每一步符號(hào)棧的變化情況。    如果該句子非法則進(jìn)行相應(yīng)的報(bào)錯(cuò)處理。

資源截圖

代碼片段和文件信息

/*************************************************************************
>?File?Name:?analyse_stack.c
>?Author:?zhanglp
>?Mail:?zhanglp92@gmail.com?
>?Blog:?http://blog.csdn.net/zhanglpql?
>?Github:?http://github.com/zhanglp92?
>?Created?Time:?2014年06月04日?星期三?22時(shí)55分33秒
?************************************************************************/

#include?
#include?
#include?
#include?
#include?
#include?

static?int?push_stack?(struct?ana_stack?*s?const?char?*str)
{
????/*?擴(kuò)展表的長度?*/
????if?(s->cnt?>=?s->size)?{
????????
????????s->size?=?(s->size?+?1)?<????????if?(?NULL?==?(s->stack?=?realloc?\
????????????(s->stack?sizeof?(struct?node)?*?s->size?+?1))?)
????????????????return?ALLOC_F;
????}
????memset?(s->stack+s->cnt?0?sizeof?(struct?ne_sign)?*?(s->size?-?s->cnt));

????/*?入棧?*/
????strncpy?(s->stack[s->cnt].val?str?strlen?(str));
????s->top?=?s->cnt++;

????return?SUCCESS;
}

static?void?pop_stack?(struct?ana_stack?*s)
{
????if?(0?>=?s->cnt)?
????????return?;

????memset?(s->stack[s->top].val?0?sizeof?(struct?ne_sign));
????s->top?-=?1;
????s->cnt?-=?1;
}

static?void?display?(struct?ana_stack?s?const?char?*str?const?char?*note)
{
????#define?MAX_LEN?????30
????int?????i?t?len?=?MAX_LEN;
????char????buf[NODE_MAX+1]?=?{0};

????for?(i?=?0;?i?
????????t?=?strlen?(s.stack[i].val);
????????snprintf?(buf+MAX_LEN-len?t+1?“%s“?s.stack[i].val);
????????len?-=?t;
????}
????memset?(buf+(MAX_LEN?-?len)?‘?‘?len);
????printf?(“|?%s?“?buf);

????memset?(buf?0?MAX_LEN+1);
????t?=?strlen?(str);
????memset?(buf?‘?‘?MAX_LEN?-?t);
????strncat?(buf?str?t);
????printf?(“|%s?“?buf);

????printf?(“|?%s?\n“?note);

????memset?(buf?‘-‘?(MAX_LEN+2)?*?2);
????printf?(“?%s\n“?buf);
????#undef?MAX_LEN
}

static?const?char*?get_top?(const?struct?ana_stack?s)
{
????return?0?>=?s.cnt???NULL?:?s.stack[s.top].val;
}

static?int?add_node?(struct?tree_node?**tree?TYPE?who?const?char?*str);

/*?返回附注信息?*/
static?const?char*?analyse_str?(struct?ana_stack?*s?struct?ana_table?an?char?e?int?*pos?struct?tree_node?**tree)
{
????/*?返回附注信息?*/
????static?char?str[NODE_MAX];

????int?index_t?rs_t?index_i?rs_i;
????const?char?*top?=?get_top?(*s);

????/*?棧為空的清況?*/
????if?(NULL?==?top)?
????????return?STACK_EMPTY;

????/*?棧頂和輸入字符在分析表的位置?*/
????rs_t?=?is_e_ne_sign?(an?top?&index_t);
????char????ch[2]?=?{e?0};?/*?將字符變成字符串?*/
????rs_i?=?is_e_ne_sign?(an?ch?&index_i);

????/*?輸入字符串有不能識(shí)別的字符?則跳過該字符?*/?
????if?(ERROR?==?rs_i?||?NE_SIGN?==?rs_i)?{?

????????*pos?+=?1;
????????return?STR_ERROR;
????}

????/*?終結(jié)符匹配,成功則出棧?*/?
????else?if?(E_SIGN?==?rs_t)?{

????????if?(index_t?==?index_i)?{?

????????????*pos?+=?1;?
????????????pop_stack?(s);?
#if?1
????????????/*?找到對(duì)應(yīng)的棧頂元素?*/
????????????while?(?(*tree)->pre?)?{

????????????????if(?(*tree)->bother?)?{

????????????????????*tree?=?(*tree)->bother;
????????????????????break;
????????????????}?else?*tree?=?(*tree)->pre;

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-06-18?12:45??語法分析\
?????文件??????536576??2014-06-18?12:34??語法分析\語法分析.doc
?????目錄???????????0??2014-06-18?12:12??語法分析\analyze-sentence\
?????文件????????1148??2014-06-05?12:53??語法分析\analyze-sentence\Makefile
?????文件??????102114??2014-06-18?07:09??語法分析\analyze-sentence\Doxyfile
?????文件???????50936??2014-06-18?12:12??語法分析\analyze-sentence\a.out
?????目錄???????????0??2014-06-18?11:10??語法分析\analyze-sentence\src\
?????文件????????2343??2014-06-05?15:20??語法分析\analyze-sentence\src\tools.c
?????文件????????6631??2014-06-04?11:31??語法分析\analyze-sentence\src\first_follow.c
?????文件????????2291??2014-06-04?10:32??語法分析\analyze-sentence\src\decide_LL1.c
?????文件????????8904??2014-06-05?15:32??語法分析\analyze-sentence\src\clean_recursion_L.c
?????文件????????3817??2014-06-04?11:32??語法分析\analyze-sentence\src\analyse_table.c
?????文件???????10463??2014-06-12?09:14??語法分析\analyze-sentence\src\analyse_stack.c
?????文件????????1744??2014-06-18?08:45??語法分析\analyze-sentence\src\sentence.c
?????目錄???????????0??2014-06-18?07:06??語法分析\analyze-sentence\sentence\
?????文件??????????26??2014-06-04?11:15??語法分析\analyze-sentence\sentence\file4
?????文件??????????58??2014-06-02?12:44??語法分析\analyze-sentence\sentence\file3
?????文件??????????29??2014-06-04?11:15??語法分析\analyze-sentence\sentence\file2
?????文件??????????24??2014-06-04?10:31??語法分析\analyze-sentence\sentence\file1
?????目錄???????????0??2014-06-12?09:14??語法分析\analyze-sentence\include\
?????文件????????1002??2014-06-05?11:03??語法分析\analyze-sentence\include\tools.h
?????文件?????????574??2014-06-05?13:57??語法分析\analyze-sentence\include\sentence.h
?????文件????????2970??2014-06-09?15:36??語法分析\analyze-sentence\include\my_types.h
?????文件????????2601??2014-06-04?11:31??語法分析\analyze-sentence\include\first_follow.h
?????文件?????????583??2014-06-04?10:24??語法分析\analyze-sentence\include\decide_LL1.h
?????文件????????2780??2014-06-04?11:27??語法分析\analyze-sentence\include\clean_recursion_L.h
?????文件?????????672??2014-06-05?11:30??語法分析\analyze-sentence\include\analyse_table.h
?????文件????????1423??2014-06-12?09:14??語法分析\analyze-sentence\include\analyse_stack.h
?????目錄???????????0??2014-06-18?10:59??語法分析\analyze-sentence\doxy\
?????目錄???????????0??2014-06-18?07:53??語法分析\analyze-sentence\doxy\html_foot\
?????目錄???????????0??2014-06-18?07:47??語法分析\analyze-sentence\doxy\img\
............此處省略967個(gè)文件信息

評(píng)論

共有 條評(píng)論

相關(guān)資源