Appendix for code examples
Answers for Problem Sets
Explain the difference between syntax and semantics.
Syntax is a precise set of rules that determine the structure of statements, allowed symbols, and the combination of legal expressions while semantics is a precise set of rules that tell you the meanings of the symbols and legal expressions.
Who is credited for the first computer programming language? What year was it created?
Ada Lovelace is credited for creating the first computer programming language in 1853.
How does machine language differ from assembly language?
Machine language is known as the computer’s own language and is written in binary code. On the other hand, assembly language is the first human readable programming language; it uses assemblers to code from assembly language to machine languages.
What makes a good programming language?
Some criteria of a good programming language include program design, simplicity, correctness, expressiveness, readability, security, modularity, error handling, and documentation.
What are tokens? How are they defined?
Tokens are sets of symbols or strings with meanings; they form together to build up the language. Tokens are usually defined using name and value pairs.
What are grammars?
Grammars are set of rules that define the syntax or arrangement of tokens to provide meaningful phrases of the programming language; it defines what makes an expression or a statement valid.
Define source code. What does it contain?
It is the set of instructions and statements written in a programming language; it contains declarations, instructions, functions, loops, and other statements that act as instructions for the program.
What is logic programming?
Logic programming is a programming paradigm that is largely based on formal logic; a program written in a logic programming language is simply a set of statements in logical forms, expressing facts and rules about a problem domain.
How many different generations of programming languages are there? What are they?
There are five different generations of programming languages – 1GL, 2GL, 3GL, 4GL, and 5GL. First generation, 1GL, languages are machine code. Second generation, 2GL, is known as assembly languages. Third generation, 3GL, languages brought logical structure to software development and made the programming languages more programmer friendly. Fourth generation, 4GL, languages resulted as a new higher level of abstraction was created to generate a more natural flowing language. Finally, fifth generation, 5GL, languages are based on solving problems using constraints rather than an algorithm written by a programmer.
What is a paradigm? What are six main programming paradigms?
A paradigm is a model or a pattern by which a programming language constructs is programs; it is a type of template. The six main programming paradigms are imperative, functional, logic, visual, procedural, and object-oriented.
What are compiler and decompiler?
Compiler refers to translating programs written in high-level source language down to a lower level machine-executable binary code. On contrast, a decompiler would convert machine code up to a high-level language.
What are some advantages and disadvantages of a compiler?
- Bridges the semantic gap between modern high-level languages which usable programs would typically be written in and the low-level languages which the computer must have in order to execute the program.
- Creates a program for the specific architecture which can execute efficiently.
- The compilers can identify some of the mistakes done by the programmer while coding.
- Code can be optimized for most efficient execution on specific hardware.
- Takes up less memory when the compiled program is executed.
- It may be necessary to develop and/or maintain several copies of source code to be compatible with different hardware platforms, for example when different peripheral sets are involved.
- Potentially lengthy compile times due to large amounts of source code in projects
What is an interpreter?
An interpreter is a computer program which translates high-level programs (source code) into an intermediate language, which can then later be converted into an executable language.
List some advantages and disadvantages of an interpreter.
- Easier for beginner programmers to become familiar with a language and start writing useful programs.
- Flexibility to make changes at run-time and to execute new code immediately or interactively.
- Faster to troubleshoot and fix issues since there is no need to save and re-compile the source code at every change.
- Fairly portable across computers provided the interpreter software is installed on each new computer
- Slower execution time due to each line needing to be interpreted before it is executed. There is more background overhead.
- Lack of an Integrated Development Environment to help manage code.
- Not a good platform for commercial software as the source code is not hidden in any way.
What are data structures?
Data structures are a form of organizing and storing data in a computer, so that it can be accessed and modified efficiently.
What is a queue?
A queue is an abstract data type, or a sequential collection of entities, in which the elements in the linear data structure are organized, and the only methods performed on the collection are enqueuing and dequeuing.
List the advantages of imperative programming.
- Close to machine
What is a pointer?
A pointer is a variable which contains the address in the memory of anther variable.
What is imperative programming?
Imperative programming is a programming paradigm that describes computation in terms of statements that change a program state.
What are conditionals?
Conditionals are statements used to evaluate conditions on bases of true or false in order to perform different computations.
Subroutines are blocks of code that performs a specific task. Once created, they can be called multiple times within the program or implemented into other programs with ease. Subroutines eliminate code duplication, makes code cleaner, and easier to maintain.
What are functions?
A function is a mathematical idealization of how a variable quantity is dependent upon another quantity; it is a machine, or black box, that, for any given input, has a corresponding output.
What are the two main types of functions?
The two main types of functions are the ones pre-defined by the language, and the ones that are defined by the user of the language.
This is used to evaluate an Atom to see if it has a value and returns either T (True) or NIL (False). Used many times as the first statement in a cond function to see if the Atom is not NIL and can be run through the conditional statements.
What is symbolic expression?
Symbolic expressions are a notation for nested list (tree-structured) data, invented for and popularized by the programming language Lisp, which uses them for source code as well as data.
What is defun used for?
The defun function is used for programming defined functions.