Skip to content

Commit 529490c

Browse files
committed
Deploying to gh-pages from @ aea1ab6 🚀
1 parent e9af119 commit 529490c

File tree

4 files changed

+71
-69
lines changed

4 files changed

+71
-69
lines changed

2025/02/08/提高-ANTLR-parser-性能/index.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ <h3 id="减少语法分支"><a href="#减少语法分支" class="headerlink" tit
1515
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">indexTypeClause:</span><br><span class="line"> USING_SYMBOL indexType</span><br><span class="line"> | TYPE_SYMBOL indexType</span><br><span class="line">;</span><br><span class="line"></span><br><span class="line">indexTypeClauseOpt:</span><br><span class="line"> (USING_SYMBOL | TYPE_SYMBOL) indexType</span><br><span class="line">;</span><br></pre></td></tr></table></figure>
1616

1717
<p>在大部分场景下,可选值 <code>?</code> 性能比分支 <code>|</code> 更好。例如,假设一门语言的 if 语句的条件可以带括号,也可以不带</p>
18+
<!-- TODO: 例子不太好,括号应该成对出现 -->
19+
1820
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ifStatement:</span><br><span class="line"> &#x27;if&#x27; &#x27;(&#x27; expression &#x27;)&#x27;</span><br><span class="line"> | &#x27;if&#x27; expression</span><br></pre></td></tr></table></figure>
1921

2022
<p>就可以优化为</p>
2123
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ifStatement:</span><br><span class="line"> &#x27;if&#x27; (&#x27;(&#x27;)? expression (&#x27;)&#x27;)?</span><br></pre></td></tr></table></figure>
2224

23-
<h3 id="谓词"><a href="#谓词" class="headerlink" title="谓词"></a>谓词</h3><p>谓词是值 .g4 文件中用 <code>&#123;&#125;</code> 花括号包括起来的部分。这些部分需要 antlr 生成目标代码后自行编写函数实现逻辑。<br>语法分析文件中(parser.g4)谓词放到最前<br>词法分析文件中(lexer.g4)谓词放到最后</p>
25+
<h3 id="语义谓词(semantic-predicates)"><a href="#语义谓词(semantic-predicates)" class="headerlink" title="语义谓词(semantic predicates)"></a>语义谓词(semantic predicates)</h3><p>语义谓词是指 .g4 文件中用 <code>&#123;&#125;</code> 花括号包括起来的部分。这些部分需要 antlr 生成目标代码后自行编写函数实现逻辑。<br>语法分析文件中(parser.g4)谓词放到最前<br>词法分析文件中(lexer.g4)谓词放到最后</p>
2426
<h3 id="使用最新的-antlr-来生成目标代码"><a href="#使用最新的-antlr-来生成目标代码" class="headerlink" title="使用最新的 antlr 来生成目标代码"></a>使用最新的 antlr 来生成目标代码</h3><p>antlr 是个比较活跃的项目,更新还是比较频繁的。</p>
2527
<ul>
2628
<li>4.10:2022 年 4 月 11 日</li>
@@ -29,5 +31,5 @@ <h3 id="使用最新的-antlr-来生成目标代码"><a href="#使用最新的-a
2931
<li>4.13:2023 年 5 月 21 日</li>
3032
</ul>
3133
<p>例如以前只有 JavaScript 版本目标代码,现在 TypeScript 也有了。另外新版本通常会有性能优化。</p>
32-
<h2 id="重要参考资料"><a href="#重要参考资料" class="headerlink" title="重要参考资料"></a>重要参考资料</h2><p><a target="_blank" rel="noopener" href="https://tomassetti.me/improving-the-performance-of-an-antlr-parser/">https://tomassetti.me/improving-the-performance-of-an-antlr-parser/</a><br><a target="_blank" rel="noopener" href="https://groups.google.com/g/antlr-discussion/c/PpgPQU5jA3Q/m/P4K6Y0BXBQAJ">https://groups.google.com/g/antlr-discussion/c/PpgPQU5jA3Q/m/P4K6Y0BXBQAJ</a></p>
34+
<h2 id="重要参考资料"><a href="#重要参考资料" class="headerlink" title="重要参考资料"></a>重要参考资料</h2><p><a target="_blank" rel="noopener" href="https://tomassetti.me/improving-the-performance-of-an-antlr-parser/">https://tomassetti.me/improving-the-performance-of-an-antlr-parser/</a><br><a target="_blank" rel="noopener" href="https://groups.google.com/g/antlr-discussion/c/PpgPQU5jA3Q/m/P4K6Y0BXBQAJ">https://groups.google.com/g/antlr-discussion/c/PpgPQU5jA3Q/m/P4K6Y0BXBQAJ</a><br><a target="_blank" rel="noopener" href="https://github.com/antlr/antlr4/issues/4613">https://github.com/antlr/antlr4/issues/4613</a></p>
3335
</div><div class="tags"><a href="/blog/tags/antlr4/"><i class="fa fa-tag"></i>antlr4</a><a href="/blog/tags/antlr/"><i class="fa fa-tag"></i>antlr</a><a href="/blog/tags/compiler/"><i class="fa fa-tag"></i>compiler</a></div><div class="post-nav"><a class="next" href="/blog/2025/01/17/LSP3/">LSP 与 VS Code 插件开发(三)语言服务器协议</a></div><div class="giscus"></div><script src="https://giscus.app/client.js" data-repo="imbant/blog" data-repo-id="MDEwOlJlcG9zaXRvcnkyNDkzOTc0NDM=" data-category="General" data-category-id="DIC_kwDODt2Aw84Ch79K" data-mapping="pathname" data-strict="0" data-reactions-enabled="1" data-emit-metadata="0" data-input-position="bottom" data-theme="preferred_color_scheme" data-lang="zh-CN" crossorigin="anonymous" async></script></div></div></div><div class="pure-u-1-4 hidden_mid_and_down"><div id="sidebar"><div class="widget"><form class="search-form" action="//www.google.com/search" method="get" accept-charset="utf-8" target="_blank"><input type="text" name="q" maxlength="20" placeholder="Search"/><input type="hidden" name="sitesearch" value="https://imbant.github.io/blog"/></form></div></div></div><div class="pure-u-1 pure-u-md-3-4"><div id="footer"><span id="footer-copyright">Copyright © </span><a href="/blog/." rel="nofollow">imbAnt's blog.</a> Powered by<a rel="nofollow" target="_blank" href="https://hexo.io"> Hexo.</a><a rel="nofollow" target="_blank" href="https://github.com/tufu9441/maupassant-hexo"> Theme</a> by<a rel="nofollow" target="_blank" href="https://github.com/pagecho"> Cho.</a><script>const tag = document.getElementById('footer-copyright');const year = new Date().getFullYear();tag.innerText += year + ' ';</script></div></div></div><a class="show" id="rocket" href="#top"></a><script type="text/javascript" src="/blog/js/totop.js?v=1.0.0" async></script><script type="text/javascript" src="//cdn.jsdelivr.net/gh/fancyapps/fancybox/dist/jquery.fancybox.min.js" async></script><script type="text/javascript" src="/blog/js/fancybox.js?v=1.0.0" async></script><link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox/dist/jquery.fancybox.min.css"><script type="text/javascript" src="/blog/js/codeblock-resizer.js?v=1.0.0"></script><script type="text/javascript" src="/blog/js/smartresize.js?v=1.0.0"></script><script type="text/javascript" src="/blog/js/gifFavIcon.js"></script></div></body></html>

about/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<p>我在各个平台的昵称为:imbAnt,前缀取自 imbalance,在游戏领域意为 awesome。后缀取自高中绰号「蚂蚁」。</p>
1313
<p>即刻:<a target="_blank" rel="noopener" href="https://okjk.co/OUqto1">imbant</a></p>
1414
<p>GitHub: <a target="_blank" rel="noopener" href="https://github.com/imbant">@imbant</a></p>
15-
<p>Email: <a href="mailto:&#49;&#51;&#54;&#51;&#x34;&#55;&#x33;&#x31;&#48;&#49;&#53;&#64;&#x73;&#105;&#x6e;&#97;&#x2e;&#99;&#110;">&#49;&#51;&#54;&#51;&#x34;&#55;&#x33;&#x31;&#48;&#49;&#53;&#64;&#x73;&#105;&#x6e;&#97;&#x2e;&#99;&#110;</a></p>
15+
<p>Email: <a href="mailto:&#49;&#51;&#54;&#51;&#52;&#55;&#x33;&#x31;&#48;&#x31;&#x35;&#x40;&#x73;&#105;&#x6e;&#97;&#x2e;&#99;&#110;">&#49;&#51;&#54;&#51;&#52;&#55;&#x33;&#x31;&#48;&#x31;&#x35;&#x40;&#x73;&#105;&#x6e;&#97;&#x2e;&#99;&#110;</a></p>
1616
<p>灰机 Wiki:<a target="_blank" rel="noopener" href="https://warcraft.huijiwiki.com/wiki/%E7%94%A8%E6%88%B7:Imbant">@Imbant</a></p>
1717
<!-- LinkedIn: [查看](https://www.linkedin.com/in/%E6%98%8E%E5%AE%87-%E8%AE%B8-7b2181194/) -->
1818
</div></div></div></div><div class="pure-u-1-4 hidden_mid_and_down"><div id="sidebar"><div class="widget"><form class="search-form" action="//www.google.com/search" method="get" accept-charset="utf-8" target="_blank"><input type="text" name="q" maxlength="20" placeholder="Search"/><input type="hidden" name="sitesearch" value="https://imbant.github.io/blog"/></form></div></div></div><div class="pure-u-1 pure-u-md-3-4"><div id="footer"><span id="footer-copyright">Copyright © </span><a href="/blog/." rel="nofollow">imbAnt's blog.</a> Powered by<a rel="nofollow" target="_blank" href="https://hexo.io"> Hexo.</a><a rel="nofollow" target="_blank" href="https://github.com/tufu9441/maupassant-hexo"> Theme</a> by<a rel="nofollow" target="_blank" href="https://github.com/pagecho"> Cho.</a><script>const tag = document.getElementById('footer-copyright');const year = new Date().getFullYear();tag.innerText += year + ' ';</script></div></div></div><a class="show" id="rocket" href="#top"></a><script type="text/javascript" src="/blog/js/totop.js?v=1.0.0" async></script><script type="text/javascript" src="//cdn.jsdelivr.net/gh/fancyapps/fancybox/dist/jquery.fancybox.min.js" async></script><script type="text/javascript" src="/blog/js/fancybox.js?v=1.0.0" async></script><link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox/dist/jquery.fancybox.min.css"><script type="text/javascript" src="/blog/js/codeblock-resizer.js?v=1.0.0"></script><script type="text/javascript" src="/blog/js/smartresize.js?v=1.0.0"></script><script type="text/javascript" src="/blog/js/gifFavIcon.js"></script></div></body></html>

sitemap.txt

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
https://imbant.github.io/blog/1970/01/01/%E6%9A%82%E5%AD%98%E5%8C%BA/
2-
https://imbant.github.io/blog/2021/05/01/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/
3-
https://imbant.github.io/blog/2023/01/17/%E9%A1%B5%E9%9D%A2%E6%BB%9A%E5%8A%A8%E6%97%B6%E4%B8%BA%E4%BB%80%E4%B9%88%E6%B2%A1%E6%9C%89%E8%A7%A6%E5%8F%91%20mouseleave%20%E4%BA%8B%E4%BB%B6/
4-
https://imbant.github.io/blog/2022/04/15/%E6%BC%AB%E8%B0%88%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/
5-
https://imbant.github.io/blog/about/index.html
6-
https://imbant.github.io/blog/2019/09/11/Token-Session-Cookie/
7-
https://imbant.github.io/blog/2024/10/29/VS-Code-Thankyou/
8-
https://imbant.github.io/blog/2019/11/19/flex-box-%E4%B8%8B%E7%9A%84%E5%AE%BD%E5%BA%A6%E9%97%AE%E9%A2%98/
9-
https://imbant.github.io/blog/2020/04/07/web-%E7%A7%BB%E5%8A%A8%E7%AB%AF%E5%BC%80%E5%8F%91%E8%B8%A9%E5%9D%91/
10-
https://imbant.github.io/blog/2023/03/03/%E4%B8%BA%E4%BB%80%E4%B9%88%E5%86%99%E5%8D%9A%E5%AE%A2/
11-
https://imbant.github.io/blog/2023/07/25/%E4%BB%8E%E6%BA%90%E7%A0%81%E7%9C%8B%20Vue%20%E7%BB%84%E4%BB%B6%E9%94%80%E6%AF%81%E5%90%8E%E8%A7%A6%E5%8F%91%E5%85%B6%E4%BA%8B%E4%BB%B6/
121
https://imbant.github.io/blog/2019/10/10/%E5%85%B3%E4%BA%8E-js-%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0/
132
https://imbant.github.io/blog/2021/09/28/%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD%E7%9B%91%E6%8E%A7%E6%8C%87%E6%A0%87%E4%B8%8E%E5%AE%9E%E7%8E%B0/
143
https://imbant.github.io/blog/2021/10/22/%E5%90%8C%E6%BA%90%E7%AD%96%E7%95%A5%E4%B8%8E%E8%B7%A8%E5%9F%9F/
@@ -20,28 +9,39 @@ https://imbant.github.io/blog/2021/07/20/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E8%B7%A8%E5
209
https://imbant.github.io/blog/2023/03/30/%E6%80%8E%E4%B9%88%E8%AE%A9-favicon-%E5%8A%A8%E8%B5%B7%E6%9D%A5/
2110
https://imbant.github.io/blog/2019/08/11/%E6%8C%81%E7%BB%AD%E9%9B%86%E6%88%90/
2211
https://imbant.github.io/blog/2025/02/08/%E6%8F%90%E9%AB%98-ANTLR-parser-%E6%80%A7%E8%83%BD/
23-
https://imbant.github.io/blog/2020/03/24/TCP-%E8%BF%9E%E6%8E%A5%E7%9A%84%E7%BB%86%E8%8A%82%E8%AF%A6%E8%B0%88/
24-
https://imbant.github.io/blog/2021/04/20/JS%20%E7%9A%84%E6%95%B0%E5%80%BC/
25-
https://imbant.github.io/blog/2022/05/03/JS-defineProperty/
26-
https://imbant.github.io/blog/2020/04/13/JS-%E4%BA%8B%E4%BB%B6%E5%BE%AA%E7%8E%AF/
27-
https://imbant.github.io/blog/2020/04/20/JS-%E5%8E%9F%E5%9E%8B%E9%93%BE/
28-
https://imbant.github.io/blog/2022/08/12/JS-%E5%AF%B9%E8%B1%A1%E5%88%B0%E5%8E%9F%E5%A7%8B%E5%80%BC%E7%9A%84%E8%BD%AC%E6%8D%A2/
29-
https://imbant.github.io/blog/2022/04/30/JS-%E7%9A%84%E7%B1%BB%E5%9E%8B%E5%88%A4%E6%96%AD/
12+
https://imbant.github.io/blog/1970/01/01/%E6%9A%82%E5%AD%98%E5%8C%BA/
13+
https://imbant.github.io/blog/2021/05/01/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/
14+
https://imbant.github.io/blog/2022/04/15/%E6%BC%AB%E8%B0%88%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/
15+
https://imbant.github.io/blog/2023/01/17/%E9%A1%B5%E9%9D%A2%E6%BB%9A%E5%8A%A8%E6%97%B6%E4%B8%BA%E4%BB%80%E4%B9%88%E6%B2%A1%E6%9C%89%E8%A7%A6%E5%8F%91%20mouseleave%20%E4%BA%8B%E4%BB%B6/
16+
https://imbant.github.io/blog/about/index.html
3017
https://imbant.github.io/blog/2024/08/24/LSP1/
3118
https://imbant.github.io/blog/2019/08/09/Node-require-%E6%89%A7%E8%A1%8C%E7%BB%86%E8%8A%82/
32-
https://imbant.github.io/blog/2020/04/10/Promise-%E5%BF%85%E7%9F%A5%E5%BF%85%E4%BC%9A/
3319
https://imbant.github.io/blog/2020/03/13/React-Diffing-%E7%AE%97%E6%B3%95/
20+
https://imbant.github.io/blog/2020/04/10/Promise-%E5%BF%85%E7%9F%A5%E5%BF%85%E4%BC%9A/
3421
https://imbant.github.io/blog/2020/03/09/React-%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F/
3522
https://imbant.github.io/blog/2023/08/21/RubyConf-China-2023-%E7%AC%94%E8%AE%B0/
23+
https://imbant.github.io/blog/2019/09/11/Token-Session-Cookie/
24+
https://imbant.github.io/blog/2024/10/29/VS-Code-Thankyou/
25+
https://imbant.github.io/blog/2019/11/19/flex-box-%E4%B8%8B%E7%9A%84%E5%AE%BD%E5%BA%A6%E9%97%AE%E9%A2%98/
26+
https://imbant.github.io/blog/2020/04/07/web-%E7%A7%BB%E5%8A%A8%E7%AB%AF%E5%BC%80%E5%8F%91%E8%B8%A9%E5%9D%91/
27+
https://imbant.github.io/blog/2023/03/03/%E4%B8%BA%E4%BB%80%E4%B9%88%E5%86%99%E5%8D%9A%E5%AE%A2/
28+
https://imbant.github.io/blog/2023/07/25/%E4%BB%8E%E6%BA%90%E7%A0%81%E7%9C%8B%20Vue%20%E7%BB%84%E4%BB%B6%E9%94%80%E6%AF%81%E5%90%8E%E8%A7%A6%E5%8F%91%E5%85%B6%E4%BA%8B%E4%BB%B6/
3629
https://imbant.github.io/blog/2024/12/31/LSP2/
3730
https://imbant.github.io/blog/2025/01/17/LSP3/
31+
https://imbant.github.io/blog/2020/03/24/TCP-%E8%BF%9E%E6%8E%A5%E7%9A%84%E7%BB%86%E8%8A%82%E8%AF%A6%E8%B0%88/
3832
https://imbant.github.io/blog/2020/02/25/BrowserRouter-vs-HashRouter/
3933
https://imbant.github.io/blog/2019/12/20/CSS-%E6%96%B9%E5%BC%8F%E8%A7%A3%E5%86%B3-iOS-%E5%BE%AE%E4%BF%A1%E6%A9%A1%E7%9A%AE%E7%AD%8B%E6%95%88%E6%9E%9C%E4%B8%8E-position-fixed-%E8%81%94%E5%8A%A8%E7%9A%84%E5%9D%91/
4034
https://imbant.github.io/blog/2023/03/20/ChatGPT-%E7%9A%84%E6%B5%81%E5%BC%8F%E5%AF%B9%E8%AF%9D%E6%98%AF%E6%80%8E%E4%B9%88%E5%AE%9E%E7%8E%B0%E7%9A%84/
4135
https://imbant.github.io/blog/2021/10/02/ES6%20%E5%90%88%E9%9B%86/
4236
https://imbant.github.io/blog/2019/08/13/ES6-%E5%AF%B9%E8%B1%A1%E5%B1%9E%E6%80%A7%E7%9A%84%E7%AE%80%E5%86%99%E4%B8%8E%E8%A7%A3%E6%9E%84%E8%B5%8B%E5%80%BC/
4337
https://imbant.github.io/blog/2022/01/26/HTML-attribute-%E4%B8%8E-DOM-property-%E8%AF%A6%E8%A7%A3/
4438
https://imbant.github.io/blog/2020/10/01/JS%20%E6%A8%A1%E5%9D%97%E5%8C%96%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/
39+
https://imbant.github.io/blog/2021/04/20/JS%20%E7%9A%84%E6%95%B0%E5%80%BC/
40+
https://imbant.github.io/blog/2022/05/03/JS-defineProperty/
41+
https://imbant.github.io/blog/2020/04/13/JS-%E4%BA%8B%E4%BB%B6%E5%BE%AA%E7%8E%AF/
42+
https://imbant.github.io/blog/2020/04/20/JS-%E5%8E%9F%E5%9E%8B%E9%93%BE/
43+
https://imbant.github.io/blog/2022/08/12/JS-%E5%AF%B9%E8%B1%A1%E5%88%B0%E5%8E%9F%E5%A7%8B%E5%80%BC%E7%9A%84%E8%BD%AC%E6%8D%A2/
44+
https://imbant.github.io/blog/2022/04/30/JS-%E7%9A%84%E7%B1%BB%E5%9E%8B%E5%88%A4%E6%96%AD/
4545
https://imbant.github.io/blog
4646
https://imbant.github.io/blog/tags/Go/
4747
https://imbant.github.io/blog/tags/LSP/
@@ -75,6 +75,6 @@ https://imbant.github.io/blog/tags/antlr4/
7575
https://imbant.github.io/blog/tags/antlr/
7676
https://imbant.github.io/blog/tags/compiler/
7777
https://imbant.github.io/blog/tags/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/
78-
https://imbant.github.io/blog/tags/js/
7978
https://imbant.github.io/blog/tags/%E7%A7%BB%E5%8A%A8%E7%AB%AF/
79+
https://imbant.github.io/blog/tags/js/
8080
https://imbant.github.io/blog/tags/TCP/

0 commit comments

Comments
 (0)