0% found this document useful (0 votes)
36 views6 pages

Lecture Handout - 3

The document discusses the key components of a C source code file including preprocessor directives, global declarations, and function definitions. It then summarizes the compilation process from source code to executable file which involves lexical analysis, preprocessing, compilation, assembly, and linking. The main tokens identified are keywords, identifiers, constants, strings, and symbols.

Uploaded by

Kirubai D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views6 pages

Lecture Handout - 3

The document discusses the key components of a C source code file including preprocessor directives, global declarations, and function definitions. It then summarizes the compilation process from source code to executable file which involves lexical analysis, preprocessing, compilation, assembly, and linking. The main tokens identified are keywords, identifiers, constants, strings, and symbols.

Uploaded by

Kirubai D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SOURCE FILES:

Function defnition, Global declaration and preprocessing directivies are source code of C
prog.
Small Prog: Source code written – Single Source file
Large prog: Source code written – Several source codes

Function definitions Depends

Preprocessor directives Global declarations

Internal Structure of Source Files:

1. Preprocessor directives
2. Global declarations
3. Function definitions

write a c program to Calculate and print the area of circles:


#include <stdio.h>

int main() {

float radius, area_circle;

// take radius as input

printf("Enter the radius of circle : ");


scanf("%f", &radius);

area_circle = 3.14 * radius * radius;

printf("Area of circle : %f", area_circle);

return 0;

OUTPUT:

COMMENTS IN C

• In computer programming, a comment is a programmer-readable explanation or annotation


in the source code of a computer program
• Comments are statements that are not executed by the compiler and interpreter.

In C there are two types of comments :

1. Single line comment.


2. Multi-line comment.
CHARACTER SET:
As every language contains a set of characters used to construct words, statements, etc., C language also
has a set of characters which include alphabets, digits, and special symbols. C language supports a
total of 256 characters.

IDENTIFIERS

The term identifier refers to the names of variables, functions, macros, structures

and other objects defined in a C program. Identifiers can contain the following characters:

• The letters in the basic character set, a–z and A–Z. Identifiers are case-sensitive.

• The underscore character, _.

• The decimal digits 0–9, although the first character of an identifier must not be a digit.

• Universal character names that represent the letters and digits of other languages.

Keywords

Keywords are special words in C programming which have their own predefined meaning. The
functions and meanings of these words cannot be altered. Some keywords in C Programming are:

The following 37 keywords are reserved in C, each having a specific meaning to the compiler, and must
not be used as identifiers:

auto break case char

continue const do default

double else enum extern

for float go if
int long register return

sign static sizeof short

struct switch typedef union

void volatile while unsigned

Consider an example below:

int age;

float height;

Here, int is a keyword which declares age as a variable of integer data type.
Similarly, float is also a keyword which declares height is a variable of floating integer data type.

Identifier Name Spaces

All identifiers fall into exactly one of the following four categories, which

constitute separate name spaces:

• Label names.

• Tags, which identify structure, union and enumeration types.

• Names of structure or union members. Each structure or union constitutes a separate name space for
its members.

• All other identifiers, which are called ordinary identifiers.

IDENTIFIER SCOPE:

The scope of an identifier refers to that part of the translation unit in which the
identifier is meaningful.

Four kinds of scope are possible:


1.File Scope

2.Block Scope

3. Function prototype scope

4. Function scope
HOW THE C COMPILER WORKS:

The compilation is a process of converting the source code into object code. It is done with the help of
the compiler.

Figure: illustrates,

From source code to executable file

The C Compiler’s Translation Phases

1. The source file input is mapped to the source character set (if necessary). Trigraphs are replaced
in this step.

a) 5 whitespace characters (space, horizontal tab, vertical tab, form feed, new-line)
b) 10 digit characters from '0' to '9'
c) 52 letters from 'a' to 'z' and from 'A' to 'Z'
d) 29 punctuation characters: _ { } [ ] # ( ) < > % : ; . ? * + - / ^ & | ~ ! = , \ " '

2. Continuation lines (lines that end with \ ) are spliced with the next line.
3. The source code is parsed into whitespace and preprocessing tokens.

a) header names: <stdio.h> or "myfile.h"


b) identifiers
c) preprocessing numbers, which cover integer constants and floating constants, but also cover
some invalid tokens such as 1..E+3.foo or 0JBK
d) character constants and string literals
e) operators and punctuators, such as +, <<=, <%, or ##.
f) individual non-whitespace characters that do not fit in any other category

4. The preprocessor is applied, which executes directives, expands macros, and applies pragmas.
Each source file pulled in by #include undergoes translation phases 1 through 4 (recursively if
necessary). All preprocessor related directives are then deleted.
5. Source character set values in character constants and string literals are mapped to the execution
character set.
6. String literals adjacent to each other are concatenated.
7. The source code is parsed into tokens, which comprise the translation unit.
8. External references are resolved, and the program image is formed.

TOKENS:

A token is either a keyword, an identifier, a constant, a string literal, or a symbol. Symbols in C consist
of one or more punctuation characters, and function as operators or digraphs, or have syntactic
importance, like the semicolon that terminates a simple statement, or the braces { } that enclose a block
statement.

For example, the following C statement consists of five tokens:

printf("Hello, world.\n");

The individual tokens are:

printf

"Hello, world.\n"

You might also like