#AST Implementation in C

17 messages · Page 1 of 1 (latest)

bitter ospreyBOT
#

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.

finite sleet
#

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

subtle shore
#

Thank you for your advice, I'll be looking into that

bitter ospreyBOT
#

@subtle shore Has your question been resolved? If so, run !solved :)

subtle shore
#

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>    ::= "<" | ">" | ">>"
finite sleet
#

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

subtle shore
#

I see thank you very much, I'll try to build on that

bitter ospreyBOT
#

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.

subtle shore
#

!solved

bitter ospreyBOT
#

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