TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Parsing command line arguments using a finite state machine and backtracking

43 点作者 elasticdog超过 10 年前

4 条评论

userbinator超过 10 年前
That was interesting to read and certainly a different approach to solving a problem, but the biggest question I had in my mind while reading the article was &quot;is it really necessary to create all this complexity --- and how does it compare to the traditional getopt()?&quot;<p>I&#x27;ve used getopt() many times, even implemented its functionality for fun, and parsing commandline arguments has never been something I thought was particularly difficult or complex.
评论 #8967338 未加载
评论 #8967528 未加载
评论 #8968322 未加载
fintler超过 10 年前
I ended up writing a blog post on how to handle CP arguments a while back. I started coding before really thinking about it -- I mean, it&#x27;s CP, how hard could it be (famous last words)?<p><a href="http://blog.typeobject.com/thinking-out-loud-file-copy-tool-arguments" rel="nofollow">http:&#x2F;&#x2F;blog.typeobject.com&#x2F;thinking-out-loud-file-copy-tool-...</a><p>It turns out the arguments to CP are really tough to reason about if you just naively dive into it. The approach in this article is much better than mine. It feels like I was fumbling around in the dark.<p>If you&#x27;re interested in seeing my implementation (it&#x27;s buggy, but handles most cases), it can be found at:<p><a href="https://github.com/hpc/dcp/blob/master/src/handle_args.c" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;hpc&#x2F;dcp&#x2F;blob&#x2F;master&#x2F;src&#x2F;handle_args.c</a><p>The entry point to handle_args.c is DCOPY_parse_path_args, which is called by the main() in:<p><a href="https://github.com/hpc/dcp/blob/master/src/dcp.c" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;hpc&#x2F;dcp&#x2F;blob&#x2F;master&#x2F;src&#x2F;dcp.c</a>
评论 #8967556 未加载
nine_k超过 10 年前
Why write an FSM and backtracking explicitly? Use parser combinators, they basically do the same thing, just express it in a clearer, grammar-friendly way: <a href="http://theorangeduck.com/page/you-could-have-invented-parser-combinators" rel="nofollow">http:&#x2F;&#x2F;theorangeduck.com&#x2F;page&#x2F;you-could-have-invented-parser...</a>
评论 #8967468 未加载
TheLoneWolfling超过 10 年前
How does this avoid the exponential-time worst-case complexity of backtracking approaches to walking NFAs?