Programming Flashcards
What is Language Translation?
Language translation is the process of converting high-level instructions to machine-level instructions (0 and 1) without sacrificing the code’s functionality.
List the stages of language translation/compilation
Lexical analysis
Syntax analysis
Semantic analysis
Intermediate code generation
Code generation
Explain the lexical analysis stage of language translation/compilation
At this stage of the process the following is done:
All comments and unnecessary spaces are removed and some simple error checking is performed. For example, if a language has restrictions on the length of an identifier this analyzer will determine if the variable is too long.
Program instructions are scanned and actual symbols of the program such as integers, identifiers, reserved words are created.
Explain the syntax analysis stage of language translation/compilation
This is the process of determining whether the syntax of the program is correct.
The code is checked to see if they follow the rules of a particular programming language were followed.
NOTE: The syntax rules of a language define how a programmer can put symbols, reserved words and identifiers together to make a valid program.
Explain the semantic analysis stage of language translation/compilation
Semantic analysis is concerned with the meaning or interpretation of codes/commands in the context in which they are used. During this stage, the commands in the program are tested to see if they were correctly used based on the language.
The constructs of the program is check for semantic correctness and the necessary information stored in a construct symbol table.
The semantics of a program statement define what that statement means (its purpose in a program). A program
Explain intermediate code generation and code optimization
Codes are modified so that they can be executed faster. This reduces the execution time for a program by looking at how the codes could execute more efficiently.
Explain the Code Generation stage of language translation/ compilation
At this stage the actual machine codes or assembly language are generated from the internal source program. It is the most detailed part of the compilation.
How are comments written in C?
Single line comments are written with two slashes
e.g:
// This is a comment
Multi Line comments are written using slashes and asteriks
e.g:
/* This is a comment */
How are if then statements written in C?
Syntax/ Layout :
if (condition)
{
Action to be taken if condition is true
} // End of if statement
E.g
if(grade>60)
{
printf(“pass”);
}// end of if statement
How are if else statements written in C
if(condition)
{
Action(s) to be taken if condition is true
}
else
{
Action(s) to be taken if condition is false
}
What is a syntax error/ when does it occur?
A syntax error occurs when the compiler cannot recognize a statement because it vio-
lates the language rules.
C programs typically go through six phases to be executed, these are:
- edit
- preprocess
- compile
- link
- load
- execute.
What are run time errors
Errors that occur as a program runs
E.g Division by Zero
Divide-by-zero is generally a fatal error that causes the
program to terminate immediately without successfully performing its job. Nonfatal
errors allow programs to run to completion, often producing incorrect results.
Define variables
//fig02_04.c
//Addition program
#include <stdio.h></stdio.h>
// function main begins program execution int main (void) { int integer1 = 0; // will hold first number user enters int integer2 = 0;// will hold second number user enters printf("Enter first integer: "); // prompt scanf("%d", &integer1); // read an integer printf("Enter second integer:"); // prompt scanf("%d", &integer2); // read an integer int sum = 0;// variable in which sum will be stored sum = integer1 + integer2; // assign total to sum printf("Sum is %d\n", sum); // print sum } // end function main
Define variables
//fig02_04.c
//Addition program
#include <stdio.h></stdio.h>
// function main begins program execution int main (void) { int integer1 = 0; // will hold first number user enters int integer2 = 0;// will hold second number user enters printf("Enter first integer: "); // prompt scanf("%d", &integer1); // read an integer printf("Enter second integer:"); // prompt scanf("%d", &integer2); // read an integer int sum = 0;// variable in which sum will be stored sum = integer1 + integer2; // assign total to sum printf("Sum is %d\n", sum); // print sum } // end function main