“Rather fail with honour than succeed by fraud.”
– Sophocles
[IS 214] Principles of Programming Languages
Supplementary Material Answer to Discussion Questions FIC: Asst.
Prof. Reinald Pugoy
[email protected] Faculty of Information and Communication
Studies, UP Open University
1. Why were programming languages born? Why are there so many
programming languages out there?
Simply because of need. It is human nature to be always in
pursuit of something that will address their needs. Due to the
diverse needs in computing and proliferation of problems that
required to be solved, these translated to several application and
programming domains. Hence, many PLs were created here and there to
address them.
2. “When writability is enhanced, readability suffers.”
These 2 codes perform addition of 2 numbers:
Machine Language COBOL
0010 0001 0000 0100 0001 0001 0000 0101 0011 0001 0000 0110 0111
0000 0000 0001 0000 0000 0101 0011 1111 1111 1111 1110 0000 0000
0000 0000
IDENTIFICATION DIVISION. PROGRAM-ID. ENVIRONMENT DIVISION. DATA
DIVISION. WORKING-STORAGE SECTION. 77 A PIC 9999. 77 B PIC 9999. 77
ANS PIC 999v99. PROCEDURE DIVISION. MAIN-PARA. DISPLAY " ENTER A ".
ACCEPT A. DISPLAY " ENTER B ". ACCEPT B. ADD-PARA. ADD A B GIVING
ANS. DISP-PARA. DISPLAY "A IS " A. DISPLAY "B IS " B. DISPLAY
"ADDITION =" ANS. STOP RUN.
“Rather fail with honour than succeed by fraud.”
– Sophocles
[IS 214] Principles of Programming Languages
Supplementary Material Answer to Discussion Questions FIC: Asst.
Prof. Reinald Pugoy
[email protected] Faculty of Information and Communication
Studies, UP Open University
Let me ask you. Which of these 2 codes is more readable? More
writable?
Machine Language is writable for it only requires you to know 2
symbols - 0 and 1. No curly braces, semi-colons, parenthesis, etc.
to bother you. However, it does not make sense when you attempt to
understand a machine code. On the other hand, COBOL is readable as
it closely resembles the English language, which we all understand
(even non-programmers can possibly understand). But, you need to
know lots of symbols and syntax rules to form a valid COBOL
program, not to mention the indention and the column number where
you need to write your code. As you can see, there is a trade-off
between readability and writability.
References (Codes):
•
http://people.uncw.edu/tompkinsj/242/BasicComputer/AddTwoNumbers.htm
• http://www.dailyfreecode.com/code/two-numbers-1897.aspx
3. Is it possible for a semantically incorrect statement to be
syntactically correct?
Yes, that is possible. Example: a = 9 / 0;
This is syntactically correct in C, Java, and in several other
PLs. However, we cannot divide something by zero. It is
meaningless, as we learned in mathematics. You may refer to this
link for other examples:
http://www.inf.unibz.it/~calvanese/teaching/ip/lecture-notes/uni10/node6.html
4. Why is studying grammar important and essential in
understanding and implementing programming languages?
This is because grammar defines the valid syntactical structure
or syntax a programming language has. In other words, it tells us
whether a particular statement has syntax error. Let us illustrate
this by using a natural language, say the English language. In the
Philippines, we learned English grammar since we were young.
Because of it, we can converse in English. What if we do not know
the proper English grammar? Instead of saying “I wanna ride the
jeep with you”, you say “I jeep ride you”, which is completely
non-sense. The same principle applies in PLs. If we do not know the
grammar and its resulting syntax, how can we communicate to the
computer the instructions we wish it to do?