Subj : Re: Compiler and an interpreter To : comp.programming From : Rob Thorpe Date : Sun Jul 31 2005 01:08 pm spinoza1111@yahoo.com wrote: > Rob Thorpe wrote: > > anjali wrote: > > > Suppose in a source-code file, the 4th line contains the first syntax > > > error.Can anybody please tell me how the compiler and interpreter will > > > behave when the given file will be the input to them? > > > > > > My guess is that the compiler will go through the entire file and will > > > report all the syntax errors in the file while the interpreter will > > > stop its execution exactly after the 4th line and will say that there > > > is a syntax error in the 4th line. > > > > This depends on the formal structure of the language and the design of > > the compiler/interpreter. > > > > For the purposes of this discussion languages can be split into two > > types, in which either: > > 1. Only a complete file/module is an acceptable input > > 2. Some small unit of the language is an acceptable input. > > > > C, C++ and Pascal are example of type 1, there are many more. > > Bash, lisp and ML are examples of type 2, again there are many more. > > > > If the language is of type 1 then the compiler/interpreter must read > > the whole file/module before beginning to do anything with it in > > earnest. In doing so it will find any syntax errors. > > > > If the language is of type 2 then the compiler/interpreter can begin to > > act on the input as it's going along. A compiler may do this by > > writing out machine code, an interpreter may do this by performing the > > actions specified. > > > > The compiler/interpreter doesn't have to be written this way though, it > > may choose to do nothing with the input until it reaches the end of the > > file/module. > > > > Most compilers read the entire input file before writing out code. > > Many interpreters act of input a line at a time. But not all, Perl for > > example reads the whole file before beginning to execute it. > > It is not even grammatical to say, where X is the name of a programming > language, that X "reads the whole file before beginning to execute it", > and more than it is grammatical to say "Cobol goes to the corner bar > and has a drink". > > Yet programmers continue to use this ugly syntax! As if programming > languages were active agents! This practise is a reification, a > fetishization and it hypostasizes mere artifacts into things that > REPLACE the very idea of human agency, and contribute in fact to > alienation. > > Perl does not to my knowledge in any way require the reading of the > entire Perl file. But even if it does, it isn't correct to say "Perl > reads". Perl is a language and not a compiler. Yes, I should have said "perl" referring to the program perl rather than the language "Perl". Or stated that I was referring to the implementation perl. > I just don't know if it is possible to write Incremental Perl or > Incremental C in the manner of a Lisp interpreter such that the > following earth shattering exchange could take place in Perl or C as it > can in Lisp. > > >7 > > 7 > > (user types 7 which evaluates, details at 11, to 7.) > > But it might be since so many things in C and Perl are expressions with > a value: > > >"Hello world" > Hello world > >"Bnarg" > Bnarg > >bnarg // undefined > VOID > > The last exchange shows that an Incremental C could never be standard > since a language in which it is the general practice to read the entire > file (a requirement given the otiose preprocessor) is also a language > that doesn't permit undefined identifiers. Yes, AFAIK you can't write an incremental implementation of standard C, there have been incremental C implementations but they haven't been standard. You might be able to write an incremental Perl interpreter, I don't know. Since the language doesn't have a standard whatever perl the program does is often taken as the standard. .