Syntax in programming is defined as the form of expressions, program units, and statements.
Semantics, on the other hand, is the meaning of these expressions, program units, and statements (Stroustrup, 2014).
Axiomatic Semantics – An approach which attempts to provide rules that indicate the relevant changes I data immediately after the execution of a feature in a given programming language.
Denotational semantics – defines programs basing on mathematical functions and utilize these functions to obtain the properties of the program (Stroustrup, 2014).
Syntax: Set of instructions which specify how to write a given programming language.
Semantics: Relates to the meaning of an instruction e.g. a++.
Parse trees and derivation connection is so close. Parse trees or derivations can be constructed from one another. Derivations that have unambiguous grammar contain unique parse trees.
Values of synthesized attributes are computed basing on the attribute values of child nodes while the value on an inherited attribute is computed basing on the attribute values of parent and sibling nodes
Attribute grammars are used for:
Compiler design
Static semantic specification
Problem Set
a). Associativity:
→ |
from left to the right |
= |
is right to the left |
+ |
is left to the right |
| |
is left to the right |
* |
is left to the right |
b). Precedence of operators from high to low
Precedence |
Operator |
2 |
→ |
5 |
* |
6 |
+ |
13 |
| |
16 |
= |
c). Left most derivation
E = Expression
T = Term
E = E + E
= E * E + E
=T * E + E
=factor * E+ E
= id * E + E
=B * T + E
=B *factor + E
=B * id +expr
=B * D +expr
= B * D + term
= B * D + factor
= B * D + id
= B * D +C
Parse tree
This grammar contains two parse trees hence it is ambiguous.
E
E + E
b E * E
c b
TREE 1
E
E * E
E + E b
b c
TREE 2
There is more than one parse tree when deriving b + c * a Thus this grammar is ambiguous
Unambiguous grammar
E → E * T | T
T → T * int | int (E)
This is unambiguous as it only has one parse tree
EBNF Grammar
→ begin < stm_list> end
→ {; }
→ =
→ A | B |C
→ [(+| -)
→ a |
A → aA | bc A
(c + 10) / 3 > 6
c + 10 > 18
c > 8
Weakest precondition is c>8
b). x – 3 > -2 * 1
x > -2 *1 + 3
x > 1
Weakest precondition is x > 1
Chapter 5
R-value is the value of the variable. This is what is needed when the variable name appears at the right side of an assignment.
Binding time is the time taken when performing binding.
Load time: used for binding a C++ static variable to a memory cell
Runtime: binding a non-static local variable to a memory cell
Compile time: binding a variable to a type in Java or C++
Static binding happens before runtime and does not change all through the process of execution.
Dynamic binding happens in the process of execution and is able to change during this phase of execution.
Static memory is apportioned before execution starts and stays bound to a similar memory all through the execution time
Advantages – Run-time proficient.
Disadvantages – There is no recursion.
Stack-dynamic memory designation of the system is a pile when declarations are examined/depicted.
Advantages – There recursion and memory-efficiency.
Detriments: Run-time isn’t as effective as static.
Explicit heap-dynamic designation and deallocation are with explicit directions, determined by the programmer, which is substantial for execution.
Advantages – adaptable capacity administration.
Weaknesses: Prone to blunder in making new statements or delete statements.
Implicit heap-dynamic distribution and deallocation is caused by a statement.
Advantages – Flexibility is high.
Drawbacks – When the run-time to keep all the attributes dynamic compiler mistake discovery is decreased.
Lifetime is when memory is apportioned for a variable (if the variable it exists).
The scope is the range of statements whereby the variable is visible. E.g. variables show up in an if statement.
The static scope is a degree that depends on program text and link reference to a variable name.
Dynamic scope is a scope that depends on run-time call sequence.
A reference to a non-local variable in a static-scoped language needs access through a two-step process, that is; Finding the right activation record and Noting the right offset in an activation record.
The static ancestors are every one of the strategies in the program inside where the methodology is characterized, for instance, the meaning of the procedure is nested. The meaning might be specifically settled inside just a single procedure, known as a static parent procedure. In any case, this strategy may itself be nested inside another method, et cetera up to the program that is main(). Every one of these techniques are thought to be static predecessors of the procedure sub(). Basically, those that entirely contain the subprogram being referred to are the static predecessors/ancestors.
Dynamic ancestors – These are every one of the procedures that are called before the sub program between the running of a program and those which have not yet completed the process of execution. They are the strategies that are sitting tight for procedure sub() to complete the process of executing before finishing. Basically, dynamic predecessors are those which are accessed to achieve the subprogram that is being referred to.
ML does not require type presentations if the understanding is unambiguous and can be deduced from other data.
Blocks are a dialect-level component added to common programming languages which enable you to make unmistakable portions of code that get passed around to methods or functions as though they were values (Gordon, Henzinger, Nori & Rajamani, 2014).
Blocks are Objective-C objects, which implies that they can be added to accumulations like NSArray or NSDictionary.
Named constant is a descriptive name given to a particular constant value. It is efficient to declare a constant by assigning it a name so that it can be used many times in a program.
Int p =3.14159
Int r = 7
Int area =0.5 * p * r*r
p will be used anywhere in the program instead of repetitively writing the number 3.14159
Problem Set
The variables a and b are bound during load time.
Variable c is bound at compilation time while variable d is bound during runtime of the program
The referencing environment inside sub 2 is:
Dynamic referencing: will contain the variables c, f, h, and j.
Static referencing: will consist of the variables b, e, h and i.
int main()
{
int x = 0;
++x;
{
int x = 1;
x = 12;
cout<<x<<endl;
}
}int y = x;
If this program is executed, an error is found in the last line:
{error: ‘x’ was not declared in this scope} , however, when we get rid of the last line in the code. We shall have an output that prints the value 12.
References
Gordon, A. D., Henzinger, T. A., Nori, A. V., & Rajamani, S. K. (2014, May). Probabilistic programming. In Proceedings of the on Future of Software Engineering (pp. 167-181). ACM.
Stroustrup, B. (2014). Programming: principles and practice using C++. Pearson Education.
Essay Writing Service Features
Our Experience
No matter how complex your assignment is, we can find the right professional for your specific task. Contact Essay is an essay writing company that hires only the smartest minds to help you with your projects. Our expertise allows us to provide students with high-quality academic writing, editing & proofreading services.Free Features
Free revision policy
$10Free bibliography & reference
$8Free title page
$8Free formatting
$8How Our Essay Writing Service Works
First, you will need to complete an order form. It's not difficult but, in case there is anything you find not to be clear, you may always call us so that we can guide you through it. On the order form, you will need to include some basic information concerning your order: subject, topic, number of pages, etc. We also encourage our clients to upload any relevant information or sources that will help.
Complete the order formOnce we have all the information and instructions that we need, we select the most suitable writer for your assignment. While everything seems to be clear, the writer, who has complete knowledge of the subject, may need clarification from you. It is at that point that you would receive a call or email from us.
Writer’s assignmentAs soon as the writer has finished, it will be delivered both to the website and to your email address so that you will not miss it. If your deadline is close at hand, we will place a call to you to make sure that you receive the paper on time.
Completing the order and download