Out of Memory

本ブログは更新を停止しました。Aerieをよろしくお願いいたします。

目次

Blog 利用状況

ニュース

2009年3月31日
更新を停止しました。引き続きAerieを御愛顧くださいませ。
2009年2月3日
原則としてコメント受付を停止しました。コメントはAerieまでお願いいたします。
詳細は2月3日のエントリをご覧ください。
2008年7月1日
Microsoft MVP for Developer Tools - Visual C++ を再受賞しました。
2008年2月某日
MVPアワードがVisual C++に変更になりました。
2007年10月23日
blogタイトルを変更しました。
2007年7月1日
Microsoft MVP for Windows - SDKを受賞しました!
2007年6月20日
スキル「ニュース欄ハック」を覚えた!
2006年12月14日
記念すべき初エントリ
2006年12月3日
わんくま同盟に加盟しました。

カレンダー

中の人

αετο? / aetos / あえとす

シャノン? 誰それ。

顔写真

埼玉を馬鹿にする奴は俺が許さん。

基本的に知ったかぶり。興味を持った技術に手を出して、ちょっと齧りはするものの、それを応用して何か形にするまでは及ばずに飽きて放り出す人。

書庫

日記カテゴリ

コマンドラインパーサ

ちょっと実用的なコマンドラインパーサを作ろう、と思っているわけです。C# で。
困ったことに、コマンドラインパーサってのはどんなアプリでも利用可能ですから、こういうものを作ろうと思い立ってしまうと、これが出来上がるまで他のどんなアプリも作りたくなくなります。俺の悪い癖です。

で、悩んでいるのが、

  • 既存のアプリのコマンドラインの仕様を変えずに移植できるように柔軟性を持たせるか
  • このパーサライブラリを使う以上は使用可能なコマンドラインの仕様にある程度の制限があるのも止むなしとするか

ということ、とか。
まぁほら、後者の方が作るのは簡単なんですけど、前者ができるならそれに越したことは無いじゃない? みたいな。

あとは、パラメータを指定するにしても、世の中にはいろんな方式のアプリがあるわけですよ。
例えば、オプション「/foo」にパラメータ「bar」を指定するのでも、

  1. /foo bar
  2. /foo:bar
  3. /foobar

なんてのがあります。
2と3は技術的にはあまり違いはありません。見た目的には2の方が好きです。
が、1と2には大きな違いがあります。
コマンドラインは Main に文字列配列として渡されますが、1 は /foo と bar が別の要素になるのに対し、2 は単一の要素になります。
当然、1の方が解析は面倒です。「bar」を処理するときに、その前の要素が「/foo」であるか、そうでないかでは意味が違ってくるからです。
このため、コマンドラインパーサは、簡易な状態遷移機械ということになります。
ちなみに、3つの中では見た目的に1が一番好きです。

このように、コマンドの順序を意識しなければならないこともあれば、順序はどうでもいい場合もあります。
例えば、オプション /hoge と /hage があるとき、以下の2つは

  • /hoge /hage
  • /hage /hoge

どっちでもいいじゃないですか。

もっと複雑な例になると、/foo:X=1,Y=2,Z=3 なんていう例も考えられます。もちろん、/foo:Z=3,X=1,Y=2でも同じ意味でなければなりません。
正直、こんなのをパースするのは面倒です。
で、正規表現を使っちゃえばいいじゃないか、と思い立ったわけです。キャプチャしてくれますから。

ただですね、上のは敢えてスペースを詰めて1つの文字列になるように書きましたが、/foo x 1 y 2 z 3 でも同じ意味でいいじゃないかと。
で、そういう場合に、

  1. /foo
  2. /foo x
  3. /foo x 1 y
  4. /foo x 1 /bar

1~3なんかは不正なコマンドラインなわけですが、正規表現でこれらを不正だと見破るのは面倒くさいです。
4 は正当なコマンドラインですが、「/foo x 1」と「/bar」は別のオプションです。が、正規表現だと、「/foo」と「x」と「1 bar」に分けちゃったりするのです。
一番簡単な方法は、/foo:x=1 /foo:y=2 /foo:z=3 という風に書かせて、可変個引数を認めないことですが、それもかっこ悪いなぁ、と。

面倒くさいです。

投稿日時 : 2008年7月28日 14:32

Feedback

# re: コマンドラインパーサ 2008/07/28 15:58 ちゃっぴ

そう、めんどくさい。なので framework 側で用意してくれないかと。

自分で作るなら、2 ですね。それでもめんどくさいけど。

# re: コマンドラインパーサ 2008/07/28 19:20 ネタ好き未記入

Win32で便利なAPIがあったような気が・・・

# re: コマンドラインパーサ 2008/07/28 19:22 ネタ好き未記入

でも、何はともあれフルスクラッチするのが楽しいのですよね♪
私もアセンブラ言語を作って、コマンドラインで起動できるようにしようと思っています。
もちろん、既存のライブラリは使いません。
全てフルスクラッチです。
これが男のロマンだと私は思います♪

# re: コマンドラインパーサ 2008/07/28 19:44 シャノン

> なので framework 側で用意してくれないかと。

まったくです。
MFC はおせっかいなほどのパーサを備えているというのにね。

> Win32で便利なAPIがあったような気が・・・

CommandLineToArgvW かな。
これは一本の文字列をスペースで区切って配列にしてくれる関数で、Main の前段階で使うやつですね。
ところで、この関数名はどう読むんでしょうか。「コマンドライン トゥ アーグヴ ウ!」でしょうか?

> でも、何はともあれフルスクラッチするのが楽しいのですよね♪

ですね♪

> 私もアセンブラ言語を作って、コマンドラインで起動できるようにしようと思っています。
> もちろん、既存のライブラリは使いません。

俺はそこまでマゾくはなれませんorz

# re: コマンドラインパーサ 2008/07/29 6:13 ネタ好き未記入

>CommandLineToArgvW
そうこれこれ。でも、なんて読むんだろうw
MSDNには日本人向けの振り仮名が欲しいですよね。

# how to write a how to essay o68eoj 2022/09/03 19:30 Charlosmox


Cheers. I like it! https://definitionessays.com/ write my thesis

# writing out numbers in essays e67evj 2023/02/10 4:25 Albertosed


Amazing tips. Appreciate it!
https://essaywritingservicelinked.com/ thesis of phd

# custom written dissertations l11hsj 2023/02/27 9:41 Robertsaids


You said it perfectly..
buy a dissertation proposal https://dissertationwritingtops.com/ best dissertation writing

# psychology paper writing service cheap in 3 hours k840qo 2023/03/01 9:07 StevenGrelo

You actually suggested this adequately.
custom papers online https://service-essay.com/ buy college paper online

# thesis writing service ireland q12qya 2023/03/03 7:18 Josephbried


Incredible plenty of great info.
essay thesis statements https://writingthesistops.com/ working thesis

# how to write your college essay n26pbs 2023/03/06 7:48 Gregorysaipt


Nicely put, Thanks a lot.
best essay writing service review https://domycollegehomeworkforme.com how to write a well written essay https://custompaperwritersservices.com

# essay writer cheap u900ub 2023/03/06 13:07 EugeneSib


Regards! Numerous knowledge!
writing opinion essays https://helpmedomyxyzhomework.com psychology dissertations https://bestpaperwritingservice.com

# how to write a persuasive argument essay e869yy 2023/03/07 6:28 Gregorysaipt


Thanks a lot! Awesome information.
quotes about writing essays https://dissertationwritingtops.com what is good writing essay https://hireawriterforanessay.com

# how to write a critique essay v25tbm 2023/03/08 4:51 Gregorysaipt


Cheers. An abundance of information!
argumentative essay on college education https://essaypromaster.com writing a dissertation methodology https://custompaperwritersservices.com

# college application essay heading t69nug 2023/03/08 11:13 EugeneSib

You reported this well!
dissertations theses https://domyhomeworkformecheap.com essay scholarships college students https://englishessayhelp.com

# how to write an english essay e73fhx 2023/03/09 3:04 Gregorysaipt


Useful information. Regards!
how to write an essay essay https://homeworkcourseworkhelps.com buy essay cheap online https://cheapessaywriteronlineservices.com

# how to write a bibliography for an essay y27reb 2023/03/10 0:31 Gregorysaipt

You actually suggested that perfectly.
writing services online https://dissertationwritingtops.com how to cite a website in an essay mla https://essaytyperhelp.com

# doctoral programs without dissertation s89cga 2023/03/10 9:16 EugeneSib


Wow all kinds of fantastic tips!
master degree thesis https://custompaperwritingservices.com master dissertation https://essaywritinghelperonline.com

# proquest umi search o51hqa 2023/03/10 22:00 Gregorysaipt


Thanks a lot. Plenty of posts!
how to write introduction essay https://custompaperwritersservices.com doctoral dissertation https://topswritingservices.com

# help me write a speech h28leh 2023/03/11 19:48 Gregorysaipt


Kudos! Ample information!
best college essays ever written https://phdthesisdissertation.com college essay writers block https://essaywriting4you.com

# completing a dissertation u72jxb 2023/03/12 20:21 EugeneSib


Lovely data, Many thanks!
writing numbers in essays https://writingthesistops.com service essay writing https://ouressays.com

# university theses b830ko 2023/03/13 10:57 EugeneSib


Kudos, Lots of material!
top college essays https://custompaperwritersservices.com dissertation coaching services https://ouressays.com

# online theses and dissertations h42aws 2023/03/13 15:13 Gregorysaipt


Amazing knowledge. Cheers.
online dissertation writing https://essaywritingserviceahrefs.com write an essay for a scholarship https://helpwritingdissertation.com

# persuasive essay helper n29ndf 2023/04/02 21:41 EugeneSib


Great tips. Thanks a lot.
english dissertation https://domyhomeworkformecheap.com essay writers https://ouressays.com

# Wein Plaza x499xv 2026/06/03 4:58 Wein Plaza


Amazing plenty of superb tips!
Wein Plaza - https://weinplaza.com/

タイトル
名前
Url
コメント