luciano de souza wrote:
Hello all,
I trying to build a very small interpreter. I can type commands like:
$ add "Luciano de Souza" luchya...@gmail.com
Somewhere in my code, I can have something like:
procedure parse(commandline: string; var params: array of string);
In this case, the commandline has the format: "add %s %s". So I would obtain:
parse('add "Luciano de Souza" luchya...@gmail.com', params);
After this command, the parameter would have the following values:
params[0] := 'add';
params[1] := 'Luciano de Souza';
params[2] := 'luchya...@gmail.com';
My question is: there is a way to do it easily using a standard class
of Freepascal?
I'd suggest that this depends on two things: the first is whether input
is guaranteed to be on a single line, if it is (or if multiple lines
could be merged) then you could use something like the standard regular
expression unit.
The second is the complexity of your quoting and escaping, and also
whether you want to handle Unicode. If you only allow (say) " and
restrict it to a single depth, or if you could do an initial rewrite to
change nested quotes into something innocuous such as #$ff, then things
are comparatively simple.
In other cases use something like recursive descent, or investigate
(p)yacc, (p)lex etc.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal