P
Percival
Hello, I am reletivly newbish at Perl and would like to build a
translator between C .h files into Nasm assembly .inc files. The only
things that I will translate between them are constants, structures, and
possibly unions.
For those who don't know C, here is the problem. Constants are defined
in two ways,
#define MyConstant 500
/\ Don't worry about that one, i got that part of the program done.
enum {
CONSTANT = 0, CONSTANT2, CONSTANT3
};
Where the = is optional, whitespaces are the only delimiter, and
constants increase by one as they move to the right. Example:
enum { Red, White, Blue};
Sets Red equal to 0, White to 1, and Blue to 2
enum { Red, White = 5, Blue};
Sets red equal to 0, white to 5, and blue to 6
enum { Red = 10, White = 2, Blue};
Sets red equal to 10, white to 2, and blue to 3.
And constants should be translated to my assembler like so:
MyConstant equ 500
CONSTANT equ 0
CONSTANT2 equ 1
CONSTANT3 equ 2
The #define statement is straightforward, and I have that part of the
program complete, (as define always comes in the beginning of the line
and so forth)
But i do not have a plan on implementing the enum feature in C. What may
help is that newlines and tabs are all treated as whitespace in C, and
all whitespaces after the first are ignored, and if the character isn't
allowed in symbols whitespaces before and after it are ignored. '=',
',', '{' and '}' are the only ones that probably will appear in enum. So:
enum {
abc = 5,
def = 10,
ghi = 11
};
Is the same as:
enum{abc=5,def=10,ghi=11};
Is the same as
enum
{
abc= 5, def=10
ghi =11 }
;
Thanks for your help.
Percival
translator between C .h files into Nasm assembly .inc files. The only
things that I will translate between them are constants, structures, and
possibly unions.
For those who don't know C, here is the problem. Constants are defined
in two ways,
#define MyConstant 500
/\ Don't worry about that one, i got that part of the program done.
enum {
CONSTANT = 0, CONSTANT2, CONSTANT3
};
Where the = is optional, whitespaces are the only delimiter, and
constants increase by one as they move to the right. Example:
enum { Red, White, Blue};
Sets Red equal to 0, White to 1, and Blue to 2
enum { Red, White = 5, Blue};
Sets red equal to 0, white to 5, and blue to 6
enum { Red = 10, White = 2, Blue};
Sets red equal to 10, white to 2, and blue to 3.
And constants should be translated to my assembler like so:
MyConstant equ 500
CONSTANT equ 0
CONSTANT2 equ 1
CONSTANT3 equ 2
The #define statement is straightforward, and I have that part of the
program complete, (as define always comes in the beginning of the line
and so forth)
But i do not have a plan on implementing the enum feature in C. What may
help is that newlines and tabs are all treated as whitespace in C, and
all whitespaces after the first are ignored, and if the character isn't
allowed in symbols whitespaces before and after it are ignored. '=',
',', '{' and '}' are the only ones that probably will appear in enum. So:
enum {
abc = 5,
def = 10,
ghi = 11
};
Is the same as:
enum{abc=5,def=10,ghi=11};
Is the same as
enum
{
abc= 5, def=10
ghi =11 }
;
Thanks for your help.
Percival