9.2.3 Implementing Flashcards
What is the difference between a rounded rectangle and a normal rectangle in railroad diagrgams?
Rounded rectangle indicates a literal.
A normal rectangle indicates an element that needs to be defined elsewhere.
What do curly braces represent in EBNF?
Write down some examples of the statement a { b }
A repetition of the the elements inside zero or more times.
a { b } would represent: a, ab, abb, abbb etc.
What do square brackets mean in EBNF?
Write down the possible statements defined by a [b] c
An option (zero or once).
a [b] c would be either abc or ac.
In EBNF, how can you specify that an element must repeat one or more times?
For example, how could you describe
hi, hii, hiii, hiiii etc.
By including the element as a literal, followed by a zero or more time loop (curly brackets).
That is, h i { i }
What are parentheses used for in EBNF?
As a grouping symbol, to remove any possible ambiguity in a rule.
How do you specify a choice between options in EBNF?
With a vertical line.
For example, x ( + | - ) y could be x + y or x - y
In EBNF, how do you specify a symbol that requires further definition elsewhere?
(This is also called a non-terminal symbol)
Using angled brackets.
For example, in the rule if then, if and then are literals while condition is defined elsewhere.
What is the only type of code that can be executed by a computer?
Machine code: commands written in binary that are specific to each processor (or family of processors).
What is assembly language?
A low-level language that is processor-dependent. It uses text codes (“opcodes”) to perform arithmetic functions and access processor registers.
Each opcode in assembly corresponds to one machine code instruction, but is (very slightly) more readable.
What does translation refer to?
The process of converting human readable (high-level) languages into machine code.
The 2 forms of translation are interpretation and compilation.
Describe how an interpreted language is executed.
The interpreter executes each line of source code as it is read.
Describe how a compiled language works.
A compiler analyses the entire source code and creates an executable file.
Outline the advantages and disadvantages of compilation and interpetation.
Interpretation
- Advantages
- Code can be executed quickly so development can happen quickly.
- Disadvantages
- Slower to execute.
- Source code is not protected.
- Intepreter needs to be distributed along with the source code to end users.
Compilation
- Advantages
- Code typically runs faster.
- Hard to reverse engineer - source code is protected.
- Disadvantages
- Developing/testing takes longer, having to compile after each change.
What are the 3 stages involved in translation?
- Lexical analysis
- Syntactical analysis
- Code generation
Outline the process of lexical analysis.
Each word in the source code is checked to see if it is part of the language.
The words are converted into tokens to represent parts of the langugae and user-defined variable names.