Now consider the nameanalysis phase of the compiler Note tha

Now consider the name-analysis phase of the compiler. Note that, in addition to the usual errors for multiply-defined names and for uses of undefined names, the name analyzer must enforce the following rules: The declaration typedef T xxx; is an error if T is not a built-in type (e.g., int, bool) or a struct type (in which case T will be of the form: struct ttt) or a new type defined by a previous typedef in the current or an enclosing scope. The declaration typedef T xxx; is an error if xxx has already been declared in the current scope (as a variable, function, parameter, or new type). A variable, function, or parameter can only be declared to be of type T if T is either a built-in type or a new type defined by a previous typedef in the current or an enclosing scope. (A variable can still be declared to be of type struct ttt as before.) Answer each of the following questions: What should be done to process a typedef: typedef T xxx;? What should be done to process the use of a name xxx in a statement? What should be done to process a declaration of a variable, function, or parameter named xxx and declared to be of type T? What information should be stored with each name in the symbol table? Illustrate your answer by showing the entries that would be in the symbol table after processing the following declarations: struct MonthDayYear {int month; int day; int year;}; typedef struct MonthDayYear date; date today; typedef int dollars; dollars salary; typedef dollars moreDollars; moreDollars md; int d; To make our harambe language more powerful, we sometimes need to learn from other existing languages. The C language allows you to define new names for existing types using typedefs. Here is some example code that uses typedefs: typedef int money; int x; money y; typedef money dollars; dollars z; x = 10; y = x;//OK because x and y are of type int z = y;//OK because y and z are of type int The first typedef defines money to be a synonym for int. Any declaration that follows this typedef can use money instead of int. The second typedef defines dollars to be a synonym for money, which makes it a synonym for int. Any declaration that follows this typedef can use dollars instead of int. Typedefs can also be used with struct types: struct Pair {int x; int y;}; typedef struct Pair Point; Point p; A typedef can occur anywhere that a variable declaration (local or global) can occur. The usual C scoping rules apply to the names in typedefs. Note that typedef int money; is considered to be a declaration of the name money and that both money x; and typedef money dollars; are considered to be uses of the name money.

Solution

A compiler is a unique application that strategies statements written in a particular programming language and turns them into machine language or \"code\" that a computer\'s processor makes use of. normally, a programmer writes language statements in a language inclusive of Pascal or C one line at a time the use of an editor. The file that is created contains what are referred to as the supply statements. The programmer then runs an appropriate language compiler, specifying the name of the document that consists of the source statements.

whilst executing (running), the compiler first parses (or analyzes) all the language statements syntactically one after the alternative and then, in one or more successive degrees or \"passes\", builds the output code, ensuring that statements that seek advice from different statements are referred to correctly within the final code. historically, the output of the compilation has been called object code or once in a while an object module . (be aware that the time period \"object\" right here is not associated with object-orientated programming.) The object code is device code that the processor can execute one preparation at a time.

The Java programming language, a language used in object-orientated programming, added the opportunity of compiling output (referred to as bytecode ) that can run on any pc machine platform for which a Java virtual device or bytecode interpreter is furnished to transform the bytecode into instructions that can be done by using the real hardware processor. the use of this digital device, the bytecode can optionally be recompiled on the execution platform by a just-in-time compiler. (See also: Java compiler)

historically in a few working systems, an extra step was required after compilation - that of resolving the relative region of commands and statistics when a couple of item module become to be run at the same time and they cross-referred to every other\'s coaching sequences or statistics. This method become every so often known as linkage editing and the output known as a load module.

A compiler works with what are occasionally known as 3GL and better-stage languages. An assembler works on packages written the use of a processor\'s assembler language.

 Now consider the name-analysis phase of the compiler. Note that, in addition to the usual errors for multiply-defined names and for uses of undefined names, th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site