Need help to parse my custom CLI commands












0















I'm developing a custom CLI in C. The CLI commands are something like:



debug read card 6 block 5 size 10
system update remote sftp://... password ****
copylogs card.log system.log module.log
system reload warm module1


The commands are in different lengths and may include optional fields.



Now I have two questions.



1- What should I bear in mind when finalizing the shape/grammer of the commands, in order not to get into trouble when lexing/parsing.



2- What is the best practice to parse the commands. I searched around the net and it seems the flex-bson way is the way I should go. As I'm totally new to these kinds of things, I'm here to get help. What should I do? Should I write my custom lexer/parser? Should I go the flex-bson way? Is there a ready-to-use lexer/parser that I can directly use in my code?



Your help is appreciated...










share|improve this question























  • You could use the "standard C" way of handling arguments, and pass each function a counter and an array of strings, and let each "command" parse the arguments on their own.

    – Some programmer dude
    Nov 22 '18 at 10:25











  • What I did long ago was, I looked into openssl code source to see what they did and try to adapt it to mine. So basically, all arguments are saved in an array of strings argv. You compare each item with your predefined flag. If it corresponds, then the next item should be the value......

    – PhoenixBlue
    Nov 22 '18 at 10:41











  • @someprogrammerdude thanks for your comment. Any comment on using the flex-bison strategy?

    – Mahdi.B
    Nov 22 '18 at 16:35











  • Nothing specific. It's one way to solve your problem. And a very powerful and flexible way, which of course brings with it quote some complexity. If you should use it really depends on the format of the commands and their argument, the more "natural" they are the more complex the solutions have to be. What you show is quite complex structure and will probably be well-suited for a Lex-Yacc (or Flex-Bison) solution.

    – Some programmer dude
    Nov 22 '18 at 16:41











  • @PhoenixBlue Thanks. So you say it's an standard strategy to go this way. By the way what's your idea of the flex-bison strategy. It fits for this case? It worths the pain?

    – Mahdi.B
    Nov 22 '18 at 16:41
















0















I'm developing a custom CLI in C. The CLI commands are something like:



debug read card 6 block 5 size 10
system update remote sftp://... password ****
copylogs card.log system.log module.log
system reload warm module1


The commands are in different lengths and may include optional fields.



Now I have two questions.



1- What should I bear in mind when finalizing the shape/grammer of the commands, in order not to get into trouble when lexing/parsing.



2- What is the best practice to parse the commands. I searched around the net and it seems the flex-bson way is the way I should go. As I'm totally new to these kinds of things, I'm here to get help. What should I do? Should I write my custom lexer/parser? Should I go the flex-bson way? Is there a ready-to-use lexer/parser that I can directly use in my code?



Your help is appreciated...










share|improve this question























  • You could use the "standard C" way of handling arguments, and pass each function a counter and an array of strings, and let each "command" parse the arguments on their own.

    – Some programmer dude
    Nov 22 '18 at 10:25











  • What I did long ago was, I looked into openssl code source to see what they did and try to adapt it to mine. So basically, all arguments are saved in an array of strings argv. You compare each item with your predefined flag. If it corresponds, then the next item should be the value......

    – PhoenixBlue
    Nov 22 '18 at 10:41











  • @someprogrammerdude thanks for your comment. Any comment on using the flex-bison strategy?

    – Mahdi.B
    Nov 22 '18 at 16:35











  • Nothing specific. It's one way to solve your problem. And a very powerful and flexible way, which of course brings with it quote some complexity. If you should use it really depends on the format of the commands and their argument, the more "natural" they are the more complex the solutions have to be. What you show is quite complex structure and will probably be well-suited for a Lex-Yacc (or Flex-Bison) solution.

    – Some programmer dude
    Nov 22 '18 at 16:41











  • @PhoenixBlue Thanks. So you say it's an standard strategy to go this way. By the way what's your idea of the flex-bison strategy. It fits for this case? It worths the pain?

    – Mahdi.B
    Nov 22 '18 at 16:41














0












0








0


1






I'm developing a custom CLI in C. The CLI commands are something like:



debug read card 6 block 5 size 10
system update remote sftp://... password ****
copylogs card.log system.log module.log
system reload warm module1


The commands are in different lengths and may include optional fields.



Now I have two questions.



1- What should I bear in mind when finalizing the shape/grammer of the commands, in order not to get into trouble when lexing/parsing.



2- What is the best practice to parse the commands. I searched around the net and it seems the flex-bson way is the way I should go. As I'm totally new to these kinds of things, I'm here to get help. What should I do? Should I write my custom lexer/parser? Should I go the flex-bson way? Is there a ready-to-use lexer/parser that I can directly use in my code?



Your help is appreciated...










share|improve this question














I'm developing a custom CLI in C. The CLI commands are something like:



debug read card 6 block 5 size 10
system update remote sftp://... password ****
copylogs card.log system.log module.log
system reload warm module1


The commands are in different lengths and may include optional fields.



Now I have two questions.



1- What should I bear in mind when finalizing the shape/grammer of the commands, in order not to get into trouble when lexing/parsing.



2- What is the best practice to parse the commands. I searched around the net and it seems the flex-bson way is the way I should go. As I'm totally new to these kinds of things, I'm here to get help. What should I do? Should I write my custom lexer/parser? Should I go the flex-bson way? Is there a ready-to-use lexer/parser that I can directly use in my code?



Your help is appreciated...







c parsing command-line-interface lexer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 10:22









Mahdi.BMahdi.B

83




83













  • You could use the "standard C" way of handling arguments, and pass each function a counter and an array of strings, and let each "command" parse the arguments on their own.

    – Some programmer dude
    Nov 22 '18 at 10:25











  • What I did long ago was, I looked into openssl code source to see what they did and try to adapt it to mine. So basically, all arguments are saved in an array of strings argv. You compare each item with your predefined flag. If it corresponds, then the next item should be the value......

    – PhoenixBlue
    Nov 22 '18 at 10:41











  • @someprogrammerdude thanks for your comment. Any comment on using the flex-bison strategy?

    – Mahdi.B
    Nov 22 '18 at 16:35











  • Nothing specific. It's one way to solve your problem. And a very powerful and flexible way, which of course brings with it quote some complexity. If you should use it really depends on the format of the commands and their argument, the more "natural" they are the more complex the solutions have to be. What you show is quite complex structure and will probably be well-suited for a Lex-Yacc (or Flex-Bison) solution.

    – Some programmer dude
    Nov 22 '18 at 16:41











  • @PhoenixBlue Thanks. So you say it's an standard strategy to go this way. By the way what's your idea of the flex-bison strategy. It fits for this case? It worths the pain?

    – Mahdi.B
    Nov 22 '18 at 16:41



















  • You could use the "standard C" way of handling arguments, and pass each function a counter and an array of strings, and let each "command" parse the arguments on their own.

    – Some programmer dude
    Nov 22 '18 at 10:25











  • What I did long ago was, I looked into openssl code source to see what they did and try to adapt it to mine. So basically, all arguments are saved in an array of strings argv. You compare each item with your predefined flag. If it corresponds, then the next item should be the value......

    – PhoenixBlue
    Nov 22 '18 at 10:41











  • @someprogrammerdude thanks for your comment. Any comment on using the flex-bison strategy?

    – Mahdi.B
    Nov 22 '18 at 16:35











  • Nothing specific. It's one way to solve your problem. And a very powerful and flexible way, which of course brings with it quote some complexity. If you should use it really depends on the format of the commands and their argument, the more "natural" they are the more complex the solutions have to be. What you show is quite complex structure and will probably be well-suited for a Lex-Yacc (or Flex-Bison) solution.

    – Some programmer dude
    Nov 22 '18 at 16:41











  • @PhoenixBlue Thanks. So you say it's an standard strategy to go this way. By the way what's your idea of the flex-bison strategy. It fits for this case? It worths the pain?

    – Mahdi.B
    Nov 22 '18 at 16:41

















You could use the "standard C" way of handling arguments, and pass each function a counter and an array of strings, and let each "command" parse the arguments on their own.

– Some programmer dude
Nov 22 '18 at 10:25





You could use the "standard C" way of handling arguments, and pass each function a counter and an array of strings, and let each "command" parse the arguments on their own.

– Some programmer dude
Nov 22 '18 at 10:25













What I did long ago was, I looked into openssl code source to see what they did and try to adapt it to mine. So basically, all arguments are saved in an array of strings argv. You compare each item with your predefined flag. If it corresponds, then the next item should be the value......

– PhoenixBlue
Nov 22 '18 at 10:41





What I did long ago was, I looked into openssl code source to see what they did and try to adapt it to mine. So basically, all arguments are saved in an array of strings argv. You compare each item with your predefined flag. If it corresponds, then the next item should be the value......

– PhoenixBlue
Nov 22 '18 at 10:41













@someprogrammerdude thanks for your comment. Any comment on using the flex-bison strategy?

– Mahdi.B
Nov 22 '18 at 16:35





@someprogrammerdude thanks for your comment. Any comment on using the flex-bison strategy?

– Mahdi.B
Nov 22 '18 at 16:35













Nothing specific. It's one way to solve your problem. And a very powerful and flexible way, which of course brings with it quote some complexity. If you should use it really depends on the format of the commands and their argument, the more "natural" they are the more complex the solutions have to be. What you show is quite complex structure and will probably be well-suited for a Lex-Yacc (or Flex-Bison) solution.

– Some programmer dude
Nov 22 '18 at 16:41





Nothing specific. It's one way to solve your problem. And a very powerful and flexible way, which of course brings with it quote some complexity. If you should use it really depends on the format of the commands and their argument, the more "natural" they are the more complex the solutions have to be. What you show is quite complex structure and will probably be well-suited for a Lex-Yacc (or Flex-Bison) solution.

– Some programmer dude
Nov 22 '18 at 16:41













@PhoenixBlue Thanks. So you say it's an standard strategy to go this way. By the way what's your idea of the flex-bison strategy. It fits for this case? It worths the pain?

– Mahdi.B
Nov 22 '18 at 16:41





@PhoenixBlue Thanks. So you say it's an standard strategy to go this way. By the way what's your idea of the flex-bison strategy. It fits for this case? It worths the pain?

– Mahdi.B
Nov 22 '18 at 16:41












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428756%2fneed-help-to-parse-my-custom-cli-commands%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428756%2fneed-help-to-parse-my-custom-cli-commands%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Create new schema in PostgreSQL using DBeaver