Computer Science - Stages of Compilatio

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/14

flashcard set

Earn XP

Description and Tags

All stages of compilation details

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

15 Terms

1
New cards

What is “compilation”?

Compilation is a process that translates a program written in a high-level programming language into machine code.

2
New cards

What are all the stages of compilation?

  • Lexical analysis

  • Syntax analysis

  • Code generation

  • Optimisation

3
New cards

What is lexical analysis and what does it identify?

Studying the words or vocabulary of a language and it includes identifying lexical tokens

4
New cards

What do tokens represent?

  • Keywords

    • var, const, function, for, while, if

  • identifiers

    • Variable names, function names

  • Operators

    • '+', '++', '-', '*'

  • Separators

    • ',' ';', '{', '}', '(', ')'

5
New cards

During lexical analysis, what is ignored?

Unnecessary elements like comments and white space

6
New cards

What is the result of a lexical analysis?

A token table, which is a collection of tokens that the lexical analyser has identified from the source code. It’s a list where each token is categorised into its type and contains its value

7
New cards

What does a syntax analysis do?

After tokens have been identified, syntax analysis makes sure they all adhere to the syntax rules of the programming language.

8
New cards

what happens if tokens don’t adhere to the syntax rules?

The character(s) that break the syntax rules will be flagged

9
New cards

what happens if the code passes the syntax analysis?

The compiler can then create an Abstract Syntax Tree (AST)

10
New cards

What is an abstract syntax tree?

A graph-based representation of the code being compiled, it’s an efficient way to represent the code for the next step

11
New cards

What does the code generation step do?

The code generation step takes the abstract syntax tree and converts it into low-level machine instructions (object code), which can then be linked to form an executable program that runs on the CPU

12
New cards

What is object code?

A compiler turns source code into object code. Object code can be executed by a computer.

13
New cards

What does the optimisation step do?

This step modifies the code to make it more efficient without changing its functionality.

14
New cards

What is the advantage of the optimisation step?

It reduces the memory required to run the code, which leads to faster execution

15
New cards

Give examples of common optimisation actions

  • Constant folding

    • Example: int x = 2 + 3; turns into int x = 5;

  • constant propagation

    • Replaces variables with their constant values wherever possible

    • Example: int a =5; int b = a + 2; turns into int b = 7;

  • Dead code elimination

    • Remove code that will never be executed or code that does not affect the program’s outcome

    • Example: removing an if statement that has a condition that’s never met

  • Loop unrolling

    • Increases the size of the loop’s body to reduce the overhead of loop control.

    • Example: A loop that multiplies numbers together will expand out to every line by line multiplication that happens

  • Common subexpression elimination

    • Identify expressions that are computed multiple times and calculate them once, storing the result.

Explore top flashcards

PNS (anatomy)
Updated 1060d ago
flashcards Flashcards (35)
leçon 4
Updated 637d ago
flashcards Flashcards (101)
El alfabeto
Updated 37d ago
flashcards Flashcards (30)
Dugaben terms
Updated 36d ago
flashcards Flashcards (59)
PNS (anatomy)
Updated 1060d ago
flashcards Flashcards (35)
leçon 4
Updated 637d ago
flashcards Flashcards (101)
El alfabeto
Updated 37d ago
flashcards Flashcards (30)
Dugaben terms
Updated 36d ago
flashcards Flashcards (59)