< Making a Programming Language From Scratch
Structural declarations
Structures are groups of different types of data in continuous locations. It is necessarily the grouping of different types of data together.
Format of structural declarations
Defstruct [Name of structure]{ .
.
.
}
Format of assembly:
[Name of structure] struct starts .
.
.
[Name of structure] ends
Algorithm to process
1.If keyword defstruct then 2.While char not { get char and store in array name 3.Write to output file format as given above.
[note that choice of keyword is totally up to you.]
Structure variable declarations
All structures are useless unless they have some representatives in the physical memory. This is called a structure variable.
A structure variable is defined along with other variables with the important difference that structure variables are not defined during initializing (at least in assembly). Thus we will deal with only uninitialized structure variables.
Format as of assembly:
[structure variable name] [parent structure name] <?>
The <?> is the structure dup operator which sets value 0 or 0.0 to all sub-components
Algorithm
1.If keyword struct then 2.Scan parent structure name [Duplicate algorithm for getting simple variables] 3.Write to file in format as given above.
Sample Conversion
In HLL
defstruct boy{ int age,grade; float marks; char name[20]; }
In Assembly
boy struct starts age dword ? grade dword ? marks real8 ? name byte 19 dup (?),0 boy ends
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.