You are on page 1of 5

REVIEW QUESTIONS: ----------------------------------------------------------------------What is the difference between syntax and semantics?

--A language is an arbitrary association of collection of forms with their meaning s. Syntax is the specification of the forms. Semantics is the specification of the meanings. === The translation process summary --1. Lexical Analysis: Converts source code into sequence of tokens. (use regular grammers, finite state automata) 2. Syntactic Analysis: structures tokens into initial parse tree. (use C FG's and parsing algorithms) 3. Semantic Analysis: annotates parse tree with semantic actions. (annot ates parse tree with semantic actions) 4. Code Generation: Produces final machine code. === What is the difference between compilation and interpretation? --Compilation is the process of translating source code into target code that can then be executed by users and other programs. Interpretation is the process of passing the source code to an interpr eter that analyzes the code as the program executes and displays results right away. === What is the difference between regular, context-free, and non-context free languages? --A regular language is a language that can be expressed by a regular expression. Context-free languages is a bigger class that contains regular languages that ca n also be expressed by a Context-Free-Grammer. Non-Context free languages, are languages where there are no Context-Free-Gramme rs to generate those languages. === Why do we use formal languages to define programming languages? --We use formal languages to define programming languages because it is a clear wa y to see the abstraction of the language. We can clearly define, prove, and analyze formal languages to produce effecient implementations of programming languages. === What are some differences between an imperative language, and a declarative language? --Declarative Imperative States what to compute States how to compute Many hows can be submitted by a single what Must satisfy cases to answer the many whats Unification is part of the language Unification not always i mplemented.

=== Briefly explain the translation process for a compiled language. --In the translation process for a compiled language, the source code is first pas sed through a compiler that translates it to the target code used by users and other languages for execution. The input is passed through the target code, and is returned by the target code. === Briefly explain the difference between a low, medium, and high level programming language . --Programming languages in low level have very minimal abstraction. It explicitly uses the structure of the underlying machine. Medium level languages have some abstraction and some dependence on the machine structure. High level languages have high level of abstraction and very minimal dependence on machine architectu re. === List a few traits that make a good programming language. Choose one and explain it. --- A programming should be easy to understand and read - Should be easy to learn - Code should reflect the programmers intuition - Simple Syntax. - I choose: Code should reflect the programmers intuition. - A good language would provide the user with functions that are named t o reflect the action that they perform. For example the reverse function in the language is expected as the name implies to reverse a list of items. It wouldn't be intuitive to return the string with characters in random order. ===

Explain each of the following features or properties of Scheme, using examples: Referential transparency - The value of a function application is independent of the context in w hich it occurs. - For example the value of f(a,b,c) only depends on a,b,c. It does not d epend on the global state of computation. no assignment statement in pure Scheme - A variable may not have a value, or its value is a function that has n ot been applied to its arguments yet. Values that are acquired at the course of evaluation are re tained untill the end of evaluation. - Similar concept with the use of variables in mathematics. Binding Time - The point in time when symbolic references to data are converted into

physical machine addresses. - Static binding - Known as early binding, any time before runtime - Dynamic binding - known as late binding - generally considered runtime binding. static scoping - scope is determined before runtime. Scopes are lexically determined (b y the context of the function definition). dynamic scoping - Dynamic scopes depend on the context in which a function is called at runtime. dynamic typing - Type binding, if any is done at runtime. Same identifier can have diff erent types. - In static typing the identifier is bound to a type as well as to data. recursion vs iteration - Recursion is preferred style to itterative constructs like while loops or for loops - makes it easier to prove correct - easier to conceptualize as functions. implementations properly tail-recursive - an implementation of a proper tail-recursive function would require th e recursive call to be the last function appliction in the function body. functions are first class values: created dynamically, stored, passed as paramet ers, returned as results, etc. - function are first class values, means that the functions can be used as parameters in other functions and be returned as variable. pass-by-value - The formal parameter is bound to the value of the actual parameter. - This is as opposed to pass by reference. automated memory management - All storage management is implicit. - we dont have to think about how program state maps to a comput er memory. - its easier to think about the state of computation === How does the Scheme or Python map function differ from a Python for item in list : loop? --In scheme map performs iteration over a list of items in parallel order instead of sequential. === How are functions values in Scheme? --- The functions values are data types addresses ===

Why should we use tail recursion when possible? --Recursion is easier to prove correct and easier to conceptualize as func tions === Create an ambiguous grammar for code comments /* delimited like so */, then crea te an unambiguous one. --S -> ************************* *** DO THIS *** ************************* === What does it mean that Scheme has no side-effects? --- It means there is no need to consider global states, the program is ea sy to prove correct. === Create a tail-recursive function to compute the nth number the fibonacci series. --Scheme fibonacci. ************************* *** DO THIS *** ************************* === What is the difference between syntax and semantics? --Syntax deals with the form of a language, while semantics deals with spe cifying the meaning of the language. === What is the difference between denotational and operational semantics? --Denotational semantics: a declaration of what an expression means. Operational semantics: an elucidation of what the programmer is asking u s to do. === Can you implement "append" with just the "cons" function? --Yes. (define append (lambda (x y) (if (empty? x) y (cons (car x) (append (cdr x) y)) ) ) ) === What is a horn clause? --A horn clause is logical statement made from antecedents and consequent Antecedents: conjunction of zero or more atomic formulae Concequent: an atomic formula

=== What is unification? How is it different than assignment? --Assignment is the process of creating a memory spot and storing a value in that memory spot to reference it later through the program using a variable or a pointer. Unification on the other hand is the process of using the equal sign to show that both sides (left and right) are exa ctly the same. In Assignment X=2 stores a value in X, but Unification X=2 will find a v alue X that unifies with the right hand side 2 (X will be 2). === How is Prolog a declarative programming language? --Prolog requires the declaration of predicates. It does not use functions as a way of computing, instead it uses facts and rules. === Explain one way that Prolog is not purely declarative. --=== What is backtracking? --The process prolog takes to systematically search for all possible solut ions that can be obtained via unification and backchaining. === How does cut (!) work? --The cut goal trims the derivation tree of all other choices on the way b ack up to and including the point in the derivation tree where the cut was introduced into the sequence of goals.

You might also like