自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Python語法的相關(guān)規(guī)則中的DFA的相關(guān)內(nèi)容的介紹

開發(fā) 后端
以下的文章是通過Lb_str代表具體符號(hào)的介紹來引出Graminit.c中定義了包括Python語法規(guī)則的DFA的相關(guān)是實(shí)際應(yīng)用方案的介紹。

我們都知道Graminit.c中定義了其中有包括Python語法規(guī)則的相關(guān)實(shí)際應(yīng)用的相關(guān)內(nèi)容,其中也包括了一些典型的類型,你如果想知道是哪四種典型的類型的話,你就可以瀏覽以下的文章對(duì)其進(jìn)行了解。

Grammar.h
Graminit.c中定義了包括Python語法規(guī)則的DFA(Deterministic Finite Automaton),關(guān)于DFA請參考Alfred V. Aho等人所著的Compilers: Principles, Techniques, and Tools一書。為了定義DFA,graminit.c引用了位于grammar.h中的一些類型:arc, state, dfa, grammar。

Label定義了從狀態(tài)轉(zhuǎn)移到另外一個(gè)狀態(tài)所經(jīng)過的邊所對(duì)應(yīng)的符號(hào),可以是非終結(jié)符(Non-Terminal),也可以是終結(jié)符(Terminal)。Label一定依附于一條或者多條邊。Lb_type代表符號(hào)的類型,如終結(jié)符NAME,代表一個(gè)標(biāo)示符,或者非終結(jié)符stmt,代表一個(gè)語句,等等。

Lb_str代表具體符號(hào)的內(nèi)容。比如,label (NAME, “if”)表示當(dāng)parser處于某個(gè)狀態(tài),如果遇到了’if’這個(gè)標(biāo)示符,則移動(dòng)另外一個(gè)狀態(tài)。如果label是一個(gè)非終結(jié)符的話,情況則要復(fù)雜一些,需要跳轉(zhuǎn)到該非終結(jié)符對(duì)應(yīng)的另外一個(gè)DFA,請參看編譯器相關(guān)書籍。

 

  1. /* A label of an arc */  
  2. typedef struct {  
  3. int lb_type;  
  4. char *lb_str;  
  5. } label;   

 

 

在Graminit.c中定義了包括Python語法規(guī)則的DFA中arc代表DFA中一個(gè)狀態(tài)到另一個(gè)狀態(tài)的弧/邊。A_lbl代表arc所對(duì)應(yīng)的Label,而a_arrow記錄了arc的目標(biāo)狀態(tài)。因?yàn)閍rc是屬于某個(gè)狀態(tài)的,因此不用紀(jì)錄arc的起始狀態(tài)。

 

  1. /* An arc from one state to another */  
  2. typedef struct {  
  3. short a_lbl; /* Label of this arc */  
  4. short a_arrow; /* State where this arc goes to */  
  5. } arc;  

 

State代表著DFA中的狀態(tài)節(jié)點(diǎn)。每個(gè)state記錄了從該state出發(fā)的邊的集合,存放在s_arc中。其他的一些成員s_lower, s_upper, s_accel, s_accept記錄了state所對(duì)應(yīng)的Accelerator,其作用會(huì)在后面講述。注意Accelerator信息并沒有定義在graminit.c中,而是在運(yùn)行時(shí)計(jì)算出來的。

 

  1. /* A state in a DFA */  
  2. typedef struct {  
  3. int s_narcs;  
  4. arc *s_arc; /* Array of arcs */  
  5. /* Optional accelerators */  
  6. int s_lower; /* Lowest label index */  
  7. int s_upper; /* Highest label index */  
  8. int *s_accel; /* Accelerator */  
  9. int s_accept; /* Nonzero for accepting state */  
  10. } state;   

 

DFA結(jié)構(gòu)中記錄了起始狀態(tài)d_initial和所有狀態(tài)的集合d_state。d_first記錄了該DFA所對(duì)應(yīng)的非終結(jié)符的firstset,也就是說,當(dāng)遇到firstset中的終結(jié)符的時(shí)候,便需要跳轉(zhuǎn)到此DFA中。d_first在后面計(jì)算Accelerators的時(shí)候會(huì)被用到。

 

  1. /* A DFA */  
  2. typedef struct {  
  3. int d_type; /* Non-terminal this represents */  
  4. char *d_name; /* For printing */  
  5. http://new.51cto.com/wuyou/int d_initial; /* Initial state */  
  6. int d_nstates;  
  7. state *d_state; /* Array of states */  
  8. bitset d_first;  
  9. } dfa;   

 

Grammar代表了Python的整個(gè)語法,記錄了所有的DFA和所有的label。G_start則是Python語法的起始symbol,一般是single_input。不過實(shí)際的起始symbol可以在創(chuàng)建Parser的時(shí)候指定,可以是single_input, file_input, eval_input中的一個(gè)。

【編輯推薦】

  1. Python語言中常用的四種工具的介紹
  2. Python語言功能中的宏編程語言的實(shí)際操作方案介紹
  3. Python unicode ascii編碼在windows中的實(shí)際應(yīng)用
  4. mod_python在性能上要優(yōu)于傳統(tǒng)CGI的緣由
  5. Python中文轉(zhuǎn)換url編碼的實(shí)際操作步驟介紹
責(zé)任編輯:佚名 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-03-25 11:30:25

2010-03-26 18:31:50

Python前景Python庫

2010-04-02 16:53:34

Oracle內(nèi)存結(jié)構(gòu)

2010-04-08 10:02:15

Oracle體系結(jié)構(gòu)

2010-03-22 14:05:08

Python字符串

2010-06-17 16:12:43

WAP協(xié)議

2010-07-20 13:07:13

SQL Server存

2009-11-26 14:33:58

Cisco路由器IOS

2010-02-01 09:18:49

C++函數(shù)指針

2010-06-08 17:30:56

IPv6協(xié)議棧

2010-04-08 10:33:08

Oracle數(shù)據(jù)庫

2010-01-27 16:56:42

Android內(nèi)核

2010-07-19 16:55:51

Telnet命令

2010-03-26 16:48:54

Python MD5

2010-01-28 16:19:39

Android She

2010-01-13 16:15:47

VB.NET消息隊(duì)列

2010-01-22 18:24:28

VB.NET重構(gòu)

2010-01-28 16:30:16

Android數(shù)據(jù)傳遞

2010-02-26 09:50:57

WCF傳輸安全機(jī)制

2010-02-25 17:57:26

WCF服務(wù)合同
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)