Replies: 15 comments 12 replies
-
The last two should work with no issues. I should get the following post parsing,
... I am not understanding how the expression evaluator works |
Beta Was this translation helpful? Give feedback.
-
At the moment there isn’t any way to mix statements and expressions. This is where you’d need to invoke a subshell with We did discuss before about the possibility of using parentheses to embed expressions inside statements but it’s not something I’ve coded yet. The main reason being that I wanted to let the idea brew a little longer in case I came up with any other elegant solutions (once this would be implemented, we’d likely then be stuck with it. So I wanted to make sure the right design was put in place). |
Beta Was this translation helpful? Give feedback.
-
Right on spot then! Because now I do understand what we were discussing before. ;-) Still... I don't understand how your command line evaluator works... (I will go hunt for the code) ie. round ((44 * 4096) / 1073741824) 0.99
from there, the command evaluator, will apply priorities and evaluations based on the metadata similar to a fn(fn(fn())) Mind sharing how the high level internals work? |
Beta Was this translation helpful? Give feedback.
-
There’s a couple of different parsers (albeit they share code so it appears like a single parser). First a command gets parsed as an expression. If it is a valid expression then the parser moves on and tokenises the next command in the pipeline. However it is an invalid expression (eg A valid statement is anything that follows the basic format of: This is why error messages say (to paraphrase) “not a valid expression nor statement”. During this early phase of parsing, expressions and statements are only lazily parsed. Eg parentheses are not calculated in expressions, values are not type checked, etc. The purpose is only to identify if the command is an expression or statement, and if the latter, to then tokenise the parameters. This means things like parentheses and subshells could hide bugs that are not found out until the interpreter is ready to execute that line of code (I have thought about optimising this process but given that the nature of shells being a meta programming environment, and the relative performance of Murex, it hasn’t really been a pressing concern). so it’s a bit of a hack but it’s a hack that works surprisingly well. The reason the hack exists is simply due to the fact that shells are littered with barewords. All strings are allowed to be barewords. I could enforce strings are quoted (like they are in expressions) but that would get really annoying really fast when the realisation of having to quote flags hits. Eg So since statements can have unquoted strings, it’s means there isn’t any strict grammar rules to which you can figure out what an expression should like like, should the parser be written to treat statements as valid expressions. this is why Murex has this weird split personality when it comes to expressions and statements. expressions are incredibly useful in programming because most other shells force expressions to be a quoted string passed to a command, which is ugly and error prone. But expressions add a level of verbosity people aren’t used to when calling executables (worth remembering that both Windows and POSIX only support strings as parameters so anything Murex does with types is already a hack on top of that). last thing worth noting is that expressions do actually get converted into a statement,
but I think as much confusion as the double parsing brings, it’s outweighed by the convenience of writing expressions as expressions rather than strings. |
Beta Was this translation helpful? Give feedback.
-
Sorry, I didnt mean to close this. |
Beta Was this translation helpful? Give feedback.
-
This is the type of discussion which would typically be great around a board and a live interaction. ;-) Thank you for the details, Yet I am still missing something, why isn't everything an expression?
The stack above will still fail evaluation, but you get my point... In a perfect world, everything should land on a stack. |
Beta Was this translation helpful? Give feedback.
-
Because command lines aren’t expressions. Eg
Then it’s pretty easy to tokenise a commands parameters. The issue is complicated even more in that command lines use space as a separator but expressions aren’t whitespace sensitive. So should
The only way to factor that into your parser is to either
The very early prototype of murex (then called JSH iirc) experimented with option 2 but it was horrible to use. |
Beta Was this translation helpful? Give feedback.
-
not into a valid expression, I agree... but it could be a valid stack... It could parse
for an expression like 5 - 5,
There is obviously a difference between expressions and commands, in which a command starts with the action, while expressions don't. so maybe the parser could detect it and output a reversed polish stack, like this
from there.. stack 0 has the signature : function(stack): stack |
Beta Was this translation helpful? Give feedback.
-
I’m not really sure that solves the problem though. You still need to define function and expression boundaries. Eg in LISP it might look like:
The equivalent in murex would look like:
The question is whether that’s verbose. Eg would this be more elegant:
which is actually not too difficult to implement because parenthesis are already a special case token. I’ve just been holding out doing so because there are a few design decisions I’ve made in a rush that I would love to undo if it weren’t for breaking backward compatibility. |
Beta Was this translation helpful? Give feedback.
-
fine - |
Beta Was this translation helpful? Give feedback.
-
I'm going to re-open this but turn it into a discussion because it's something that should be kept in our consciousness rather than closed and forgotten...at least until a satisfactory resolution has been decided. |
Beta Was this translation helpful? Give feedback.
-
I’m think about maybe having parentheses as a shortcut for inlining an expression. And this would also unify expressions and statements a little better because a statement then is |
Beta Was this translation helpful? Give feedback.
-
Started work on this idea: #677 (note I'm working off a different branch for POC) |
Beta Was this translation helpful? Give feedback.
-
Now merged into
outputs:
because anything that directly follows
even though there isn't any whitespace between This behaviour differs from a subshell where whitespace is important. eg
because it is parsed as
I'm undecided about which way is the "correct" way.
This is just a small detail though -- at least compared to the significance of the inclusion of |
Beta Was this translation helpful? Give feedback.
-
and I am done with my rewrite of the
|
Beta Was this translation helpful? Give feedback.
-
Hi again...
I am a bit puzzled as to how the parser works. I did read the chapter, yet I don't understand why the bellow code doesn't work
what am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions