Tuesday 26 March 2013

Review & Problem Set for Chapter 3 from Concepts of Programming Languages Tenth Edition by Robert Sebesta

REVIEW Chapter 3

1. Define syntax and semantics.
the syntax of a programming language is the form of its expressions, statements, and program units. Its semantics is the meaning of those expressions, statements, and program units.

3. Describe the operation of a general language generator.
Language generator is a device that can be used to generate the sentences of languages. Language generator operates by generating a sentence of language, however language generators is unpredictable.

5. What is the difference between a sentence and a sentential form?
The difference is that a sentential form is any string derivable from the start symbol while sentence is a sentential form which contains only terminal symbols.

6. Define a left-recursive grammar rule.
A left recursive grammar rule is a grammar rule that has its left hand side also appearing at the beginning of its RHS, this left recursion specifies left associatively.

8. Distinguish between static and dynamic semantics.
The static semantic define restriction on the structure of valid texts that are hard or impossible to express ins standard syntactic formalisms while dynamic semantic defines how and when the various constructs of a language should produce a program behavior.

10. What is the difference between a synthesized and an inherited attribute?
The synthesized attributes are the result of the attribute evaluation rules, and may also use the values of the inherited attributes. The inherited attributes are passed down from parent nodes. In some approaches, synthesized attributes are used to pass semantic information up the parse tree, while inherited attributes help pass semantic information down it.

12. What is the primary use of attribute grammars?
An attribute grammar is a device used to describe more of the structure of a programming language than is possible with a context-free grammar. An attribute grammar is an extension to a context-free grammar. The primary purpose of an attribute grammar is it allows certain language rules to be described, such as type of compatibility. An attribute grammar is a formal way to define attributes for the productions of a formal grammar, associating these attributes to values.

19. What two things must be defined for each language entity in order to construct a denotational description of the language?
objects and functions

20. Which part of an inference rule is the antecedent? 

The antecedent is the top part of an inference rule.

21. When a grammar rule said to be left recursive?
When a grammar rule has its LHS also appearing at the beginning of its RHS, the rule is said to be left-recursive. This left recursion specifies left associativity.


PROBLEM SET Chapter 3

1. Syntax Error and semantic error are two types of compilation error. Explain the difference between the two in a program with examples
Syntax error is due to we doesn't follow the rule of a language and the compiler/interpreter unable to recognize, for example in C, missing a semicolon, will result in a syntax error. While semantic error is a logical error, for example 5 + 5 = 7.

3. Rewrite the BNF of example 3.4 to represent operator – and operator / instead of operator + and operator *.
.       <assign> => <id>  = <expr>

.       <id> => A|B|C

.       <expr>=> <expr> – <term> | <term>

.       <term> => <term> / <factor> | <factor>

.       <factor>=> (<expr>)   | <id>


10. Describe, in English, the language defined by the following grammar:

<S> -> <X> <Y>

<X> -> x<X> | x

<Y> -> y<Y> | y


Answer :
<S> -> <X> <Y>

S is defined as the statement <X> <Y>

.        <X> -> x<X> | x

while <X> itself is defined as x<X> or just x(this statement is able to loop back to X so that X can contain x inside the function. This will result in an k number of x

.        <Y> -> y<Y> | y

while <Y> is defined as y<Y> or just y(this statement is able to loop back to y so that Y can contain a inside the function. This will result in an j number of y (same case as X)

because X can contain k number of x and Y can contain j number of y, this will result in <S> -> k*<x >j*<y> whereas k is >= 1 and j is >= 1 therefore allowing unlimited amount of x and y.
 

11. Consider the following grammar:

<S> -> <A>a <B> b

<A> -> <A>b | b

<B> -> a<B> | a


Answer :
in my opinion, none of those are the language generated by the grammar, it should be k<A>aj<B>b,(A contains b and B contains a) in which the end will be a single b, the list of answer does not include an answer that ends with a single b

13. Write a grammar for the language consisting of strings that have n copies of the letter a followed by double the number of copies of the letter b where n > 0. For example, the string abb, aabbbb, and aaaabbbbbbbb are in the language byt a, aabb, ba, and aaabb are not.
<S> => a<S>bb<S>  | abb


15. Convert the BNF of example 3.1 to EBNF.
.       <program> -> begin <stmt_list> end

.       <stmt_list> -> stmt[stmt_list]

.       <stmt> -> <var> = <expressions>

.       <var> -> A| B | C

.       <expressions> -> <var> {(+|-)< var> }


16. Convert the BNF of example 3.3 to EBNF.
.      <assign> -> id = <expr>

.      <id> -> A|B|C

.      <expr> -> <expr> {(+ | *) <expr>) | <id>


17. Convert the following EBNF to BNF:

S -> a{bA}

A ->a[b]A


Answer :

.    S -> A | AX

.       X -> bA | bAX

.       A -> aA | abA


18. What is a fully attributed parse tree?
A fully attributed parse tree is a parse tree which are the attributes in all its nodes are computed.

Tuesday 12 March 2013

Assignment for Programming Language Concept

Review Chapter 2

from Concept of Programming Languages (Tenth Edition) by Robert Sebesta

1. Plankaltul designed between 1936 and 1945, while published in 1972

2. Plankaltul has some advanced features in data structure area and what most interesting was the inclusion of mathematical expressions showing relations between the variables

3. Plankaltul mean program calculus

4. Speedcoding include the operations of floating-point operators and include the novel facility of automatically incrementing address register

5. the words of UNIVAC 1's memory had 72 bits, grouped as 12 six-bit bytes'

6. IBM 704 has indexing and floating-point instructions in hardware, heralded the end of the interperative era
7. John Backus is the one who developed the speed coding for IBM 701

8. Short Code was developed by John Mauchly, short code wasn't translated to the machine code, rather it was implemented with a pure interpreter, therefore it was the cause this programming called automatic programming

10. One of the significant features of Fortran 2 that Fortran 1 don't have is the independent compilation of sub-routines

11. Fortran 77 retained most of the features of Fortran IV, and added with character string handling, logical loop control statement, and modules

12. Fortran 90 is the first one who has the dynamic variables

13. Fortran 77 is the first one who implemented character string handling

14. The linguist is concerned with the natural language processing, one of the beginning reasoning to AI development

15. Pure LISP has only two kinds of data structures : atom and lists.

16. Scheme is a small language with simple semantics and syntax, because of this, Scheme is well suited for education purpose, while common LISP is a large and complex language with a primitive functions

18. Algol 60 is a joint language project by GAMM ( german acronym for Society for applied Mathematics and Mechanics) and ACM (Association for Computer Machinery)

22. COBOL was based on FLOW-MATIC language, that was implemented in 1957

23. COBOL design project begin on May 28,29, 1959 at the Pentagon

24. The hierarchical data structures which is first appeared in 
the Plankatul were first implemented in COBOL

26. The original BASIC only have floating point data type

Problem set

5. i think one of the most hard to achieve is to speed for compiling process for a variety of programs, because computers at that time was expensive and have small memory and relatively unreliable

11. i personally think IBM is correct because trying to create an universal language that can be used in every aspect is good, but it would cause the language itself becoming a complex and large memory consumption, the downside is that

12. Procedural language determines WHAT & HOW a process should be done, Non-procedural language is concerned with the WHAT not the HOW. Non-procedural languages are those languages where you specify what conditions the answer should satisfy, but not how to obtain it.

13. In my opinion, C was a multipurpose language with wide variety and easy to understand, while Fortran is a scientific language, so people would prefer C than Fortran

14. i think the plus of type less language is made the programmer to be creative and, there are no restriction to the use of types, but the minus is the program would be hard to recognize and could become confusing, because there are no boundary between types

15. yes, SQL and Visual Basic

16. because the more simpler the language made it easier to modify and improves it readability to another programmer

17. Usually language design by committe are limited with the "goals" they made, and they need to calculate the cost of creating process, moreover if the one creating is a business based committe, they would make it cost-effective as possible so when goes to the market, the language can be sold at a fair price












Saturday 2 March 2013

Answer for Exercise Chapter 1 - Programming Language Concept Program

Review chapter 1

1. because we need to understand the basic concept and sometimes, we can apply other languange trict to solve a problem in a higher level language

2. because the knowledge of programming languange can  made us to express new ideas and also made learning other language easier

3. Fortran the name is a blend derived from The IBM Mathematical Formula Translating System

4. COBOL (COmmon Business-Oriented Language)

5. LISP ( "LISt Processing") and Prolog (a general purpose logic programming language associated with artificial intelligence and computational linguistics )

6. UNIX, right now mostly written by C

7. because they causing something that can be solved simple, become complex because too many combinations dan variations can be used

8. because, if the user allowed to create a overloading operator and do not do it sensibly, it may cause reduced readability

Case study chapter 1

1. yes, because we need to understand first the command we use, instead using unknown words, it would made the problem much simpler

2. from wikipedia, Ada Lovelace, was an English mathematician and writer chiefly known for her work on Charles Babbage's early mechanical general-purpose computer, the Analytical Engine. Her notes on the engine include what is recognized as the first algorithm intended to be processed by a machine. Because of this, she is often considered the world's first computer programmer. 

6. i believe the readability of a program is very important because it made someone else could understand what i made

7. semi colons made the program readability increased i think because it was clear where the statement would end, but those without i believe would increase the coding time

8. pros : this design made us easier to tell where is the error and simplicify the main program. cons : if we doesn't place the function in the right place or made too many, it would become confusing

9. orthogonality made the data type can be used many ways and because of this the powerful structure of data structures can be made, therefore without this, the program would become very long and confusing

12. not, because, as i know, we need to combine every aspect of a programming language, even made the function by ourself, furthermore, we would complement what missing with the other languanges trick, i would not say some is complete because can be used for many usage but because the language itself was made to be flexible

13. the first high level language i learn is C i believe that is working with a compiler, using microsoft visual studio