All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Ask a Question
Search
Search
Sign In
Register
study help
computer science
an experiential introduction to principles of programming languages
Questions and Answers of
An Experiential Introduction To Principles Of Programming Languages
Write down the names of programming languages that you have used or heard about. Try to identify key design goals for each of these languages.
Identify an application domain that is of interest to you. Search and list one or more domain-specific programming languages that are designed to make software development for that domain easier.
A comparative analysis of domain-specific programming language and general-purpose programming language is presented. Think of, and write down, an additional argument in favor of adopting a
For your favorite programming language, identify means of computation, means of combination, and means of abstraction.
For a recently released programming language, make a list of all the features that the language makes available. Then, categorize these features into means of computation, means of combination, and
Write down the signature and the definition of a function called odddigit. There are two ways of writing it. First is by using the definition of evendigit and the second is by doing it directly.
Write down the signature and the definition of a function called carry, which produces true if incrementing the digit will produce a carry and false otherwise.
A hexadecimal number notation represents the numbers 0–15. The traditional digits 0–9 are represented using standard digits. The numbers 10, 11, 12, 13, 14, and 15 are represented as using the
Write the signature and the definition of a function called greater, which accepts two natural numbers as arguments using the recipe discussed in this chapter. For this problem and for this entire
Write the signature and the definition of a function called listgreater, which accepts two list-of-naturals and produces true if the first list has more element compared to the second, and false
Write the signature and the definition of a function called sumof-tree, which accepts a tree of natural numbers as the argument and produces the sum of all the numbers in that tree. For this problem
Convert the following arithmetic expressions written in infix notation to the prefix notation of Arithlang.
Convert the following arithmetic expressions written in prefix notation to infix notation and count the increase in the number of operators.
Write five different arithmetic expressions using the prefix notation of Arithlang, such that each expression produces the value 42. Each expression must use all four arithmetic operators: +, −, *,
How many nonterminals and terminals are present in the grammar for the Arithlang language shown in figure 3.3? List them.
Extend the grammar of Arithlang to support a unary minus expression. Compare the production rule of the unary minus expression with the production rule for SubExp.
Rewrite the grammar of Arithlang to avoid having to duplicate the common form ExpExp+.
Write the leftmost derivations for the following programs in Arithlang.
Write the rightmost derivations for the programs in the previous exercise.Previous exerciseWrite the leftmost derivations for the following programs in Arithlang.
Arithlang grammar supports positive integers. Extend this grammar to support negative integers.
Arithlang grammar supports positive integers. Extend this grammar to support double values.
Draw the parse tree of the following Arithlang programs.Next, draw ASTs for the same programs. Finally, report on the compression ratio achieved by the AST representation. The compression ratio is
In a previous exercise, you wrote five different programs using the prefix notation of Arithlang and all four arithmetic operators +, −, *, and /, such that each expression produces the value 42.
Draw an AST diagram for the expression (+ (− 6 3) (* 4 1) (/(+ 7 2 1) 5)). See figure 3.8 for an example. Make sure that you understand why certain nodes are leaf nodes in this tree. What is the
Write an alternative implementation for the AST for Arithlang, one in which CompoundArithExp stores a field of enum type OperatorKind, modeling the concrete operator with four values, Add, Sub, Mult,
Extend the implementation of the AST for Arithlang to include an AST node for the negation expression “− Exp.”
Use the visitor design pattern to create another example of a visitor class, say ASTCounter, which counts the number of AST nodes. The methods in ASTCounter should not use any global or static
Use the visitor design pattern to create another example visitor class, say NumberCollector, which collects all numbers that appear in the AST in a list. For example, three numbers, “3,” “4,”
Examine the following different interpretations of the value of the addition expression. What effect could it have on the value of programs?An addition expression evaluates its subexpressions at
Extend the Arithlang programming language to support the least common multiple (LCM) expression, whose syntax should be (# list-of-operands). The LCM of integers is the smallest positive integer that
Write the value relation for the LCM expression. Note that you would need to account for the case of 0.
Extend the Arithlang programming language to support the modulus expression (% a b), also called a remainder sometimes. The following interaction log illustrates the intended semantics of this
Write the value relation for the modulus expression.
Extend the Arithlang programming language to support the exponential operation (** a b). The following interaction log illustrates the intended semantics of this expression:
Write the value relation for the power expression.
Extend the Arithlang programming language to support two new expressions, greatest-of (>? a b) and least-of ( a b). The following interaction log illustrates the intended semantics of this
Write down the value relation for the greatest and least expressions.
The current semantics of the Arithlang programming language does not account for divide-by-zero errors.1. Write a program that uses all the arithmetic expressions defined in Arithlang and gives a
Modify all the value relations for the Arithlang expressions to produce divide-by-zero errors, if necessary to support the semantics of that expression.
A typical calculator provides four operations to remember value: add to memory (M+), subtract from memory (M-),recall value stored in memory (MRec), and clear value stored in memory (Mclr). Extend
Write the value relation for the memory cell operations.
Convert the following arithmetic expressions, written in an informal notation, to the notation of Varlang. Also, check and write the value of each expression.
Write five different arithmetic expressions using the syntax of Varlang, such that each expression produces the value 342. Each expression must use all four arithmetic operators +, −, *, and / and
Building on the last problem, write five different arithmetic expressions using the syntax of Varlang such that each expression produces the value 342. Each expression must use all four arithmetic
Using the let expression, write a Varlang program that declares a variable pi with value 3.1415 and then uses that variable in the body of the let expression to compute the area of a circle of radius
Using the let expression, write a Varlang program that declares a variable g, the gravitational acceleration constant, with value 9.80655, another variable m, for the mass of an object, with value
Given two variables, m that stands for the mass of a rigid object and v that stands for the velocity of that object, write a Varlang program that computes the kinetic energy of that object. You may
Write all the free and bound variables in each of the following Varlang programs. If a program has none of a particular kind, state None.
Are there holes in the scope of top-level variable definitions in each of the following Varlang programs? If a program has none, state None. Otherwise, write the portions of the program that
Write the leftmost derivations for the following programs in Varlang.
Modify the grammar of the Varlang language so that the let expression can declare exactly one variable. Is this design less expressive than the previous design, where multiple variables could be
Modify the grammar of the Varlang language so that the let expression has a Haskell-like syntax. An example of such a let expression is let x = 3 in x.
Design and implement a new kind of environment, ExtendEnvList, that also implements the Env interface presented in this section. Unlike ExtendEnv, this kind of environment should allow storing
Design and implement a new kind of empty environment, EmptyEnvNice, that also implements the Env interface presented in this section. Unlike EmptyEnv, which throws an exception when a name, say
Extend the Varlang programming language such that all programs start running in a nonempty environment that predefines Roman numerals for 1–10 to their numeric values. The following interaction log
Extend the environment interface and data types to define the following additional functionalities:1. A predicate method isEmpty that returns true when the environment is empty and false
A variable occurs free in an expression if it is not bound by an enclosing let expression. Implement this predicate as an isFree method for each AST node, such that given a variable name of type
Extend the Varlang programming language from the previous question to implement a substitution-based variation of the let expression (say a lets expression). Recall that a substitution-based
Notice from the semantics and from the implementation of the let expression that Varlang doesn’t place any restriction on defining the same variable two or more times in the same let expression. In
The current semantics of the let expression in the Varlang language allows variable definitions to create a hole in the scope of the outer definition. Modify the semantics of the Varlang programming
In some operating systems, when programs deallocate memory pages, those memory pages can be allocated to other programs without any changes. In such cases, other malicious programs can read the
The current semantics of the let expression allows Varlang programmers to define multiple variables (say, var0, …, varN) and give them the values of the expressions exp0, …, expN. These
Define a constant pi with the usual value of 3.14159265359. Define a constant fourByThree, with the value of 1.33333. Using the definition of pi and fourByThree, compute the volume of a sphere with
Extend the Definelang programming language from this chapter such that it supports a variation of the define declaration, say ldefine declaration (short for “lazy define”). In a regular define
Extend the Definelang programming language from this chapter such that it supports declaring macros and macro expansion.A macro definition takes the following form:The macros described in the
Extend the Definelang programming language from this chapter such that it supports an undefine declaration. The goal of adding this new declaration is to clean up the global name space by removing
Extend the Definelang programming language from this chapter such that it supports a cdefine declaration for a constant define declaration. The goal of adding this new declaration is to define a
Using the define declaration, define a constant pi with the standard value of 3.14159265359. Use the definition of pi to define a function area of a circle that takes a radius and computes the area
Define a function called sumsquares that takes two integers as a parameter and computes the sum of square of numbers from the first number to the second number.
Define a function sumseries that takes a number n as argument and computes the series given here. Take the value of (sumseries 0) to be 0:
Experiment with built-in functions for lists.1. Use (list) to create an empty list, 2. Use (list 342) to create a list with a single element 342.3. Use (car (list 342)) to get the first element of
Write a function, sumeven, that takes a list of numbers and returns the summation of the even numbers in this list. For example:
Write a function, frequency, that takes a list, lst, and an element, elem, and returns the frequency of that element in that list. For example:
Write a function, reverse, which takes a list, lst, and returns the reverse of that list. For example:
Write a recursive function called sumPower, that takes a list of numbers, and computes the sum of 2 to the power of each element in the list.The following interactions log illustrates the semantics
Write a function, getbooks, that takes in a list of lists with author/book string pairs and returns a single list of only the books. Assume that the author is the first element and the book is the
Write a function, triangle, which takes a number and produces a list, each element of which is a list of symbols.When triangle is called with a nonnegative integer, n, it returns a list containing n
Write a procedure, board, which takes a integer number as input and produces a list as an output, each element of which is a list of 0s and 1s.When board is called with a nonnegative integer, n, it
Write a function carpet that takes one nonnegative natural number as the argument and produces a list as shown in the examples.You may assume that the argument of carpet will always be a nonnegative
Pascal’s Triangle The pattern you see here is called Pascal’s Triangle:The numbers at the edge of the triangle are all 1, and each number inside the triangle is the sum of the two numbers above
Define a function filter with the following signature:The function takes two inputs, an operator test_op, which should be a single argument function that returns a Boolean; and lst, which should be a
Define a function foldl (fold left) with three parameters, op, zero_element, and lst. The parameter op itself is a two-argument function, zero_element is the zero element of the operator function
Define a function foldr (fold right) with three parameters, op, zero_element, and lst. The parameter op itself is a two-argument function, zero_element is the zero element of the operator function
If f is a numerical function and n is a positive integer, then we can form the nth repeated application of f, which is defined to be the function whose value at x is f(f(…(f(x))…)). For example,
The idea of smoothing a function is an important concept in signal processing. If f is a function and dx is a small number, then the smoothed version of f is the function whose value at a point x is
The greatest common divisor (GCD) of two numbers a and b is defined as follows: If a > b, then (gcd a b) is gcd of a - b and b. Else, if a 1. Define a function gcd that computes the GCD according
Define a higher-order function forloop that takes three arguments: an initial value (counter) representing the initial value of the loop counter, a function (condition) representing a test expression
Define a function, record, which takes a list of strings, fields, and a list of values, values, and returns a procedural representation of record. Write a second procedure, lookup, which takes a
Define a procedural representation of a binary tree. A binary tree is either a terminal node that contains a value or a nonterminal node containing two children that are both binary trees. Define two
Write a curried form of a function using a lambda abstraction that takes the length, width, and height of a cuboid and computes the volume of the cuboid by multiplying the length, width and
Define a curried version of the following procedure, calling it speed-mph:
Using your solution from problem 6.6.2, define a procedure as follows:Problem 6.6.2Define a curried version of the following procedure, calling it speed-mph:
Optimize the function call semantics by reducing the size of the environment saved in FunVal so that it contains only mappings from free variables in the function body to their bindings in the
Extend the Funclang programming language from problem 6.9.1 to implement a substitution-based variation of the call expression (say [ ] expression). Recall that a substitution-based semantics works
Extend the Funclang programming language to implement a tracing lambda expression tlambda, which prints “Entering a function” before starting to run the function body, and “Exiting a
An alternative to static binding is dynamic binding, in which the function body is evaluated in an environment obtained by extending the environment at the function call point (instead of the
In this question, you will explore a semantic variation of function call and return.A function definition can provide default values for the function’s parameters. Extend the Funclang interpreter
In this question, you will explore a semantic variation of function call and return.A function can take an implicit parameter. Extend the Funclang language to support function calls that can
In this question, you will explore a semantic variation of function call and return.A function can take a variable number of parameters. Such functions are known as varargs or variadic functions.
In the realization of call-by-name discussed so far, a promise is created for each argument expression.That might seem like overkill. For instance, we don’t need promises for numeric values like 42
Showing 1 - 100
of 156
1
2