Download presentation
Presentation is loading. Please wait.
Published byAmy McGee Modified over 8 years ago
1
Introduction to Compiling M.A Doman
2
What is a compiler? A compiler is a program that reads a program written in one language and translates it into another language Compiler reports the presence of errors in the source program compiler Source Program Target Program Error Messages
3
Preprocessing The first pass of the compiler Reads each source file Every time it hits an directive #include it goes and gets the header file named. It then reads and processes it. Expands macros Passes the results to the next phase of the compiler.
4
Preprocessing Macro preprocessing Allows the user to define macros that are shorthand for larger constructs Define variables/identifiers #define _card.h #define BUFFER_SIZE 256 Conditional expressions #if.. #else Contain parameters #define max(a,b)(a>b ? a: b)
5
Stack.h Stack.CPP Node.H Node.cpp StackTest.c pp Compiler Preprocessor
6
Compilation Model Analysis Breaks up the source into pieces and constructs and creates an intermediate representation of the source program Synthesis Constructs the desired target from the intermediate representation 2-6
7
Compilation Analysis Linear or lexical analysis The source is read as a stream of characters and grouped into tokens position = initial + rate * 60; Tokens: position : Identifier of type double = : assignment operator initial : identifier of type double + : plus operator rate : Identifier of type double * : multiplication operator 60 : constant of 60 (int) 8-7
8
Compilation Analysis Hierarchal / Syntax analysis Also called parsing Groups the tokens into grammatical phrases that the compiler will later use to synthesize the logic. Usually represented by a parse tree: 8-8
9
Compilation Analysis Example (broad) of a parse tree: position = initial + rate * 60; 8-9 Operator = Identifier position Operator + Identifier initial Operator * Identifier rate Number 60
10
Compilation Analysis Semantic Analysis Checks the source program for semantic errors Gathers type information Does type checking Operator * Identifier rate Number 60 IntoDouble
11
Linking Once all the object (.o) files are created, they are passed to the linker All references are resolved Finished product: an executable porgram
12
Stack.o Library functions StackTest.o Compiler Linker Node.o a.exe
13
Stack. h Stack.C PP Node. H Node.c pp StackTes t.cpp Compiler Preprocessor Stack.o Library functions StackTest. o Linker Node.o a.exe
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.