Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Neeraj Sharma

    @neeraj-iAaNcG • Jun 11, 2012

    As far as I know, a program is passed to the pre-processor before it is executed or in other words before its processing begins. The pre-processor is involved in the task of linking the libraries. For example, consider a C program

    #include<stdio.h>
    int main()
    {
    printf("Hi there");
    }

    #include is a pre processor there which helps in including the header file in the program before the execution begins. If the header file is not included then printf will have no meaning in the program as the definition of printf is in stdio.h header file. Same is the case with including string.h for using string handling functions like strlen(), strcat() etc.

  • aarthivg

    @aarthivg-HH344f • Jun 11, 2012

    In the book written by Gilberg, It states that preprocessor reads the source code and prepares it for the translator. While preparing, it scans for the special code called preprocessor commands.
    #-Link-Snipped-#, this preprocessor command is what you say as, checking for header files, whether it is included in the program or it helps to include header file.

  • lovejeet

    @lovejeet-etHdkD • Jun 12, 2012

    the main task of compiler is translation. that is, compiler is a type of translator which translates high level language into machine language. now, according to the gilberg in his book, the 1st phase of compiling is lexical analysis(there are seven such phases). the lexical analysis reads the source code, scans it and arranges it in tokens. so what preprocessor commands are the commands included in the program to include header file and other files or to define macros. correct me if i am wrong.

  • aarthivg

    @aarthivg-HH344f • Jun 12, 2012

    lovejeetthe main task of compiler is translation. that is, compiler is a type of translator which translates high level language into machine language. now, according to the gilberg in his book, the 1st phase of compiling is lexical analysis(there are seven such phases). the lexical analysis reads the source code, scans it and arranges it in tokens. so what preprocessor commands are the commands included in the program to include header file and other files or to define macros. correct me if i am wrong.

    what is lexical analysis,tokens and macros?

    I have just started learning 'c' (only two days old๐Ÿ˜‰ ). So please try to be in simple words๐Ÿ˜€

  • Neeraj Sharma

    @neeraj-iAaNcG • Jun 12, 2012

    Lexical analysis divides the code in simple parts like c=a+b can be divided as a combination of tokens where c,=,a,+,b are called tokens or lexemes.

    Macro is another type of pre processor. As #include is used for including files, macro is used to have an alternate definition or kind of substitution .
    #define pre processor is used for defining a macro
    #define PI 3.14
    signifies that wherever you mention PI in your program, it will be replaced by 3.14 at the time of calculation.
    A compiler has following phases:
    Lexical Analysis, Syntax Analysis, Semantics Analysis, Intermediate Code generator, Code Optimizer, Code Generator.