17.01.2015 Views

Course Notes on Formal Languages and Compilers

Course Notes on Formal Languages and Compilers

Course Notes on Formal Languages and Compilers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

10. PROGRAMMING LANGUAGE IMPLEMENTATION ISSUES<br />

51<br />

5<br />

10<br />

15<br />

20<br />

25<br />

30<br />

35<br />

A high level rogramming language has a hierarchic structure for statements<br />

expressi<strong>on</strong>s <strong>and</strong> definiti<strong>on</strong>s of functi<strong>on</strong>s, procedures, data <strong>and</strong> their types.<br />

Assembly language has a sequential structure (except for expressi<strong>on</strong>s) <strong>and</strong><br />

does not support a large variety of data types. Machine language is<br />

completely sequential in structure <strong>and</strong> has no c<strong>on</strong>cept at all of data type.<br />

There is therefore a large gap between a high level language <strong>and</strong> machine<br />

or <strong>and</strong> the main problem to be h<strong>and</strong>led is this large gap. It is for this reas<strong>on</strong><br />

that there are many phases in compilati<strong>on</strong> <strong>and</strong> interpretati<strong>on</strong>, where each<br />

phase h<strong>and</strong>les a part of the problem. The multiphase design makes also it<br />

easier to transfer the compiler to another machine. This is because the<br />

code generati<strong>on</strong> phase <strong>and</strong> the interpretati<strong>on</strong> phase are the <strong>on</strong>ly really<br />

machine dependent phases in the compiler.<br />

Let us now give examples of different programming language features,<br />

associated problems <strong>and</strong> some soluti<strong>on</strong>s.<br />

Code generati<strong>on</strong> or interpretati<strong>on</strong> - Associating properties with names<br />

Recall first the distincti<strong>on</strong> between identifier <strong>and</strong> name, that is names are<br />

unique but identifiers can have multiple definiti<strong>on</strong>s. Certain languages (such<br />

as Fortran IV) allow determining all the properties of a name at compile<br />

turns e.g. type of data, its size, <strong>and</strong> its absolute run time address. Other<br />

languages such a Pascal, need the absolute address to be determined at<br />

run time even though sizes are all known. At compile time, relative<br />

addresses are known e.g. relative to top of a stack.<br />

Other languages such as ADA, the size of data is not known <strong>and</strong> even this<br />

needs to be determined at run time e.g. <strong>on</strong> block entry. In languages such<br />

as LISP <strong>and</strong> PROLOG the type may <strong>on</strong>ly be known at run time. In view of<br />

these approaches to languages, different implementati<strong>on</strong>s are used. Code<br />

generati<strong>on</strong> can be used when the types of the data are known at compile<br />

time but is much harder or impossible to use when the data types are<br />

known at run time, <strong>and</strong> interpretati<strong>on</strong> is a simpler soluti<strong>on</strong> in this case.<br />

Type declarati<strong>on</strong>s <strong>and</strong> checking<br />

Here are three possibilities for programming languages.<br />

40<br />

45<br />

Str<strong>on</strong>gly typed language: Type declarati<strong>on</strong>s <strong>and</strong> compile time type<br />

checking. e.g. Pascal, ADA<br />

Weakly typed language: Type declarati<strong>on</strong>s but no type checking.<br />

e.g. assembly language, C.<br />

Utyped language: No type declarati<strong>on</strong>s but run time type checking.<br />

e.g. LISP, PROLOG

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!