When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
17 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
if you want to handle different operators with different precedences, like | and >, you should probably write a proper parser
I don't see where your build_ast would be doing that, it just goes through tokens from left to right
and then oddly enough, some precedence is being dealt with in add_child_node, though that's a weird place to do it
it would be very simple to write a recursive descent parser since the grammar isn't too complicated
so I'd highly recommend writing a context-free grammar for your shell language first, and then implementing a simple parser for it
I was trying to build subtrees and put it all together at the end
Thank you for your advice, I'll be looking into that
@subtle shore Has your question been resolved? If so, run !solved :)
Are these good grammar rules to begin with ?
<command-line> ::= <command> { <pipeline> }
<pipeline> ::= "|" <command> { <pipeline> }
<command> ::= { <option> } <word> { <argument> } { <env> } { <heredoc> } { <redirection> }
<option> ::= "-" <word>
<argument> ::= <word> | <quoted-word> | <variable>
<word> ::= <non-space>+
<quoted-word> ::= '"' <any-chars>* '"'
<variable> ::= "$" <word>
<env> ::= <word> "=" <word>
<heredoc> ::= "<<" <word>
<redirection> ::= <direction> <word>
<direction> ::= "<" | ">" | ">>"
looks about right
though usually the shell doesn't parse arguments, it just passes everything through to the program
and stuff like matching quoted arguments is more of a lexer job
I see thank you very much, I'll try to build on that
This question is being automatically marked as stale.
If your question has been answered, run !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity