Re: magic/absurd bash interpreter/compiler ?

Eric <eric@deptj.eu>
Mon, 24 Dec 2012 19:13:39 +0000

          From comp.compilers

Related articles
magic/absurd bash interpreter/compiler ? Avoid9Pdf@gmail.com (2012-12-23)
Re: magic/absurd bash interpreter/compiler ? miller@yoyo.ORG (J G Miller) (2012-12-24)
Re: magic/absurd bash interpreter/compiler ? jthorn@astro.indiana.edu (Jonathan Thornburg) (2012-12-24)
Re: magic/absurd bash interpreter/compiler ? eric@deptj.eu (Eric) (2012-12-24)
Re: magic/absurd bash interpreter/compiler ? barmar@alum.mit.edu (Barry Margolin) (2012-12-24)
Re: magic/absurd bash interpreter/compiler ? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2012-12-25)
Re: magic/absurd bash interpreter/compiler ? eric@deptj.eu (Eric) (2012-12-26)
Re: magic/absurd bash interpreter/compiler ? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2012-12-28)
Re: magic/absurd bash interpreter/compiler ? barmar@alum.mit.edu (Barry Margolin) (2012-12-28)
| List of all articles for this month |

From: Eric <eric@deptj.eu>
Newsgroups: comp.compilers,comp.unix.shell,comp.os.linux.misc
Date: Mon, 24 Dec 2012 19:13:39 +0000
Organization: Compilers Central
References: 12-12-014
Keywords: parse, design, comment
Posted-Date: 24 Dec 2012 19:02:08 EST

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]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.