Commits

Weisi Dai committed ea9b249

added compile_hw3

Comments (0)

Files changed (1)

+% multiple1902 <multiple1902@gmail.com>
+% public on https://bitbucket.org/multiple1902/homework
+% licensed under cc by-sa 3.0
+\documentclass[12pt]{article}
+\def\course{编译原理}
+\def\homeworkid{3}
+\usepackage{amsthm,amssymb,fullpage}
+\usepackage{enumerate}
+\usepackage[slantfont,boldfont,CJKnumber,CJKtextspaces,CJKmathspaces]{xeCJK}
+\usepackage{tabularx}
+\usepackage{booktabs}
+\usepackage{multicol}
+\usepackage[
+    colorlinks, %linkcolor=blue,anchorcolor=blue,citecolor=green,
+    pdfcreator={TeX}, pdftitle={\course 作业\homeworkid},
+    pdfauthor={multiple1902@gmail.com}
+    ]{hyperref}
+\def\UrlBreaks{\do-\do_}
+\setCJKmainfont{細明體}
+\setCJKsansfont{微軟正黑體}
+\newcommand{\problem}[1]{
+    \noindent \hskip 0.05\linewidth \fbox{\parbox{0.9\linewidth}{#1}} \\
+}
+\usepackage{pstricks}
+\usepackage{pst-node}
+
+\begin{document}
+
+\noindent\begin{tabularx}{\linewidth}{|X|}
+\hline \vskip -2mm
+{\sf \course} \hfill \today \\
+{\centering \sf \large
+Homework \homeworkid \\ }
+计算机92班 \hfill 戴唯思 09055029 \\ \hline
+\end{tabularx}
+
+\section*{1}
+
+    \problem{考虑下面文法$G_1$:
+    \[S\to A|\wedge|(T)\]
+    \[T\to T,S|S\]
+    消去$G_1$的左递归, 然后对每个非终结符, 写出不带回溯的递归子程序.
+    }
+
+\section*{2}
+
+    \problem{对下面的文法$G$:
+
+    \[E\to TE'\]
+    \[E'\to+E|\varepsilon\]
+    \[T\to FT'\]
+    \[T'\to T|\varepsilon\]
+    \[F\to PF'\]
+
+    \begin{enumerate}
+        \item 计算这个文法的每个非终结符的FIRST和FOLLOW;
+            \setcounter{enumi}{2}
+        \item 构造它的预测分析表.
+    \end{enumerate}
+    }
+
+\section*{3}
+
+    \problem{下面文法中, 哪些是LL(1)的, 说明理由.
+
+    \begin{multicols}{2}
+        \begin{enumerate}
+            \item \[S\to Abc\]
+                \[A\to a|\varepsilon\]
+                \[B\to b|\varepsilon\]
+                \setcounter{enumi}{2}
+            \item \[S\to ABBA\]
+                \[A\to a|\varepsilon\]
+                \[B\to b|\varepsilon\]
+        \end{enumerate}
+    \end{multicols}
+
+    }
+
+\section*{4}
+
+    \problem{对以下文法:
+    \[Expr\to -Expr\]
+    \[Expr\to(Expr)|var\ ExprTail\]
+    \[ExprTail\to-Expr|\varepsilon\]
+    \[Var\to id\ VarTail\]
+    \[VarTail\to(Expr)|\varepsilon\]
+
+    \begin{enumerate}
+        \item 构造LL(1)分析表;
+        \item 给出对句子$id---id( (id) )$的分析过程.
+    \end{enumerate}
+
+    }
+
+\section*{5}
+
+\section*{补充题}
+
+    \problem{文法如下:
+    \begin{multicols}{3}
+        \begin{enumerate}
+            \item $E\to TE'$
+            \item $E'\to +TE'|\varepsilon$
+            \item $T\to FT'$
+            \item $T'\to*FT'|\varepsilon$
+            \item $F\to(E)|i$
+        \end{enumerate}
+    \end{multicols}
+
+    对$i_1i_4+i_2*i_3$和$i_1+i_2*i_3i_5$分析器如何动作, 是何结果?
+    }
+
+    \begin{enumerate}
+        \item $i_1i_4+i_2*i_3$
+            \begin{center}
+                \begin{tabular}{lll}\toprule
+                    栈 & 输入 & 输出 \\ \midrule
+                    %$\#E$ & $i_1i_4+i_2*i_3$ &  \\
+                    $\#E$ & $\underline{i_1}i_4+i_2*i_3$ & \\
+                    $\#E'T$ & $\underline{i_1}i_4+i_2*i_3$ & $E\to TE'$\\
+                    $\#E'T'F$ & $\underline{i_1}i_4+i_2*i_3$ & $T\to T'F$\\
+                    $\#E'T'i$ & $\underline{i_1}i_4+i_2*i_3$ & $F\to i$\\
+                    $\#E'T'$ & $\phantom{i_1}\underline{i_4}+i_2*i_3$ & \\
+                    $\#E'\underline{T'}$ & $\phantom{i_1}\underline{i_4}+i_2*i_3$ & error\\
+                    \bottomrule
+                \end{tabular}
+            \end{center}
+
+            匹配失败.
+        \item $i_1+i_2*i_3i_5$
+            \begin{center}
+                \begin{tabular}{lll}\toprule
+                    栈 & 输入 & 输出 \\ \midrule
+                    %$\#E$ & $i_1+i_2*i_3i_5$ & \\
+                    $\#E$ & $\underline{i_1}+i_2*i_3i_5$ & \\
+                    $\#E'T$ & $\underline{i_1}+i_2*i_3i_5$ & $E\to TE'$\\
+                    $\#E'T'F$ & $\underline{i_1}+i_2*i_3i_5$ & $T\to FT'$\\
+                    $\#E'T'$ & $\phantom{i_1}\,\underline{+}\,i_2*i_3i_5$ & $F\to i_1$\\
+                    $\#E'$ & $\phantom{i_1}\,\underline{+}\,i_2*i_3i_5$ & $T'\to\varepsilon$\\
+                    $\#E'T+$ & $\phantom{i_1}\,\underline{+}\,i_2*i_3i_5$ & $E'\to +TE'$\\
+                    $\#E'T$ & $\phantom{i_1+}\,\,\underline{i_2}*i_3i_5$ & 匹配$+$\\
+                    $\#E'T'F$ & $\phantom{i_1+}\,\,\underline{i_2}*i_3i_5$ & $T\to FT'$\\
+                    $\#E'T'$ & $\phantom{i_1+i_2}\,\,\underline{*}i_3i_5$ & $F\to i_2$\\
+                    $\#E'T'F*$ & $\phantom{i_1+i_2}\,\,\underline{*}i_3i_5$ & $T'\to*FT$\\
+                    $\#E'T'F$ & $\phantom{i_1+i_2*}\,\,\underline{i_3}i_5$ & 匹配$*$\\
+                    $\#E'T'$ & $\phantom{i_1+i_2*i_3}\underline{i_5}$ & $F\to i_3$\\
+                    $\#E'\underline{T'}$ & $\phantom{i_1+i_2*i_3}\underline{i_5}$ & error\\
+                    \bottomrule
+                \end{tabular}
+            \end{center}
+
+            匹配失败.
+
+    \end{enumerate}
+
+
+\end{document}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.