Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where exactly is the boundary between a preprocessor and a compiler?

According to various sources (for example, the SE radio episode with Kevlin Henney, if I remember correctly), "C with classes" was implemented with preprocessor technology (with the output then being fed to a C compiler), whereas C++ has always been implemented with a compiler (that just happened to spit out C in the early days). This seems to cause some confusion, so I was wondering:

Where exactly is the boundary between a preprocessor and a compiler? When do you call a piece of software that implements a language "a preprocessor", and when do you call it "a compiler"?

By the way, is "a compiled language" an established term? If so, what exactly does it mean?

like image 575
fredoverflow Avatar asked Aug 25 '11 07:08

fredoverflow


2 Answers

This is an interesting question. I don't know a definitive answer, but would say this, if pressed for one:

A preprocessor doesn't parse the code, but instead scans for embedded patterns and expands them

A compiler actually parses the code by building an AST (abstract syntax tree) and then transforms that into a different language

like image 177
Daren Thomas Avatar answered Sep 22 '22 07:09

Daren Thomas


The language of the output of the preprocessor is a subset of the language of the input.

The language of the output of the compiler is (usually) very different (machine code) then the language of the input.

like image 26
Tomas Avatar answered Sep 21 '22 07:09

Tomas