Program construction Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are regular expressions?

A
  • Lexical analyser looks through code for specific patterns of letters, numbers or symbols. These are known as regular expressions
  • Once recognised they are applied to source code + a stream of tokens is generated
  • Can be represented as diagrams
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is lexical analysis?

A
  • Views source code and replaces keywords and symbols with tokens
  • spaces and comments are removed and tokens have replaced keywords, variables etc.
  • Invalid tokens pull up error
  • Once completed stream of tokens sent to syntax analysis
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are abstract syntax trees?

A
  • As code is parsed, a tree structure is formed
  • Abstract syntax trees (AST) are syntactically correct and only readable in one way
  • Operators are at root node
  • Numbers are operands
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What its semantic analysis?

A

Tries to imply meaning of code
Checks against aspects that are not related to syntactic form or that are not easily determined during parsing
Typical semantic errors:
-Type mismatch
-Undeclared variable
-Reserved identifier misuse
-Multiple declaration of variable in scope
-Accessing an out of scope variable
If error is found then report generator displays an error message.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is code mapping?

A

Matching common patterns from AST to block of machine code
Repeated until all parts of AST are mapped
Allocate blocks of code to registers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is code optimisation?

A

Code improvement e.g constant folding(e.g replace x= 4*4 with x= 16)
Remove redundant code
Tries to improve code by making it consume less resources and deliver high speed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the stages of compilation?

A

Lexical analysis
Syntax analysis
Semantic analysis
Code generation and optimisation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
What are translation and execution errors?
#Needs more (look at P.C test)
A

Translation:
Occurs when program is being compiled
e.g Syntax, linking and semantic errors

Execution(runtime):
Occurs when program is running
e.g. division by 0, reading past end of file, stack overflow ect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is machine code generation and optimisation?

A
  • Final phase of compilation
  • Once AST is created + checked against rules of language, code generation can then happen
  • When program can be lexically and syntactically analysed without errors, machine code can be generated
  • Tweaks code so it can run as quickly and with as little memory as possible.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the assembler?

A
  • Assembler is a program that translates assembly code into machine language
  • Relatively simple process as in general one assembly code statement translates into one machine code statement
  • It can allocate memory to variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Compare compiler and interpreter

A

Compiler

  • Source code hidden from other developers- intellectual property protected
  • Compiled code will only run on CPUs with same instruction sets and matching OS
  • Executable files can easily be distributed on CD or over internet

Interpreter:

  • Source code shown to all developers and users- intellectual property risk
  • will run on any platform from same source code base interpreter is required to run
  • Systems need to be set up before code can run. Can include installing library files as well as interpreter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Disadvantages of interpreter?

A
  • Must have interpreter running on computer to be able to run the program
  • As source code must be compiled each time, programs can sometimes run slowly
  • Have to rely on interpreter for machine level optimisation rather than programming them yourself
  • Developers can view source code which means they could use your intellectual property
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Advantages of interpreter

A
  • Source code has to be written only once, then can run on any computer with a compiler
  • Can easily inspect contents pf variables as running
  • Can test code more efficiently as well as being able to test single lines of code
  • code can be run on many different types of computers and OS
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is interpreter?

A
  • Converts high level language program to machine code line by line
  • Error found will be reported immediately to user + halts further execution
  • Any machine coed produced while interpreter is running will not be saved meaning it will have to be interpreted each time it wants to run code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are compilers?

A
  • Convert high level language source code into machine code
  • Produces standalone executable file which can be released to others without the need for further compilation
  • Protects intellectual property of developers
  • Code is converted all at once
  • If compiler encounters syntax error, it cannot translate statement so no object code is produced
  • When errors are found they are placed in error file and error message displayed to user.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is syntax analysis?

A
  • Checks against allowable patterns / in an acceptable order
  • Known as parsing the code
  • String of tokens split into phrases
  • Phrases are checked in accordance with rules (syntax) of programming language
  • If a match cannot be made then the report generator generates an error
17
Q

What is intermediate code?

A
  • Code that is compiled and can be run on different machines/platforms
  • Needed as normal compiled code has incompatibilities when run on different machines
  • Used with Virtual machines (A programming environment that allow s a program written to run on other types of machine without any changes being necessary)
  • If code is translated directly then a different translator would be used for each high-level language and each version of machine code. (as each processor architecture requires a different machine code)
18
Q

What is symbol table construction(Lexical analysis)?

A
  • When a label/variable is encountered it is mapped to. a memory address
  • Variables map to a memory location
  • labels map to a position where instruction jumps to
  • Data structure used to store keyword, variables etc. which were removed during lexical analysis.