#include "Vector.h"

void Vector_Initialize(Vector* this)

...{
this->count = 0;
}

void add(Vector* this, void* obj)

...{
this->obj[this->count] = obj;
this->count++;
}

int size(Vector* this)

...{
return this->count;
}

void* elementAt(Vector* this, int pos)

...{
return this->obj[pos];
}

void addVector(Vector* this, void* data)

...{
int i;

for(i = 0;i<size(data);i++)...{
add(this,elementAt(data,i));
}
}
#ifndef VECTOR_H__
#define VECTOR_H__

#define VECTOR_MAX 256


typedef struct...{
void* obj[VECTOR_MAX];
int count;
}Vector;

void Vector_Initialize(Vector* this);

void add(Vector* this, void* obj);

int size(Vector* this);

void* elementAt(Vector* this, int pos);

void addVector(Vector* this, void* data);
#endif
#include "Numeric.h"


static const CNumeric_VMT vmt = ...{CNumeric_Generate};

void CNumeric_Initialize(CNumeric* this, int val)

...{
((CExpression*)this)->vmt = (const CExpression_VMT*)&vmt;
this->value = val;
}

void CNumeric_Generate(CNumeric* this, FILE* output)

...{
fprintf(output, "%d", this->value);
}
#ifndef NUMERIC__H_
#define NUMERIC__H_
#include "Expression.h"
#include <stdio.h>

typedef struct Numeric_t CNumeric;


typedef struct...{
void (*generate)(CNumeric*, FILE*);
}CNumeric_VMT;


struct Numeric_t...{
CExpression super;
int value;
};

extern void CNumeric_Initialize(CNumeric*, int);
extern void CNumeric_Generate(CNumeric*, FILE*);

#endif
#include "PrimaryExpression.h"


static const CPrimaryExpression_VMT vmt = ...{ CPrimaryExpression_Generate };

void CPrimaryExpression_Initialize(CPrimaryExpression* this)

...{
CExpression_Initialize((CExpression*)this);
((CExpression*)this)->vmt = (const CExpression_VMT*)&vmt;
}
void CPrimaryExpression_Generate(CPrimaryExpression* this, FILE* output)

...{
}
#ifndef _PRIMARY_EXPRESSION_H
#define _PRIMARY_EXPRESSION_H

#include "Expression.h"
#include <stdio.h>

typedef struct PrimaryExpression_t CPrimaryExpression;


typedef struct...{
void (*generate)(CPrimaryExpression*, FILE*);
}CPrimaryExpression_VMT;


struct PrimaryExpression_t...{
CExpression super;
};

extern void CPrimaryExpression_Initialize(CPrimaryExpression*);
extern void CPrimaryExpression_Generate(CPrimaryExpression*, FILE*);
#endif
#include "Expression.h"


static const CExpression_VMT vmt = ...{CExpression_Generate};

void CExpression_Initialize(CExpression* this)

...{
((CExpression*)this)->vmt = (const CExpression_VMT*)&vmt;
}

void CExpression_Generate(CExpression *this, FILE *output)

...{

}
#ifndef EXPRESSION__H_
#define EXPRESSION__H_
#include <stdio.h>

typedef struct Expression_t CExpression;


typedef struct...{
void (*generate)(CExpression*, FILE*);
}CExpression_VMT;


struct Expression_t...{
const CExpression_VMT *vmt;
};

extern void CExpression_Initialize(CExpression*);

extern void CExpression_Generate(CExpression*, FILE*);

#define Expression_Generate(this, output)
(((CExpression*)(this))->vmt->generate((CExpression*)(this),output))
#endif
#include "FunctionCall.h"


static const CFunctionCall_VMT vmt = ...{ CFunctionCall_Generate };

void CFunctionCall_Initialize(CFunctionCall* this, char* name, Vector* parm)

...{
CPrimaryExpression_Initialize((CPrimaryExpression*)this);
((CExpression*)this)->vmt = (const CExpression_VMT*)&vmt;
this->name = name;
this->parm = parm;
}

void CFunctionCall_Generate(CFunctionCall* this, FILE* output)

...{
int i;
fprintf(output, "%s(", this->name);

for(i = 0; i< size(this->parm); i++)...{
Expression_Generate(elementAt(this->parm, i), output);

if(i < size(this->parm) - 1)...{
fprintf(output, ",");
}
}
fprintf(output, ")");
}
#ifndef FUNCTIONCALL__H_
#define FUNCTIONCALL__H_

#include "PrimaryExpression.h"
#include "Vector.h"
#include <stdio.h>

typedef struct FunctionCall_t CFunctionCall;


typedef struct...{
void (*generate)(CFunctionCall*,FILE*);
}CFunctionCall_VMT;


struct FunctionCall_t...{
CPrimaryExpression super;
char* name;
Vector *parm;
};

extern void CFunctionCall_Initialize(CFunctionCall*, char*, Vector*);

extern void CFunctionCall_Generate(CFunctionCall*, FILE*);
#endif
发表于 @ 2007年09月21日 15:11:00|评论(loading...)|编辑