Sujet : Re: Command Languages Versus Programming Languages
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.unix.shell comp.unix.programmer comp.lang.miscDate : 30. Mar 2024, 02:01:45
Autres entêtes
Organisation : None to speak of
Message-ID : <87il14si3a.fsf@nosuchdomain.example.com>
References : 1 2 3 4
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> writes:
On 29.03.2024 21:59, Lawrence D'Oliveiro wrote:
On Fri, 29 Mar 2024 10:37:22 +0100, Janis Papanagnou wrote:
Program text is initially text.[*] During parsing (either in
an interpreted or in a compiled language) you split the text
in tokens.
And then, how do you interpret the tokens?
>
In an interpreter the tokens are interpreted, in a compiler
they are subject to the parsing. (But you know that I'm sure.)
Are you suggesting that interpreters don't parse their input? No doubt
there are interpreters that handle tokens one at a time, but shells
typically don't work that way.
There are a lot of different ways to distinguish between languages like
sh/ksh/bash that are normally interpreted and languages like C that are
normally compiled to machine code:
- Is the language primarily designed for interactive command-line use?
- Is the language normally compiled to machine code?
- Is the language compiled by some kind of byte code that is then
interpreted? Is that byte code *sometimes* translated to machine
code?
- Is foo treated by default as a string or as an identifier?
(Treating it as a string is convenient for interactive use.)
- Does a syntax error on line 10 prevent lines 1-9 from being executed?
I don't think *any* of these distinctions are fundamental.
For example, a Perl or Python program/script is parsed and "compiled"
into some in-memory form before execution begins. A syntax error
prevents the entire script from being executed. In Bourne-line shells,
a syntax error won't be detected until execution reaches that line.
(Things like Perl's BEGIN and eval can complicate things.)
Shells also have to parse their input, though it's done a bit
differently. Typically the entire script isn't parsed as a unit.
[...]
So what is 'for i in a ; do ... ; done' then in your world?
>
This is one of many basic shell constructs that I use in shell
programming (not "shell scripting") regularly.
I use it both in shell scripting/programming and interactively.
And the entire construct needs to be processed before the shell can
begin to execute it. Misspelling "done" prevents the whole thing from
running.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comWorking, but not speaking, for Medtronicvoid Void(void) { Void(); } /* The recursive call of the void */