-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
主题更新至3.2.1;wu-kan.github.io作为wu-kan.cn的镜像站独立;博文两篇
- Loading branch information
wu-kan
committed
May 30, 2020
1 parent
b6613cf
commit fe827d5
Showing
4 changed files
with
258 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,12 @@ jekyll-theme-WuK: # 我的主题的自定义样式都在这个命名空间 | |
rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/combine/gh/poole/[email protected]/public/css/poole.min.css,gh/poole/[email protected]/public/css/lanyon.min.css" | ||
/> | ||
- | # 引入fontawesome图标样式 | ||
# - | # 用js引入fontawesome图标样式,功能更丰富 | ||
# <script | ||
# async="async" | ||
# src="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/js/all.min.js" | ||
# ></script> | ||
- | # 用css引入fontawesome图标样式,渲染速度更快 | ||
<link | ||
rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css" | ||
|
@@ -102,7 +107,7 @@ jekyll-theme-WuK: # 我的主题的自定义样式都在这个命名空间 | |
"hidden": true, | ||
"night": "for(let i=7; i<16; ++i) if(document.body.classList.contains(`theme-base-0`+i.toString(16))) { document.body.classList.remove(`theme-base-0`+i.toString(16)); document.body.classList.add(`theme-base-0`+((i-6)%9+7).toString(16)); break; }", | ||
"content": { | ||
"link": ["https://jekyll-theme-WuK.wu-kan.cn"], | ||
"link": ["https:\/\/jekyll-theme-WuK.wu-kan.cn"], | ||
"skin": ["要换成我的朋友吗?", "让她放个假吧~"], | ||
"hidden": true, | ||
"custom": [{ | ||
|
@@ -458,6 +463,11 @@ jekyll-theme-WuK: # 我的主题的自定义样式都在这个命名空间 | |
code.language-mermaid { | ||
display: none; | ||
} | ||
.mermaid { | ||
overflow: auto auto; | ||
max-width: 100%; | ||
max-height: 50vh; | ||
} | ||
</style> | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js" | ||
|
@@ -527,6 +537,7 @@ jekyll-theme-WuK: # 我的主题的自定义样式都在这个命名空间 | |
.container.content { | ||
padding-top: 1rem; | ||
padding-bottom: 1rem; | ||
margin-bottom: 2rem; | ||
box-shadow: 0 0 .75rem rgba(0, 0, 0, 0.1); | ||
background-color: rgba(255, 255, 255, 0.95); | ||
animation-duration: 2s; | ||
|
@@ -596,16 +607,15 @@ jekyll-theme-WuK: # 我的主题的自定义样式都在这个命名空间 | |
tags: | ||
pie_chart: # 显示一个标签的饼状统计图,需要引入 mermaid | ||
enable: true | ||
prepend: <i class="fas fa-tag"></i> # 在标签页的每个标签前面显示一个图标 | ||
count: true # 统计每个标签下文章的数量 | ||
archive: | ||
group_by: '%b %Y' # 见<https://liquid.bootcss.com/filters/date/> | ||
posts_count: | ||
enable: true # 博文数量统计 | ||
append: 篇博文。长路漫漫! # 提示语 | ||
pie_chart: # 显示一个标签的饼状统计图,需要引入 mermaid | ||
enable: true | ||
year_count: true | ||
prepend: <i class="fas fa-folder-open"></i> | ||
merger: # 打赏页,需要配置! | ||
append_to_head: | ||
- | # 需要配置的变量见<https://merger.justhx.com/cn/docs/configure> | ||
|
@@ -724,6 +734,19 @@ jekyll-theme-WuK: # 我的主题的自定义样式都在这个命名空间 | |
homePageName='回到我的主页' | ||
></script> | ||
compress_html: # <https://github.com/penibelst/jekyll-compress-html> | ||
clippings: all | ||
comments: [] # 注释不能压缩,否则 reveal.js 的 ppt切屏受影响 | ||
endings: all | ||
ignore: | ||
envs: [] | ||
blanklines: false | ||
profile: false | ||
startings: [] | ||
|
||
webmaster_verifications: # <https://jekyll.github.io/jekyll-seo-tag/usage/> | ||
baidu: szbTSfUGAB | ||
|
||
# githubpage上支持的插件见<https://pages.github.com/versions/> | ||
plugins: # <https://jekyllrb.com/docs/plugins/> | ||
- jekyll-readme-index # 使用readme做index,从而和github渲染效果一致 | ||
|
@@ -733,7 +756,7 @@ plugins: # <https://jekyllrb.com/docs/plugins/> | |
- jekyll-feed # 为站点生成RSS源 | ||
- jekyll-remote-theme # 使用remote_theme插件实现主题的前后分离,详见<https://github.com/benbalter/jekyll-remote-theme/> | ||
|
||
remote_theme: https://github.com/wu-kan/[email protected].0 #使用固定版本号以防止主题更新导致站点显示错乱 | ||
remote_theme: https://github.com/wu-kan/[email protected].1 #使用固定版本号以防止主题更新导致站点显示错乱 | ||
|
||
readme_index: # 缺失index.md和index.html时,使用README.md代替之 | ||
with_frontmatter: true # 支持带有yaml头的README | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
--- | ||
title: 文法推导 | ||
tags: 编译原理 | ||
--- | ||
|
||
[题目链接](http://soj.acmm.club/show_problem.php?pid=1000&cid=2835) | ||
|
||
Time Limit: 1sec Memory Limit: 256MB | ||
|
||
## Description | ||
|
||
$$ | ||
E\to TE' \\ | ||
E'\to +TE' \vert \epsilon \\ | ||
T\to FT' \\ | ||
T'\to *FT' \vert \epsilon \\ | ||
F\to (E) \vert \bold{id} | ||
$$ | ||
|
||
依据教材第 4.4 节文法 4.28,将其中的 id 替换为 0 到 9 的数字,对于输入的字符串,输出其最左推导的过程。如果输入的字符串不符合文法的定义,则输出"Syntax Error"。 | ||
|
||
## Input | ||
|
||
有多组测试数据,每组数据一行,包含一个字符串,字符串只包含有文法中的终端符号。字符串长度不超过 100。 | ||
|
||
输入以#号结束。 | ||
|
||
## Output | ||
|
||
对于每组数据,如果输入字符串符合文法的定义,输出其最左推导的过程,每步推导占一行;否则,输出“Syntax Error”。每组数据输出结束后再输出一个空行。 | ||
|
||
## Sample Input | ||
|
||
```bash | ||
3+5*0 | ||
1*2* | ||
# | ||
``` | ||
|
||
## Sample Output | ||
|
||
```bash | ||
E | ||
TE' | ||
FT'E' | ||
3T'E' | ||
3E' | ||
3+TE' | ||
3+FT'E' | ||
3+5T'E' | ||
3+5*FT'E' | ||
3+5*0T'E' | ||
3+5*0E' | ||
3+5*0 | ||
|
||
Syntax Error | ||
|
||
``` | ||
|
||
## Problem Source | ||
|
||
语法分析 | ||
|
||
## Solution | ||
|
||
因为看漏了文法中的括号,导致无限 WA、RE、TLE…老年人该看看眼睛了。 | ||
|
||
```cpp | ||
#include <bits/stdc++.h> | ||
#define SE "Syntax Error\n" | ||
using namespace std; | ||
struct Rule | ||
{ | ||
char prefix, eps, id; | ||
string lc, rc; | ||
}; | ||
string work(const char *b, const char *e, string r) | ||
{ | ||
static map<string, Rule> mp{ | ||
{"E", {0, 0, 0, "T", "E'"}}, | ||
{"E'", {'+', 1, 0, "T", "E'"}}, | ||
{"T", {0, 0, 0, "F", "T'"}}, | ||
{"T'", {'*', 1, 0, "F", "T'"}}, | ||
{"F", {0, 0, 1, "E", "E"}}}; | ||
if (mp[r].id) | ||
{ | ||
if (e - b == 1 && isdigit(*b)) | ||
return r + "\n" + string(1, *b) + "\n"; | ||
if (e - b < 2 || *b != '(' || *(e - 1) != ')') | ||
return SE; | ||
string s = work(b + 1, e - 1, mp[r].lc); | ||
if (s == SE) | ||
return SE; | ||
string ans = r + "\n"; | ||
for (int p = 0, q = 0; q < s.size(); ++q) | ||
if (s[q] == '\n') | ||
{ | ||
ans += "(" + s.substr(p, q - p) + ")\n"; | ||
p = q + 1; | ||
} | ||
return ans; | ||
} | ||
if (e - b == 0 && mp[r].eps) | ||
return r + "\n\n"; | ||
if (e - b == 0 && mp[r].prefix) | ||
return SE; | ||
if (e - b && mp[r].prefix && mp[r].prefix != *b) | ||
return SE; | ||
for (int i = (mp[r].prefix ? 1 : 0); i <= e - b; ++i) | ||
{ | ||
string lc = work(mp[r].prefix ? b + 1 : b, b + i, mp[r].lc); | ||
if (lc == SE) | ||
continue; | ||
string rc = work(b + i, e, mp[r].rc); | ||
if (rc == SE) | ||
continue; | ||
string ans = (mp[r].prefix ? string(1, mp[r].prefix) : "") + r + "\n", last; | ||
for (int p = 0, q = 0; q < lc.size(); ++q) | ||
if (lc[q] == '\n') | ||
{ | ||
last = (mp[r].prefix ? string(1, mp[r].prefix) : "") + lc.substr(p, q - p); | ||
ans += last + mp[r].rc + "\n"; | ||
p = q + 1; | ||
} | ||
for (int p = 0, q = 0, first = 0; q < rc.size(); ++q) | ||
if (rc[q] == '\n') | ||
{ | ||
if (first) | ||
ans += last + rc.substr(p, q - p) + "\n"; | ||
else | ||
first = 1; | ||
p = q + 1; | ||
} | ||
return ans; | ||
} | ||
return SE; | ||
} | ||
int main() | ||
{ | ||
for (char s[127]; scanf("%s", s) != EOF && strcmp("#", s);) | ||
cout << work(s, s + strlen(s), "E") << "\n"; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
title: 编译原理(五) | ||
tags: 编译原理 | ||
--- | ||
|
||
## 考虑以下文法,写出每个非终端符号的 FIRST 集和 FOLLOW 集 | ||
|
||
$$ | ||
S\to aTUV\vert bV\\ | ||
T\to U\vert UU\\ | ||
U\to\varepsilon\vert bV\\ | ||
V\to\varepsilon\vert cV | ||
$$ | ||
|
||
| | FIRST | FOLLOW | | ||
| --- | --------------- | ------------------------ | | ||
| $S$ | $a,b$ | $\text{\textdollar}$ | | ||
| $T$ | $\varepsilon,b$ | $\text{\textdollar},b,c$ | | ||
| $U$ | $\varepsilon,b$ | $\text{\textdollar},b,c$ | | ||
| $V$ | $\varepsilon,c$ | $\text{\textdollar},b,c$ | | ||
|
||
## 考虑以下文法 | ||
|
||
$$ | ||
S\to(L)\vert a\\ | ||
L\to L,S\vert S | ||
$$ | ||
|
||
### 消除文法的左递归 | ||
|
||
$$ | ||
S\to(L)\vert a\\ | ||
L\to ST\\ | ||
T\to ,ST\vert\varepsilon | ||
$$ | ||
|
||
### 构造文法的 LL(1) 分析表 | ||
|
||
根据 | ||
|
||
| | FIRST | FOLLOW | | ||
| --- | ---------------- | -------------------------- | | ||
| S | $(\ a$ | $\text{\textdollar}\ )\ a$ | | ||
| L | $(\ a$ | $)$ | | ||
| T | $,\ \varepsilon$ | $)$ | | ||
|
||
可得 | ||
|
||
| | $($ | $)$ | $a$ | $,$ | $\text{\textdollar}$ | | ||
| --- | --------- | ----------------- | --------- | --------- | -------------------- | | ||
| S | $S\to(L)$ | | $S\to a$ | | | | ||
| L | $L\to ST$ | | $L\to ST$ | | | | ||
| T | | $T\to\varepsilon$ | | $T\to,ST$ | | | ||
|
||
### 对于句子 $(a, (a, a))$,给出语法分析的详细过程(参照课本 228 页的图 4.21) | ||
|
||
| MATCH | STACK | IN | OUT | | ||
| ----------- | -------------------------- | ----------------------------- | ----------------- | | ||
| | $S\text{\textdollar}$ | $(a,(a,a))\text{\textdollar}$ | | | ||
| | $(L)\text{\textdollar}$ | $(a,(a,a))\text{\textdollar}$ | $S\to(L)$ | | ||
| $($ | $L)\text{\textdollar}$ | $a,(a,a))\text{\textdollar}$ | | | ||
| $($ | $ST)\text{\textdollar}$ | $a,(a,a))\text{\textdollar}$ | $L\to ST$ | | ||
| $($ | $aT)\text{\textdollar}$ | $a,(a,a))\text{\textdollar}$ | $S\to a$ | | ||
| $(a$ | $T)\text{\textdollar}$ | $,(a,a))\text{\textdollar}$ | | | ||
| $(a$ | $,ST)\text{\textdollar}$ | $,(a,a))\text{\textdollar}$ | $T\to,ST$ | | ||
| $(a,$ | $ST)\text{\textdollar}$ | $(a,a))\text{\textdollar}$ | | | ||
| $(a,$ | $(L)T)\text{\textdollar}$ | $(a,a))\text{\textdollar}$ | $S\to L$ | | ||
| $(a,($ | $L)T)\text{\textdollar}$ | $a,a))\text{\textdollar}$ | | | ||
| $(a,($ | $ST)T)\text{\textdollar}$ | $a,a))\text{\textdollar}$ | $L\to ST$ | | ||
| $(a,($ | $aT)T)\text{\textdollar}$ | $a,a))\text{\textdollar}$ | $S\to a$ | | ||
| $(a,(a$ | $T)T)\text{\textdollar}$ | $,a))\text{\textdollar}$ | | | ||
| $(a,(a$ | $,ST)T)\text{\textdollar}$ | $,a))\text{\textdollar}$ | $T\to,ST$ | | ||
| $(a,(a,$ | $ST)T)\text{\textdollar}$ | $a))\text{\textdollar}$ | | | ||
| $(a,(a,$ | $aT)T)\text{\textdollar}$ | $a))\text{\textdollar}$ | $S\to a$ | | ||
| $(a,(a,a$ | $T)T)\text{\textdollar}$ | $))\text{\textdollar}$ | | | ||
| $(a,(a,a$ | $)T)\text{\textdollar}$ | $))\text{\textdollar}$ | $T\to\varepsilon$ | | ||
| $(a,(a,a)$ | $T)\text{\textdollar}$ | $)\text{\textdollar}$ | | | ||
| $(a,(a,a)$ | $)\text{\textdollar}$ | $)\text{\textdollar}$ | $T\to\varepsilon$ | | ||
| $(a,(a,a))$ | $\text{\textdollar}$ | $\text{\textdollar}$ | | | ||
|
||
## 考虑以下文法,这一文法是否是 LL(1) 文法?给出理由 | ||
|
||
$$ | ||
S\to aSbS\vert bSaS\vert\varepsilon | ||
$$ | ||
|
||
不是。因为 $\bold{FIRST}(S)=\{a,b,\varepsilon\},\bold{FOLLOW}(S)=\{\text{\textdollar},a,b\}$,而且 $S\to\varepsilon$ 但 $\bold{FIRST}(S)\cap\bold{FOLLOW}(S)\neq\emptyset$,不符合 LL(1) 文法的性质。 |