interpreter + stages of compilation

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 5:35 AM on 10/12/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

15 Terms

1
New cards

Order of compilation stages


  • Lexical

  • Syntax

  • Code generation

  • Code optimisation


2
New cards

Tasks of syntax compilation stage


  • Constructing a parse tree

  • Checking that rules of grammar/language has been obeyed

  • Production of an error report


3
New cards

Reasons for optimisation of code


  • Minimises amount of memory used

  • Minimises execution time


4
New cards

Explain how an interpreter executes a program without producing a complete translate version of it



  • Examines source code one statement at a time

  • Checks each statement for errors

    • If no error is found the statement is executed

    • If an error is found this is reported and the interpreter halts

  • Interpretation is repeated for every iteration in repeated sections of code

  • Interpretation has to be repeated every time the program is run


5
New cards

Lexical analysis description

  • Converting a sequence of characters into a sequence of tokens


6
New cards

Syntax analysis description

  • Using parsing algorithms to interpret the meaning of a sequence of tokens


7
New cards

Code generation description

  • Converting an intermediate representation of source code into an executable form


8
New cards

Optimisation description

  • Minimising a program’s execution time and memory requirement


9
New cards

Purpose of syntax analysis

  • Checks that the code matches the grammar of the language

  • Syntax errors are reported

  • A parse tree is produced


10
New cards

Process of executing a program using an interpreter

  • The interpreter translates the source code one line at a time

  • If the line is syntax error free, it is executed

  • It is not stored in an executable format

  • If an error is found, the program halts with an error message

  • Each line must be translated every time it is run (including lines running multiple times, like loops)


11
New cards

Lexical analysis during program compilation

  • First stage of compilation

  • White space and comments are removed

  • Takes modified source code and converts it into a series of tokens

  • Each token is categorised and assigned  type

  • Identifiers are stored in a table

  • If it finds invalid tokens, it generates an error

  • Acceptable data then passes to the syntax analyser


12
New cards

Syntax analysis during program compilation

  • Second stage of compilation

  • Takes input from the lexical analyser in the form of token streams

  • Uses parsing algorithms to interpret the meaning of a sequence of tokens

  • Source code is analysed / Checking that the rules of the grammar have been obeyed

  • Output from phase is a parse tree

  • Syntax errors are reported here


13
New cards

Purpose of lexical analysis during compilation of a program

  • Convert high-level source code

    • That can be sent to the parser for syntax analysis

  • To create a symbol(token) table

  • To remove unnecessary white space and comments from the code


14
New cards

Purpose of optimisation stage in compilation of a program

  • Minimising program storage

  • Minimising CPU time

  • Minimising memory use

  • Minimising program execution time


15
New cards

Process of optimisation during compilation of a program

  • To identify and remove redundant code // to simplify expressions // To reorder the code

    • So that storage size, memory use, power consumption, program execution time and CPU time is minimised