文件名称:operator-precedence-parser
介绍说明--下载内容均来自于网络,请自行研究使用
1、给出文法如下:
G[E]
E->T|E+T
T->F|T*F
F->i(E)
可以构造算符优先表如下:
+ * ( ) i
+
*
(
)
i
2、计算机中表示上述优先关系,优先关系的机内存放方式有两种1)直接存放,2)为优先关系建立优先函数,这里由学生自己选择一种方式;
3、给出算符优先分析算法如下:
k:=1 S[k]:=‘#’
REPEAT
把下一个输入符号读进a中;
IF S[k]∈VT THEN j:=k ELSE j:=k-1
WHILE S[j] a DO
BEGIN
REPEAT
Q:=S[j]
IF S[j-1]∈VT THEN j:=j-1 ELSE j:=j-2
UNTIL S[j] Q
把S[j+1]…S[k]归约为某个N;
k:=j+1
S[k]:=N
END OF WHILE
IF S[j] a OR S[j] a THEN
BEGIN
k:=k+1 S[k]:=a
END
ELSE ERROR
UNTIL a=‘#’
4、根据给出算法,利用适当的数据结构实现算符优先分析程序;-1 gives grammar as follows: E [E] E-> T | E+ T T-> F | T* F F-> i (E)
Operator priority table can be constructed as follows:+* () i
+
*
(
)
i
2, the computer indicated above priority, preferential relations machine memory put in two ways 1) Direct storage, 2) as a priority relationship building priority function, here by the students themselves choose a way
3, gives the operator precedence analysis algorithm is as follows:
k: = 1 S [k]: = #
REPEAT read the next input symbol into a medium IF S [k] ∈VT THEN j: = k ELSE j: = k-1 WHILE S [j] a DO BEGIN REPEAT Q: = S [j] IF S [j-1] ∈VT THEN j: = j-1 ELSE j: = j-2 UNTIL S [j] Q to S [j+ 1] ... S [k] is about a normalization N k: = j+1 S [k]: = N END OF WHILE
IF S [j] a OR S [j] a THEN BEGIN k: = k+ 1 S [k]: = a END ELSE ERROR UNTIL a = #
4, according to the given algorithm, using the appropriate data structure to achieve operator priority analysis program
G[E]
E->T|E+T
T->F|T*F
F->i(E)
可以构造算符优先表如下:
+ * ( ) i
+
*
(
)
i
2、计算机中表示上述优先关系,优先关系的机内存放方式有两种1)直接存放,2)为优先关系建立优先函数,这里由学生自己选择一种方式;
3、给出算符优先分析算法如下:
k:=1 S[k]:=‘#’
REPEAT
把下一个输入符号读进a中;
IF S[k]∈VT THEN j:=k ELSE j:=k-1
WHILE S[j] a DO
BEGIN
REPEAT
Q:=S[j]
IF S[j-1]∈VT THEN j:=j-1 ELSE j:=j-2
UNTIL S[j] Q
把S[j+1]…S[k]归约为某个N;
k:=j+1
S[k]:=N
END OF WHILE
IF S[j] a OR S[j] a THEN
BEGIN
k:=k+1 S[k]:=a
END
ELSE ERROR
UNTIL a=‘#’
4、根据给出算法,利用适当的数据结构实现算符优先分析程序;-1 gives grammar as follows: E [E] E-> T | E+ T T-> F | T* F F-> i (E)
Operator priority table can be constructed as follows:+* () i
+
*
(
)
i
2, the computer indicated above priority, preferential relations machine memory put in two ways 1) Direct storage, 2) as a priority relationship building priority function, here by the students themselves choose a way
3, gives the operator precedence analysis algorithm is as follows:
k: = 1 S [k]: = #
REPEAT read the next input symbol into a medium IF S [k] ∈VT THEN j: = k ELSE j: = k-1 WHILE S [j] a DO BEGIN REPEAT Q: = S [j] IF S [j-1] ∈VT THEN j: = j-1 ELSE j: = j-2 UNTIL S [j] Q to S [j+ 1] ... S [k] is about a normalization N k: = j+1 S [k]: = N END OF WHILE
IF S [j] a OR S [j] a THEN BEGIN k: = k+ 1 S [k]: = a END ELSE ERROR UNTIL a = #
4, according to the given algorithm, using the appropriate data structure to achieve operator priority analysis program
(系统自动生成,下载前可以参看下载内容)
下载文件列表
operator precedence parser.cpp