robert meyer charles scott n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Compiling & Syntax PowerPoint Presentation
Download Presentation
Compiling & Syntax

Loading in 2 Seconds...

play fullscreen
1 / 12

Compiling & Syntax - PowerPoint PPT Presentation


  • 100 Views
  • Uploaded on

Robert Meyer Charles Scott. Compiling & Syntax. Syntax. The syntax of a programming language can be implemented by any of 3 general methods: Compilation Interpretation Hybrid Implementation. Source. Compiler. Object Code. Source. Lexical Analyzer. Symbol Table. Lexical Units.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Compiling & Syntax' - scout


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
syntax
Syntax

The syntax of a programming language can be implemented by any of 3 general methods:

Compilation

Interpretation

Hybrid Implementation

Source

Compiler

Object Code

slide3

Source

Lexical Analyzer

SymbolTable

Lexical Units

Syntax Analyzer

Parse Tree’s

(optional)

Intermediate CodeGeneration & SemanticAnalysis

Optimizer

Input

Code Generation

Computer

Results

Machine Language

slide4

Source

Lexical Analyzer

SymbolTable

Lexical Units

  • Lexical Analyzer:
  • Gathers Characters of source program into lexical Units
  • Lexical units:
      • Identification
      • Special Words
      • Operators
      • Punctuation Symbols
      • Comments are Ignored!
slide5

Source

Lexical Analyzer

SymbolTable

Lexical Units

Syntax Analyzer

Parse Tree’s

  • 2) Syntax Analyzer
    • Takes Lexical Units and Constructs Hierarchical structure called “Parse Tree” which represents syntactic structure of the program.
slide6

1

farenheight

2

celcius

|F|a|r|e|n|h|i|e|g|h|t| |:|=| |3|2| |+| |c|e|l|c|i|u|s| |*| |1|.|8|;|

Broken down by Character

Lexical Analyzer

id1 := Int32 + id2 * Real ;

Syntax Analyzer

Symbol Table

:=

id1

+

*

32int

id2

Real

idn

Denotes symbol n in the symbol table

Determines the type of the identifier

Context Analyzer

:=r

id1

+r

*r

32int

id2

1.8real

slide7

Source

Note: Semantic analysis is an integral part of the intermediate code generation process. It checks for errors that are difficult to detect during syntax analysis such as type errors.

Lexical Analyzer

SymbolTable

Lexical Units

Syntax Analyzer

Parse Tree’s

Intermediate CodeGeneration & SemanticAnalysis

  • 3) Intermediate Code Generation
    • Produces Program in a different language.
      • Assembly
      • Something like assembly
      • Something higher level than assembly
slide8

Source

3.1) Optimization

Makes program smaller and/or faster. Most optimization is done on Intermediate code.

Lexical Analyzer

SymbolTable

Lexical Units

Program

Syntax Analyzer

Lab for beginner programmers: No Optimization

Compiler

Object Code

Parse Tree’s

(optional)

Intermediate CodeGeneration & SemanticAnalysis

Optimizer

slide9

Intermediate Code Generation

(optional)

Temp1 = int_to_real(32)

Temp2 = ID2

Temp2 = Temp2 * 1.8

Temp1 = Temp1 + Temp2

ID1 = Temp1

Optimizer

Integer constant 32 converted to float constant

Temp1 = ID2

Temp1 = Temp1 * 1.8

Temp1 = Temp1 + 32

ID1= Temp1

Reduced instruction set by 1 instruction, and reduced memory usage by 1 temp variable

movf ID2, R1

mulf 1.8, R1

addf 32, R1

movf R1, ID1

*Code Depends on machine

slide10

4) Code Generation

Translates Intermediate code to machine language.

The symbol table serves as a database for the compilation process.

Source

Lexical Analyzer

SymbolTable

Lexical Analyzer

Syntax Analyzer

Lexical Units

Syntax Analyzer

Symbol Table

Intermediate Code

Parse Tree’s

(optional)

Intermediate CodeGeneration & SemanticAnalysis

Optimizer

Linker translates to executable code

Input

Code Generation

Computer

Results

Machine Language

slide11

Machine Language:

  • To run the program in machine language form it needs:
    • Some other code
    • Programs from the Operating system (Input / Output)

Machine

Language

OS

Routines

Libraries

System calls executed on programs behalf

Linker

Executable Image

Loader

Fetch

Execute

Interrupt

Program

Loop

slide12

Interpret:

    • Slower than compiler.
    • One instruction at a time.
    • Virtual Machine introduced by IBM to test code on different platforms.