When can you claim that your program is a "compiler"?

Accorging to wikipedia

A compiler is a computer program (or set of programs) that converts source code written in a programming language (source language) into another computer language (the target language, often in binary form, called object code). The most common reason for converting source code is to create an executable program.

But can the following code snippet be considered a compiler?

class S { public static void main( String ... args ) { if( "1".equals(args[0]) ) { System.out.println("echo Hi"); } } } 

I know this is a simplification, but when can you say that this program is actually a "compiler"?

+4
source share
2 answers

Is the language consisting of line "1" with the print semantics of "Hello!" programming language? I would say no, so this is not a compiler.

When it takes a real programming language and converts it to another, different, language, then you call it a compiler. This usually involves parsing the source language to get semantic meaning, and then change it to another language.

+3
source

You can use Turing completeness as a criterion, but it's a little strict (a special-purpose programming language may not be Turing), so I will go with something less rigid.

I think the key is that the output should be a series of instructions and that there will be a non-trivial correspondence between this output and the input. The example you provided violates the last criterion, since only two possible outputs are possible, no matter how complicated the input is: "echo Hi" and nothing.

The correspondence can be very close (both between FORTRAN and the assembly), and more distant (Prolog or Lisp and the assembly), but until you can create a huge amount of behavior through a consistent input language, the compiler.

+1
source

Source: https://habr.com/ru/post/1341890/


All Articles