I want to write my own command line library from scratch. What algorithm should I use in order to parse gnu style args like in getopt for example ? I mean what's the best way other than tokenizing and parse them in a naive way? Should I try to look at LR, LL algorithms or this is way too overkill?
1 Answer
An LL(1) parser is a top down left to right parser, that needs only to know one symbol in advance. This is sufficient to parse a command line syntax.
But constructing an LL(1) parser seems to be an overkill for this kind of tasks, where a loop, a couple of if
s and some flags would completely do the trick.
-abc
=-a -b -c
),--foo=bar
style values, or abbreviations, then using an existing options parsing library seems sensible.