









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A comprehensive guide to cs 326 midterm exam, covering key concepts and providing answers to common questions. It delves into various aspects of compilation, programming languages, and computer science fundamentals, offering valuable insights for students preparing for the exam.
Typology: Exams
1 / 15
This page cannot be seen from the preview
Don't miss anything!
List the phases of front end compilation ---------CORRECT ANSWER--------- --------Character stream => scanner(lexical analysis) => token stream => parser(syntax analysis) =>parse tree => semantic analysis and intermediate code generation List the phases of back end compilation ---------CORRECT ANSWER--------- --------Semantic analysis and intermediate code generation => - abstract syntax free or other intermediate form => machine independent code improvement(optional) => modified intermediate form => target code generation => assembly or machine language or other target language => machine specific code improvement (optional) => modified target language == symbol table What are regular languages? ---------CORRECT ANSWER-----------------A subset of context free ones What is a formal language? ---------CORRECT ANSWER-----------------A set of strings of symbols drawn from a finite alphabet Name the qualities of a scanner ---------CORRECT ANSWER-----------------โ ignores white space (blanks, tabs, new-lines) โ ignores comments โ recognizes tokens โ implemented as a function that returns next token every time it is called
Name the qualities of a parser ---------CORRECT ANSWER-----------------โ calls the scanner to obtain tokens โ builds parse tree โ passes it to the later phases (semantic analysis, code generation and improvement) What can expressions be in Scheme ---------CORRECT ANSWER------------ -----atoms or lists What is an atom in Scheme? ---------CORRECT ANSWER-----------------a number, string, identifier, character, or boolean What is a list in Scheme? ---------CORRECT ANSWER-----------------a sequence of expressions separated by spaces, between parentheses What to constant atoms evaluate to? ---------CORRECT ANSWER------------ -----themselves What do identifiers (symbols) evaluate to? ---------CORRECT ANSWER----- ------------the value bound to them What do lists evaluate to? ---------CORRECT ANSWER----------------- evaluate as "function calls"
Name the two storage allocation mechanisms ---------CORRECT ANSWER- ----------------Static and Dynamic Describe static allocation ---------CORRECT ANSWER-----------------each object is given an address before execution begins and retains that address throughout execution Describe Dynamic allocation ---------CORRECT ANSWER-----------------โ Stack - objects are allocated (on a stack), and bindings are made when entering a subroutine โ Heapโ Explicit - allocated and deallocated by explicit directives at arbitrary times, specified by the programmerโ Implicit - allocation and deallocation are implicit (transparent for the programmer); requires garbage collection Describe and give examples of languages that are Statically (also called lexically) scoped ---------CORRECT ANSWER-----------------โ Bindings are determined by examining the program text โ Can be determined at compile time โ Examples: C, Pascal, Scheme Describe and give examples of languages that are dynamically scoped ----- ----CORRECT ANSWER-----------------โ Bindings depend on the flow of control at run time (on the dynamic sequences of calls) โ Choose the most recent active binding (at run time) โ Examples: APL, Snobol, early Lisp
explain the differences between shallow vs. deep binding --------- CORRECT ANSWER-----------------โ deep binding - use the environment from the moment when the function was passed/stored/returnedโ shallow binding
What is syntax? ---------CORRECT ANSWER-----------------What a program looks like What are semantics? ---------CORRECT ANSWER-----------------What a program means What is implementation? ---------CORRECT ANSWER-----------------How a program executes What languages are used for systems programming? ---------CORRECT ANSWER-----------------C, Modula- 3 What languages are used for scientific computations? ---------CORRECT ANSWER-----------------Fortean, Ada What languages are used for embedded systems? ---------CORRECT ANSWER-----------------C,Ada,Modula- 2 What languages are used for symbolic computing? ---------CORRECT ANSWER-----------------Lisp,Scheme,ML What does imperative mean? ---------CORRECT ANSWER----------------- How should the computer do it
What does declarative mean? ---------CORRECT ANSWER----------------- What should the computer do What types of programming are imperative? ---------CORRECT ANSWER--- --------------Von Neumann, Object-oriented What types of programming are Declarative? ---------CORRECT ANSWER-- ---------------Functional, logic and constraint based Name von Neumann languages ---------CORRECT ANSWER----------------- Fortran, Basic, Pascal, C Name object-oriented languages ---------CORRECT ANSWER----------------- Smalltalk,Eiffel, C++, Java Name functional languages ---------CORRECT ANSWER-----------------Lisp, Scheme, ML, Haskell Name logic and constraint based languages ---------CORRECT ANSWER--- --------------Prolog Explain machine language ---------CORRECT ANSWER------------------ sequence of bits that directly controls the processor
When are arguments evaluated? ---------CORRECT ANSWER----------------- โ Before being passed to the function (applicative-order evaluation): in most languages, safer, more clear โ Pass a representation of unevaluated parameters to the function; evaluate them only when needed (normal-order evaluation): typical for macros, can be faster Why are the front end and the back end of a compiler usually implemented as separate passes? ---------CORRECT ANSWER-----------------The front makes the source language program understandable, the back maps programs to the target machine Is C++ a weekly typed language? ---------CORRECT ANSWER----------------- Yes, because it has many features that deliberately weaken its type system. For example, type casting allows you to interpret a field of a structure that was an integer as a pointer. Is the syntax of a language the grammar rules of that language? --------- CORRECT ANSWER-----------------Yes, syntax is generated by the languages under the grammar. Is C++ a static/lexical scoped language? ---------CORRECT ANSWER------- ----------Yes Explain orthogonality in the context of a language design. Give an example. ---------CORRECT ANSWER-----------------Orthogonality in a programming language means that a relatively small set of primitive constructs can be
combined in a relatively small number of ways to build the control and data structures of the language. It is associated with simplicity. Eg. Inheritance, pointers in c++, function, etc. Explain why type checking impacts the reliability of a language. Give an example. ---------CORRECT ANSWER-----------------Type checking impacts the reliability of a language because it helps prevent certain types of errors that can occur during program execution. When a programming language has strong type checking it means the compiler or interpreter can catch errors related to type mismatches before program execution. This can help in avoiding runtime errors that can be difficult to debug and cause the program to crash. x = "5" y = 3 z = x + y print(z) Explain static semantics and why it cannot be enforced by the parser. Provide an example to justify your answer. ---------CORRECT ANSWER----- ------------Static semantics are thing like scoping of a variable which are determined during compile time. This is because static semantics often require contextual information that is not present in the syntax of the program such as the types of variables or the scope of identifiers. An example is inheritance since the parser doesn't know how this works. public class Example { public static void main(String[] args) { int x = 5; boolean b = x; // ERROR System.out.println(b); } }
TEXTBOOK and SLIDES ---------CORRECT ANSWER----------------- Feature Multiplicity ---------CORRECT ANSWER-----------------having more than one way to accomplish a particular operation Problem with operator overloading (a single operator has more than one meaning) ---------CORRECT ANSWER-----------------it can lead to reduced readability if users are allowed to create their own overloading and do not do it sensibly. Type checking ---------CORRECT ANSWER-----------------simply testing for type errors in a given program, either by the compiler or during program execution. Type checking is an important factor in language reliability. Aliasing ---------CORRECT ANSWER-----------------having two or more distinct names in a program that can be used to access the same memory cell. Categories for evaluating programming languages ---------CORRECT ANSWER-----------------1. Simplicity
Application Domains of Programming Languages ---------CORRECT ANSWER-----------------1. Scientific Programming (e,g. R, Fortran)