Grammar Analysis
Abstract—LL(1) grammar is obvious and can be determined ameliorated LL(2) analyzing method ,which greatly simplifies
easily. LL(1) grammar is used widely, but LL(1) grammar can LL(2) analyzing program.
only express little language information. LL(1) grammar can not
meet practicality request in most circumstances. The LL(k)
grammar can express much more language information than II. A BRIEF INTRODUCE OF LL FORECAST AND ANALYSIS
LL(1) grammar in compiling principles, but LL(k) analyzing METHOD
program is much more complex. It is not be used widely in
practical syntax analysis programs. The improved LL(2) A. LL(1) grammar and forecast analysis table
analyzing method greatly simplifies primary syntax analyzing
program. The method only adopts to see a sign ahead with a part If G=(VNˈVTˈPˈS) is a grammar that is independent
of regulation formulas, which enhances the practicability of of context. VN is not-end character collection. VT is a end
LL(2) analyzing program. Therefore, improved forecasting character collection. P is regulation formula. S is initialization
analyzer has easier and higher efficiency. If a grammar is LL(2) symbol. Suppose the # is end character of input strings. Then
grammar rather than LL(1) grammar, above improved there is following definition:
forecasting analysis method may be adopted to get better results. * a£, aęVT, Į,ȕęV* }
First (Į) = {a |¢=>
Keywords-Grammar; Sign cluster; Regulation formula Follow(A) = {a | S => * · · · Aa· · · , aęVT, AęVN }
In logic, the LL forecasting analyzer consists of total Follow[k](A) is called subsequence [k]collection of variable
control program, a forecasting analysis table and a analysis A. Those elements in the collection are strings whose length is
shed, as figure 1 shows. k and that is composed of those symbols in VT and symbol #.
The definition of LL(k) is : if a grammar that is
independent of context is a LL(k) grammar, then adequate and
Input necessary condition is that for every not-end symbol A, two
a1 a2 ... ai ... an # different rule formula AĺĮ and Aĺȕ, following
cluster
circumstance come into existence:
Ĥŀ(First1[k](Į,First1[k](ȕ),
H[k](First2[k](Į)·Follow[k](A)),
xj H[k](First2[k](ȕ)·Follow[k](A))) = ĭ
Total control program Output In above expression, left expressions express clash
. collection of LL(k) collection.
.
. Suppose that there is a grammar G ˷ P ˹ that is
Analysis table independent of context:
x1
# 1) PėeDeS
2) Dėd;D
3) Dėd
Figure 1. LL forecasting analyzer
4) Sės;S
5) Sės
B. LL(k) grammar and forecast analysis table
The former work may be extend to previous row k It can be prove that G[P] is LL(2) grammar rather than
symbols, thereby getting the definition of LL(k) grammar. LL(1) grammar, according to above definition. The
Suppose that Į, Ȝ, Ș denote a sign cluster, P, Q, Q1, Q2, …, Qn constructing method of LL(2) analysis table is similar to the
denote a set of a sign cluster. Respectively define: constructing method of LL(1). Table 2 shows analysis table of
G[P].
Į·Q={Įȕ|ȕ Q}
Ĥ Į·Q=P·Q
TABLE 2 FORECAST AND ANALYSIS TABLE OF G[P] LL(2)
ĮęP
H[k](Q)={Į|ĮȕęQ, |Į|=k, |ȕ|0, Not-end end symbol
Or ĮęQ, |Į|<k} symbol ed d; de s; s#
n −1 n P 1
(Q1 , Q2 ,..., Qn ) = (Qi Q j ) D 2 3
i =1 j = i +1
S 4 5
Call Qi,( i=1, 2, …, n) is root set of Ĥģ(Q1, Q2, …, Qn).
We can know that if Ĥģ(Q1, Q2, …, Qn)= , then Q1,
Q2, … ,Qn can not cut each two other. III. THE IMPROVED OF AMELIORATED LL(2) FORECASTING
Suppose that k1, there is following definition: AND ANALYSIS TABLE
ACKNOWLEDGMENT
This work is supported by the Foundation of Hebei
University of Science and Technology.
REFERENCE
[1] Jin Chengzhi. “Construct principle and construct technology of translate
and edit programme”. Beijing: higher education press, 2000
[2] Jiang Liyuang, Kang Muning. “The principle of translate and edit”.
Xian: northwest industry university pres, 2000
[3] Chen Huowang, Zhao Chunling, Tan Qingping. “The design language of
program principle of translate and edit”. Beijing: national defense
industry press,2000.
[4] Lv Yingzhi, Feng Jianhua. “LL(2) grammar analyzing method base –
LL(1) grammar”. The Transaction of Tsinghua University,
1997,37(1):102-105
[5] Zhang Be, Huang Tao, Fu Yuanbin. “Design and Implementation of
compiler of object description language”. The Transaction of Software,
1998,9(7):525-531
[6] Terrence W P, Marvin. V Z. “Programming Languages: Design and
Implementation”. Prentice Hall, 1996
[7] Gong Tianfu. “Program Design Language and Complier”, Publishing
Houst of Electronics Industry, 2003.
[8] M. J. C. Gordon. “Programming Language Theory and its
Implementation”. Printics Hall, 1988
[9] Hu Lunjun, Xu Lanfang, Luo Ting. “Compiler Principle”. Beijing:
Publishing House of Electronics Industry, 2005