Вы находитесь на странице: 1из 2

PROGRAMMING LANGUAGES

Ryan Llorca Nuada


BSCS 2B

1. In your own words define syntax.


2. Enumerate the 4 criteria for evaluating the syntax for Programming Language. I
know you are familiar with C Language, evaluate C using the 4 criteria you
enumerated.
3. Given the list syntactic elements, identify them in C Language.
4. In your own words define ambiguous grammars, why it is important that a
grammar for the Programming Language should not be ambiguous?

Answers:

1. Syntax is the forms which programs are written.

2. The four criteria for evaluating the syntax of programming languages are:
readability, writability, ease of translation and lack of ambiguity.
In terms of readability, C is of course much less readable compared to
Pascal. The use of braces enclose group of statements instead of begin and end in
Pascal contributed to its being less readable compared to Pascal.
In terms of writability, however, C is better compared to Pascal and
COBOL. The short keywords being used in the language and the use of braces to
enclose group of statements contribute to this.
The syntax of C is quite small. Hence, it is very easy to write a compiler
for it. At least it is easier to write a compiler compared to Pascal or COBOL and
much easier compared to Algol-68.
The language C is one of the languages whose syntax is unambiguous.
You cannot find any ambiguity in the syntax of C.

3. Syntactic Elements of C.

1. general syntax i. char, int, short, long


a. definitions ii. float, double
b. statements iii. string
c. keywords iv. pointer
d. b. modifiers
asm auto break case char const i. signed
continue default do double else ii. unsigned
enum extern __finally float for c. literals
goto if int long register return i. char, integer
short signed sizeof static struct ii. float
switch __try typedef union iii. string
unsigned void volatile while 3. type constructors
2. primitive data types a. struct
a. types b. enum
c. union e. control
d. array i. continue
e. pointer ii. break
f. function iii. goto
g. typedef iv. return
4. compiler directives f. exception handling
a. static i. __try
b. volatile ii. __finally
c. automatic 8. preprocessor
d. register a. #define, #undef
5. procedures and parameter passing i. simple
a. parameters ii. parameterized
i. allowable types b. #include
ii. modes c. conditional compilation
iii. … i. #if #else #endif #elif
b. result type ii. #ifdef, #ifndef
6. operators 9. scope
a. arity a. names
i. unary i. preprocessor
1. prefix ii. object
2. postfix iii. struct
ii. binary iv. enum
1. infix v. typedef
2. index b. visibility
iii. ternary i. block
b. precedence ii. unit
c. operation iii. link level
i. arithmetic 1. C
ii. bit 2. Pascal
iii. logical c. modifiers
iv. pointer and structure i. extern
v. procedure ii. static
d. type cast 10. storage management
7. statements a. code
a. expression b. static
b. compound i. uninitialized
c. conditional ii. initialized
i. if 1. string
ii. switch 2. data
d. iterative c. heap
i. for d. stack
ii. do e. register
iii. while

4. An ambiguous grammar is the one that produces mare than one parse tree (or
derivation) for at least one string in the language.
It is important for he language to be unambiguous so that there is only one
interpretation for each program in the language.

Вам также может понравиться