Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #802
| From | Eric <eric@deptj.eu> |
|---|---|
| Newsgroups | comp.compilers, comp.unix.shell, comp.os.linux.misc |
| Subject | Re: magic/absurd bash interpreter/compiler ? |
| Date | 2012-12-24 19:13 +0000 |
| Organization | Compilers Central |
| Message-ID | <12-12-018@comp.compilers> (permalink) |
| References | <12-12-014@comp.compilers> |
Cross-posted to 3 groups.
On 2012-12-23, Avoid9Pdf@gmail.com <Avoid9Pdf@gmail.com> wrote: > It's OK if your dog doesn't KNOW how he catches a ball, or even if you > don't know the algorithm of how you ride-a-bicycle, provided you can > instinctively do it. But this bash nonsense is infuriating me! We > need a rigorous/formal syntax for computing. > > http://wiki.bash-hackers.org/howto/redirection_tutorial writes: >> Let's see another use case. We want to read a file line by line, >> this is easy, we just do: >> >> while read -r line;do echo "$line";done < file > > Well, I have some experience in building compilers, eg. augumented > FiniteStateMachine: where the PASCAL-like syntax-railway-diagrams are just > drawn and the diagram has the corresponding action for the received token > which progreses past THAT node in the diagram. > > And FORTH-like interpreters. > > These all 'compile' from-left-to-right, with possibly one token look-ahead. > > But this bash crap, seems to give a whole recursively-descendable-structure > and at the END, mentions ByTheWay <use FileIn as input>, whereas the > <InputFile> must be known at the BEGINING. Why on earth would you expect all computer languages to parse with a single pass from left to right? Neither Pascal nor Forth is a typical computer language. Pascal has more-or-less the sort of parser you seem to think should be universal, Forth does not! Bash (like other shells) is an interactive command-line based user interface which can also be used to write scripts, and it has evolved over many years, so why would it be like that? > Does this thing use multiple passes. Eg. where the complete command-line > is FIRST analysed for "<", ">", and then LATER any function/s who's input > and/or output is not specified, can use the previous scan's stuff. Bash has to use multiple passes and be recursive because of substitutions and compound commands like "while" in the example. What it does, and in what order, is actually in the man page. Redirects are picked out early, and can actually be anywhere in the command line for a simple command, but are more limited in a compound command. They are used last, just before actual execution. There is no way that input/output is ever unspecified. > What kind of mental model must we develop to handle this bash syntax > which contradicts normal/proper syntax, or must we approach is like > an infant learns its first language, or like your dog catches a ball? Normal/proper syntax is exactly what you expect it to be? I doubt it. There is no "normal", and "proper" can be a matter of opinion. So many questions, on so many forums, are from people who expect the language they are learning to be just like one they have already learnt. The main thing that these people need to learn is to _not_ do that. You can probably achieve the same results with the new language, but probably not in an exactly analogous way. Eric -- ms fnd in a lbry [I've had a lot of questions from people who seem unclear on the difference between an interpreter and a compiler, and get confused as soon as the language gets complex enough that it can't be handled a line at a time by read-parse-interpret. Most languages I know can indeed be parsed in a single left to right pass, but all you have at that point is a parse tree, with a lot of the compiler's work left to do. -John]
Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
magic/absurd bash interpreter/compiler ? Avoid9Pdf@gmail.com - 2012-12-23 11:04 +0000
Re: magic/absurd bash interpreter/compiler ? J G Miller <miller@yoyo.ORG> - 2012-12-24 00:28 +0000
Re: magic/absurd bash interpreter/compiler ? "Jonathan Thornburg" <jthorn@astro.indiana.edu> - 2012-12-24 03:57 +0000
Re: magic/absurd bash interpreter/compiler ? Eric <eric@deptj.eu> - 2012-12-24 19:13 +0000
Re: magic/absurd bash interpreter/compiler ? Barry Margolin <barmar@alum.mit.edu> - 2012-12-24 20:48 -0500
Re: magic/absurd bash interpreter/compiler ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-25 03:25 +0000
Re: magic/absurd bash interpreter/compiler ? Eric <eric@deptj.eu> - 2012-12-26 12:51 +0000
Re: magic/absurd bash interpreter/compiler ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-28 03:17 +0000
Re: magic/absurd bash interpreter/compiler ? Barry Margolin <barmar@alum.mit.edu> - 2012-12-28 10:25 -0500
csiph-web