Restructure repository to include all source folders

Move git root from Client/ to src/ to track all source code:
- Client: Game client source (moved to Client/Client/)
- Server: Game server source
- GameTools: Development tools
- CryptoSource: Encryption utilities
- database: Database scripts
- Script: Game scripts
- rylCoder_16.02.2008_src: Legacy coder tools
- GMFont, Game: Additional resources

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-29 20:17:20 +09:00
parent 5d3cd64a25
commit dd97ddec92
11602 changed files with 1446576 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
#ifndef _BaseDef_H_
#define _BaseDef_H_
#define MACHINECODEFILEEXT ".mcf" //Machine Code File
#define INTCODEFILEEXT ".imc" //InterMediate Code
#define SCRIPTFILEEXT ".gsf" //Gama Script File
///////////////////////////////////////////////////////////////////////////////////
//
typedef void * ANY_FUNCTION;
enum eDataType
{
T_VOID = 0,
T_BOOL,
T_INT,
T_FLOAT,
T_STRING = 4
};
typedef int BOOL;
#define TRUE 1
#define FALSE 0
///////////////////////////////////////////////////////////////////////////////////
//
struct ScriptFunc
{
void * pFunc;
long Type;
ScriptFunc( void *, long );
};
typedef ScriptFunc SE_FUNC;
///////////////////////////////////////////////////////////////////////////////////
//
union AnyData
{
int intValue;
float floatValue;
const char* stringValue;
AnyData( int n )
: intValue( n )
{}
AnyData( float f )
: floatValue( f )
{}
AnyData( const char * pszStr )
: stringValue( pszStr )
{}
AnyData( void * p )
: stringValue( (const char *)p )
{
}
AnyData & operator=( int n )
{
intValue = n;
return *this;
}
};
///////////////////////////////////////////////////////////////////////////////////
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
#ifndef _IMCodeGen_H_
#define _IMCodeGen_H_
#include "STL.h"
class CSyntaxTree;
class IOPCode;
typedef list<IOPCode*> IMCODES;
typedef map<int, IMCODES*> FUNCTIONS;
void GenerateCode( CSyntaxTree &, IMCODES &, FUNCTIONS & );
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,641 @@
#ifndef _IMCodeUnits_H_
#define _IMCodeUnits_H_
#include "BaseDef.h"
#include "Message.h"
#include "STL.h"
class CSymbolTable;
class CRelocTable;
typedef map<int, long> FUNCTABLE;
///////////////////////////////////////////////////////////////////////////////////
//
void SetSymbolTable( CSymbolTable * );
void SetFuncTable( FUNCTABLE * );
void SetRelocTable( CRelocTable * );
///////////////////////////////////////////////////////////////////////////////////
//
typedef unsigned char byte;
enum eRegister
{
EAX = 0,
ECX,
EDX,
EBX,
ESP,
EBP,
ESI,
EDI = 7,
NONE = 8
};
enum eCondition
{
G = 0, //Greater
GE, //Greater or Equal
L, //Less
LE, //Less or Equal
E, //Equal
NE = 5 //Not Equal
};
typedef struct _VAR_* VAR;
typedef struct _CONST_* CONST;
typedef struct _FUNC_* FUNC;
///////////////////////////////////////////////////////////////////////////////////
//
class IOPCode
{
public:
long m_lAddress;
public:
virtual ~IOPCode() {} //ToMachineCode ȣ<><C8A3> <20><><EFBFBD><EFBFBD> Addressing<6E><67> <20>ݵ<EFBFBD><DDB5><EFBFBD> <20>Ǿ<EFBFBD> <20>־<EFBFBD><D6BE><EFBFBD> <20>Ѵ<EFBFBD>.
virtual int ToMachineCode( byte * ) = 0; //<2F>Ѱܹ<D1B0><DCB9><EFBFBD> <20>ּҿ<D6BC> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ带 <20><><EFBFBD><EFBFBD> index<65><78> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD><C5B2>.
virtual long Addressing( long ) = 0; //<2F><><EFBFBD><EFBFBD> <20>ּҸ<D6BC> <20>ް<EFBFBD>, <20><><EFBFBD><EFBFBD> instruction<6F><6E> <20>ּҸ<D6BC> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
virtual void Show( MESSAGE_FUNCTION2 ) = 0;
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_call : public IOPCode
{
FUNC m_funcID;
int m_iLine;
public:
COP_call( FUNC, int line );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_mov : public IOPCode
{
byte m_Type;
FUNC m_funcID;
union
{
VAR m_leftVarID;
eRegister m_leftReg;
};
union
{
int m_midArrayIndex;
eRegister m_midIndexReg;
};
union
{
eRegister m_rightReg;
CONST m_rightConstID;
VAR m_rightVarID;
int m_rightValue;
float m_rightValuef;
};
public:
COP_mov( FUNC, VAR, eRegister reg );
COP_mov( eRegister reg, FUNC, VAR );
COP_mov( eRegister reg, CONST constID );
COP_mov( FUNC, VAR, float valuef );
COP_mov( eRegister lreg, eRegister rreg );
COP_mov( eRegister lreg, int value );
COP_mov( FUNC, VAR, int arrayIndex, eRegister rreg );
COP_mov( eRegister lreg, FUNC, VAR, eRegister indexReg );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_nop : public IOPCode
{
public:
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_add : public IOPCode
{
byte m_Type;
eRegister m_leftReg;
union
{
int m_iValue;
eRegister m_rightReg;
};
public:
COP_add( eRegister reg, int value );
COP_add( eRegister lreg, eRegister rreg );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_sub : public IOPCode
{
byte m_Type;
eRegister m_leftReg;
union
{
eRegister m_rightReg;
int m_iValue;
};
public:
COP_sub( eRegister reg, int value );
COP_sub( eRegister lreg, eRegister rreg );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_imul : public IOPCode
{
eRegister m_leftReg;
eRegister m_rightReg;
public:
COP_imul( eRegister lreg, eRegister rreg );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_idiv : public IOPCode
{
eRegister m_rightReg;
public:
COP_idiv( eRegister rreg );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_push : public IOPCode
{
eRegister m_Reg;
public:
COP_push( eRegister reg );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_pop : public IOPCode
{
eRegister m_Reg;
public:
COP_pop( eRegister reg );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_jmp : public IOPCode
{
public:
IOPCode * m_pJumpTarget;
public:
COP_jmp();
COP_jmp( IOPCode * pJmpTarget );
virtual ~COP_jmp();
virtual int ToMachineCode( byte * );
virtual long Addressing( long addr );
virtual void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_jcc : public COP_jmp
{
eCondition m_Condition;
public:
COP_jcc( eCondition condition );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_jmpmark : public IOPCode
{
public:
IOPCode * m_pJumpSrc;
public:
COP_jmpmark();
COP_jmpmark( COP_jmp * pOPjmp );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_cmp : public IOPCode
{
byte m_Type;
FUNC m_funcID;
union
{
VAR m_leftVarID;
eRegister m_leftReg;
};
union
{
byte m_rightValue;
CONST m_rightConstID;
eRegister m_rightReg;
};
public:
COP_cmp( FUNC, VAR lvarID, CONST rconstID );
COP_cmp( eRegister lreg, byte value );
COP_cmp( eRegister lreg, eRegister rreg );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_ret : public IOPCode
{
public:
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
class COP_xor : public IOPCode
{
eRegister m_leftReg;
eRegister m_rightReg;
public:
COP_xor( eRegister lreg, eRegister rreg );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_setcc : public IOPCode
{
eCondition m_Condition;
eRegister m_Reg;
public:
COP_setcc( eCondition condition, eRegister lreg );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_int3 : public IOPCode
{
public:
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_fld : public IOPCode
{
FUNC m_funcID;
VAR m_varID;
public:
COP_fld( FUNC, VAR );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_fadd : public IOPCode
{
FUNC m_funcID;
VAR m_varID;
public:
COP_fadd( FUNC, VAR );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_fsub : public IOPCode
{
FUNC m_funcID;
VAR m_varID;
public:
COP_fsub( FUNC, VAR );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_fmul : public IOPCode
{
FUNC m_funcID;
VAR m_varID;
public:
COP_fmul( FUNC, VAR );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_fdiv : public IOPCode
{
FUNC m_funcID;
VAR m_varID;
public:
COP_fdiv( FUNC, VAR );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_fstp : public IOPCode
{
FUNC m_funcID;
VAR m_varID;
bool m_bDouble;
public:
COP_fstp( FUNC, VAR, bool = false );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_fcomp : public IOPCode
{
FUNC m_funcID;
VAR m_varID;
public:
COP_fcomp( FUNC, VAR );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_fnstsw_ax : public IOPCode
{
public:
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_test_ah : public IOPCode
{
byte m_Value8;
public:
COP_test_ah( byte );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_itoa : public IOPCode
{
eRegister m_leftReg;
FUNC m_funcID;
VAR m_StringBuffer;
public:
COP_itoa( eRegister, VAR );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_ftoa : public IOPCode
{
eRegister m_freeReg;
VAR m_DoubleVar;
VAR m_StringBuffer;
public:
COP_ftoa( eRegister, VAR, VAR );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
//<2F>Ҵ<EFBFBD><D2B4><EFBFBD> <20>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD> <20>ּҰ<D6BC> EAX<41><58> <20><><EFBFBD><EFBFBD><EEB0A3>.
class COP_malloc : public IOPCode
{
eRegister m_Reg;
public:
COP_malloc( eRegister );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_free : public IOPCode
{
FUNC m_funcID;
VAR m_varID;
public:
COP_free( FUNC, VAR );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
class COP_strcpy : public IOPCode
{
int m_type;
eRegister m_leftReg;
FUNC m_funcID;
union
{
eRegister m_rightReg;
VAR m_varID;
};
public:
COP_strcpy( eRegister, eRegister );
COP_strcpy( eRegister, FUNC, VAR );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
//ptr[leftReg]<5D><> ptr[rightReg]<5D><> <20><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> eax<61><78> <20>ִ´<D6B4>.
class COP_strcmp : public IOPCode
{
eRegister m_leftReg;
eRegister m_rightReg;
public:
COP_strcmp( eRegister lreg, eRegister rreg );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
//
//ptr [rightReg] <20><> <20>ִ<EFBFBD> <20><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD> <20><><EFBFBD≯<EFBFBD> <20><><EFBFBD><EFBFBD> leftReg<65><67> <20>ִ´<D6B4>.
class COP_strlen : public IOPCode
{
int m_type;
FUNC m_funcID;
union
{
eRegister m_Reg;
VAR m_varID;
};
public:
COP_strlen( eRegister reg );
COP_strlen( FUNC, VAR );
int ToMachineCode( byte * );
long Addressing( long addr );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
#endif

View File

@@ -0,0 +1,160 @@
#include "IntermediateCode.h"
#include "IMCodeGen.h"
#include "IMCodeUnits.h"
#include "SymbolTable.h"
#include <list>
#include <map>
#include "RelocTable.h"
#include <stdlib.h>
#include <string>
///////////////////////////////////////////////////////////////////////////////////
//
CIntermediateCode::CIntermediateCode()
: m_pCodes( new IMCODES )
, m_pFunctions( new FUNCTIONS )
, m_pFuncTable( new FUNCTABLE )
{
}
CIntermediateCode::~CIntermediateCode()
{
Destroy();
delete m_pCodes;
delete m_pFunctions;
delete m_pFuncTable;
}
void CIntermediateCode::Create( CSyntaxTree & rSyntaxTree )
{
GenerateCode( rSyntaxTree, *m_pCodes, *m_pFunctions );
}
void CIntermediateCode::DestroyIMCodes( IMCODES * pIMCodes )
{
for( IMCODES::iterator i = pIMCodes->begin(); i != pIMCodes->end(); i++ )
{
delete *i;
}
pIMCodes->clear();
}
void CIntermediateCode::Destroy()
{
for( FUNCTIONS::iterator i = m_pFunctions->begin(); i != m_pFunctions->end(); i++ )
{
DestroyIMCodes( i->second );
delete i->second;
}
m_pFunctions->clear();
DestroyIMCodes( m_pCodes );
}
void CIntermediateCode::Show( MESSAGE_FUNCTION2 Print, CSymbolTable * pSymbolTable )
{
const char * DataTypeString[] = { "void", "bool", "int", "float", "string" };
SetSymbolTable( pSymbolTable );
Print( "<<< void Main() >>>\n" );
for( IMCODES::iterator i = m_pCodes->begin(); i != m_pCodes->end(); i++ )
{
IOPCode * pCode = (*i);
Print( "%X :\t", pCode->m_lAddress );
pCode->Show( Print );
}
for( FUNCTIONS::iterator j = m_pFunctions->begin(); j != m_pFunctions->end(); j++ )
{
SFuncType type = pSymbolTable->GetTypeOfFunc( j->first );
Print( "<<< %s %s(", DataTypeString[type.GetReturnType()], pSymbolTable->GetNameOfFunc( j->first ) );
if( type.GetArgType( 0 ) != T_VOID )
{
Print( " " );
Print( DataTypeString[ type.GetArgType( 0 ) ] );
for( int ith = 1; ith < 8; ith++ )
{
eDataType dataType = type.GetArgType( ith );
if( dataType == T_VOID )
break;
Print( ", %s", DataTypeString[dataType] );
}
Print( " " );
}
Print( ") >>>\n" );
IMCODES * pFuncCode = j->second;
for( i = pFuncCode->begin(); i != pFuncCode->end(); i++ )
{
Print( "%X :\t", (*i)->m_lAddress );
(*i)->Show( Print );
}
}
}
long CIntermediateCode::Addressing( long addr )
{
for( IMCODES::iterator i = m_pCodes->begin(); i != m_pCodes->end(); i++ )
{
addr = (*i)->Addressing( addr );
}
for( FUNCTIONS::iterator j = m_pFunctions->begin(); j != m_pFunctions->end(); j++ )
{
IMCODES * pFuncCode = j->second;
for( i = pFuncCode->begin(); i != pFuncCode->end(); i++ )
{
addr = (*i)->Addressing( addr );
}
}
return addr;
}
int CIntermediateCode::ToMachineCode( void * pBuf, CRelocTable * pRelocTable )
{
Addressing( 0 );
for( FUNCTIONS::iterator k = m_pFunctions->begin(); k != m_pFunctions->end(); k++ )
{
int funcID = k->first;
int offset = k->second->front()->m_lAddress;
m_pFuncTable->insert( FUNCTABLE::value_type( funcID, offset ) );
}
SetFuncTable( m_pFuncTable );
SetRelocTable( pRelocTable );
byte * pBuffer = (byte*)pBuf;
int TotalSize = 0;
IMCODES::iterator i = m_pCodes->begin();
for( ; i != m_pCodes->end(); i++ )
{
int size = (*i)->ToMachineCode( pBuffer );
pBuffer += size;
TotalSize += size;
}
for( FUNCTIONS::iterator j = m_pFunctions->begin(); j != m_pFunctions->end(); j++ )
{
IMCODES * pFuncCode = j->second;
for( i = pFuncCode->begin(); i != pFuncCode->end(); i++ )
{
int size = (*i)->ToMachineCode( pBuffer );
pBuffer += size;
TotalSize += size;
}
}
return TotalSize;
}
///////////////////////////////////////////////////////////////////////////////////
//

View File

@@ -0,0 +1,51 @@
#ifndef _IntermediateCode_H_
#define _IntermediateCode_H_
#include "STL.h"
#include "BaseDef.h"
#include "Message.h"
///////////////////////////////////////////////////////////////////////////////////
//
class IOPCode;
class CSyntaxTree;
class CSymbolTable;
class CRelocTable;
class CIntermediateCode
{
public:
typedef list<IOPCode*> IMCODES;
typedef map<int, IMCODES*> FUNCTIONS;
typedef map<int, long> FUNCTABLE;
protected:
IMCODES * m_pCodes;
FUNCTIONS * m_pFunctions;
FUNCTABLE * m_pFuncTable;
protected:
void DestroyIMCodes( IMCODES * );
public:
CIntermediateCode();
~CIntermediateCode();
void Create( CSyntaxTree & );
void Destroy();
void Show( MESSAGE_FUNCTION2, CSymbolTable * pSymbolTable );
long Addressing( long addr ); //past end<6E><64> addr<64><72> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
int ToMachineCode( void *, CRelocTable * );
FUNCTABLE & GetFuncTable() { return *m_pFuncTable; }
};
///////////////////////////////////////////////////////////////////////////////////
//
#endif

View File

@@ -0,0 +1,110 @@
#include "Message.h"
#include <iostream>
#include <stdarg.h>
using namespace std;
void DefaultMessageFunction( const char * ErrMsg )
{
cout << ErrMsg << endl;
}
MESSAGE_FUNCTION g_pfuncCompilerMessage = DefaultMessageFunction;
void CompilerMessage( const char * szStr )
{
(*g_pfuncCompilerMessage)( szStr );
}
void CompilerMessage2( const char * szStr, ... )
{
va_list args;
va_start( args, szStr );
char szBuffer[1024];
vsprintf( szBuffer, szStr, args );
CompilerMessage( szBuffer );
}
void SetCompilerMessageFunction( MESSAGE_FUNCTION func )
{
g_pfuncCompilerMessage = func;
}
void ErrorMessage( int line, const char * Msg )
{
CompilerMessage2( "Error (line %d) : %s", line, Msg );
exit(0);
}
void ErrorMessage( const char * Msg )
{
CompilerMessage2( "Error : %s", Msg );
exit(0);
}
void ErrorMessage2( int line, const char * Msg, ... )
{
va_list args;
va_start( args, Msg );
char szBuffer[1024];
vsprintf( szBuffer, Msg, args );
CompilerMessage2( "Error (line %d) : %s", line, szBuffer );
exit(0);
}
void ErrorMessage2( const char * Msg, ... )
{
va_list args;
va_start( args, Msg );
char szBuffer[1024];
vsprintf( szBuffer, Msg, args );
CompilerMessage2( "Error : %s", szBuffer );
exit(0);
}
void WarningMessage( int line, const char * Msg )
{
CompilerMessage2( "Warning (line %d) : %s", line, Msg );
}
void WarningMessage( const char * Msg )
{
CompilerMessage2( "Warning : %s", Msg );
}
void WarningMessage2( const char * Msg, ... )
{
va_list args;
va_start( args, Msg );
char szBuffer[1024];
vsprintf( szBuffer, Msg, args );
CompilerMessage2( "Warning : %s", szBuffer );
}
void WarningMessage2( int line, const char * Msg, ... )
{
va_list args;
va_start( args, Msg );
char szBuffer[1024];
vsprintf( szBuffer, Msg, args );
CompilerMessage2( "Warning (line %d) : %s", line, szBuffer );
}
void ScriptSystemError( const char * Msg )
{
CompilerMessage2( "Script System Error : %s", Msg );
}

View File

@@ -0,0 +1,27 @@
#ifndef _Message_H_
#define _Message_H_
///////////////////////////////////////////////////////////////////////////////////
//
typedef void (*MESSAGE_FUNCTION)( const char * ErrMsg );
typedef void (*MESSAGE_FUNCTION2)( const char *, ... );
void CompilerMessage( const char * );
void CompilerMessage2( const char *, ... );
void SetCompilerMessageFunction( MESSAGE_FUNCTION );
void ErrorMessage( int line, const char * );
void ErrorMessage( const char * );
void ErrorMessage2( int line, const char *, ... );
void ErrorMessage2( const char *, ... );
void WarningMessage( int line, const char * );
void WarningMessage( const char * );
void WarningMessage2( int line, const char *, ... );
void WarningMessage2( const char *, ... );
void ScriptSystemError( const char * );
///////////////////////////////////////////////////////////////////////////////////
//
#endif

View File

@@ -0,0 +1,21 @@
flex -olex.cpp string.l
@echo off
rem *** Make sure Bison can find these files
rem move bison.simple . >nul
rem move bison.hairy . >nul
rem *** Run Bison to generate the parser
bison --defines --verbose -o parse.cpp string.y
rem *** Put the files back
rem move bison.simple .. >nul
rem move bison.hairy .. >nul
rem *** Rename parse.cpp.h to lexsymb.h
if exist lexsymb.h del lexsymb.h
ren parse.cpp.h lexsymb.h
pause
:End

View File

@@ -0,0 +1,196 @@
#include "RelocTable.h"
#include <vector>
#include <fstream>
#include <stdio.h>
#include <windows.h>
#include "VirtualMachine.h"
CRelocTable::CRelocTable()
: m_pGlobalVarTable( new RELOCTABLE )
, m_pStringTable( new RELOCTABLE )
, m_pFuncRelocTable( new FUNCRELOCTABLE )
{
}
CRelocTable::~CRelocTable()
{
delete m_pGlobalVarTable;
delete m_pStringTable;
delete m_pFuncRelocTable;
}
void CRelocTable::Create( ifstream & file )
{
Destroy();
int GlobalVarSize;
int StringBufferSize;
int FuncBufferSize;
file.read( (char*)&GlobalVarSize, sizeof(int) );
file.read( (char*)&StringBufferSize, sizeof(int) );
file.read( (char*)&FuncBufferSize, sizeof(int) );
int Temp;
for( int i = 0; i < GlobalVarSize; i++ )
{
file.read( (char*)&Temp, sizeof(int) );
m_pGlobalVarTable->push_back( Temp );
}
for( i = 0; i < StringBufferSize; i++ )
{
file.read( (char*)&Temp, sizeof(int) );
m_pStringTable->push_back( Temp );
}
for( i = 0; i < FuncBufferSize; i++ )
{
eStdFunc Func;
file.read( (char*)&Func, sizeof(Func) );
file.read( (char*)&Temp, sizeof(int) );
m_pFuncRelocTable->push_back( FUNCRELOC( Func, Temp ) );
}
}
#define READ_INT( p, var ) { var = *((int*)p); p += sizeof(int); }
#define READ_STDFUNCTYPE( p, var ) { var = *((eStdFunc*)p); p+= sizeof(eStdFunc); }
const void * CRelocTable::Create( const void * pDataBuf, unsigned dataSize )
{
Destroy();
const char * pBuf = (const char *)pDataBuf;
int GlobalVarSize, StringBufferSize, FuncBufferSize, temp;
READ_INT( pBuf, GlobalVarSize );
READ_INT( pBuf, StringBufferSize );
READ_INT( pBuf, FuncBufferSize );
for( int i = 0; i < GlobalVarSize; i++ )
{
READ_INT( pBuf, temp );
m_pGlobalVarTable->push_back( temp );
}
for( i = 0; i < StringBufferSize; i++ )
{
READ_INT( pBuf, temp );
m_pStringTable->push_back( temp );
}
for( i = 0; i < FuncBufferSize; i++ )
{
eStdFunc Func;
READ_STDFUNCTYPE( pBuf, Func );
READ_INT( pBuf, temp );
m_pFuncRelocTable->push_back( FUNCRELOC( Func, temp ) );
}
return pBuf;
}
void CRelocTable::Destroy()
{
m_pGlobalVarTable->clear();
m_pStringTable->clear();
}
void CRelocTable::Save( ofstream & file )
{
int GlobalVarSize = m_pGlobalVarTable->size();
int StringBufferSize = m_pStringTable->size();
int FuncBufferSize = m_pFuncRelocTable->size();
file.write( (const char*)&GlobalVarSize, sizeof(int) );
file.write( (const char*)&StringBufferSize, sizeof(int) );
file.write( (const char*)&FuncBufferSize, sizeof(int) );
for( int i = 0; i < GlobalVarSize; i++ )
{
int offset = m_pGlobalVarTable->at( i );
file.write( (const char*)&offset, sizeof(int) );
}
for( i = 0; i < StringBufferSize; i++ )
{
int offset = m_pStringTable->at( i );
file.write( (const char*)&offset, sizeof(int) );
}
for( i = 0; i < FuncBufferSize; i++ )
{
FUNCRELOC relocFunc = m_pFuncRelocTable->at( i );
file.write( (const char*)&relocFunc.first, sizeof(relocFunc.first) );
file.write( (const char*)&relocFunc.second, sizeof(relocFunc.second) );
}
}
void CRelocTable::AddGlobalVar( int offset )
{
m_pGlobalVarTable->push_back( offset );
}
void CRelocTable::AddConstString( int offset )
{
m_pStringTable->push_back( offset );
}
void CRelocTable::AddFuncBind( eStdFunc func, int offset )
{
m_pFuncRelocTable->push_back( FUNCRELOC( func, offset ) );
}
void CRelocTable::Relocate( void * pGlobalVarBuffer, void * pStringBuffer, void * pCodeBuffer )
{
void * ArrFuncPtr[] = { itoa, gcvt, malloc, free, strcpy, strcmp,
strlen, RegisterAllocatedMemory, UnregisterAllocatedMemory };
char * pCode = (char*)pCodeBuffer;
for( RELOCTABLE::iterator i = m_pGlobalVarTable->begin(); i != m_pGlobalVarTable->end(); i++ )
{
long * pValue = (long*)(pCode + *i);
*pValue += long(pGlobalVarBuffer);
}
for( RELOCTABLE::iterator j = m_pStringTable->begin(); j != m_pStringTable->end(); j++ )
{
long * pValue = (long*)(pCode + *j);
*pValue += long(pStringBuffer);
}
for( FUNCRELOCTABLE::iterator k = m_pFuncRelocTable->begin(); k != m_pFuncRelocTable->end(); k++ )
{
long * pValue = (long*)(pCode + k->second);
*pValue = (long) ArrFuncPtr[k->first];
}
}
void CRelocTable::Unlocate( void * pGlobalVarBuffer, void * pStringBuffer, void * pCodeBuffer )
{
char * pCode = (char*)pCodeBuffer;
for( RELOCTABLE::iterator i = m_pGlobalVarTable->begin(); i != m_pGlobalVarTable->end(); i++ )
{
long * pValue = (long*)(pCode + *i);
*pValue -= long(pGlobalVarBuffer);
}
for( i = m_pStringTable->begin(); i != m_pStringTable->end(); i++ )
{
long * pValue = (long*)(pCode + *i);
*pValue -= long(pStringBuffer);
}
for( FUNCRELOCTABLE::iterator k = m_pFuncRelocTable->begin(); k != m_pFuncRelocTable->end(); k++ )
{
long * pValue = (long*)(pCode + k->second);
*pValue = 0;
}
}

View File

@@ -0,0 +1,51 @@
#ifndef _RelocTable_H_
#define _RelocTable_H_
#include "STL.h"
///////////////////////////////////////////////////////////////////////////////////
//
enum eStdFunc
{
FUNC_ITOA = 0,
FUNC_GCVT,
FUNC_MALLOC,
FUNC_FREE,
FUNC_STRCPY,
FUNC_STRCMP,
FUNC_STRLEN,
FUNC_REGISTERALLOCATEDMEMORY,
FUNC_UNREGISTERALLOCATEDMEMORY = 8
};
class CRelocTable
{
typedef vector<int> RELOCTABLE;
typedef pair<eStdFunc, int> FUNCRELOC;
typedef vector<FUNCRELOC> FUNCRELOCTABLE;
RELOCTABLE * m_pGlobalVarTable;
RELOCTABLE * m_pStringTable;
FUNCRELOCTABLE * m_pFuncRelocTable;
public:
CRelocTable();
~CRelocTable();
void Create( ifstream & );
const void * Create( const void * pDataBuf, unsigned dataSize );
void Destroy();
void Save( ofstream & );
void AddGlobalVar( int offset );
void AddConstString( int offset );
void AddFuncBind( eStdFunc, int offset );
void Relocate( void * pGlobalVarBuffer, void * pStringBuffer, void * pCodeBuffer );
void Unlocate( void * pGlobalVarBuffer, void * pStringBuffer, void * pCodeBuffer );
};
///////////////////////////////////////////////////////////////////////////////////
#endif

View File

@@ -0,0 +1,53 @@
#ifndef _STL_H_
#define _STL_H_
#pragma warning(disable:4786) //STL<54><4C> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Warning<6E><67> <20><><EFBFBD>ֱ<EFBFBD> <20><><EFBFBD><EFBFBD>..
//STL <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
namespace std
{
template<class T>
class allocator;
template<class T>
struct less;
template<class Key, class Pred = less<Key>, class A = allocator<Key> >
class multiset;
template<class Key, class Pred = less<Key>, class A = allocator<Key> >
class set;
template<class Key, class T, class Pred = less<Key>, class A = allocator<T> >
class map;
template<class Key, class T, class Pred = less<Key>, class A = allocator<T> >
class multimap;
template<class T, class A = allocator<T> >
class deque;
template<class T, class Cont = deque<T> >
class queue;
template<class T, class Cont = deque<T> >
class stack;
template<class T, class A = allocator<T> >
class vector;
template<class T, class A = allocator<T> >
class list;
template<class T, class U>
struct pair;
template<class E>
struct char_traits;
template<class E, class T = char_traits<E>, class A = allocator<T> >
class basic_string;
typedef basic_string<char, char_traits<char>, allocator<char> > string;
template <class E, class T = char_traits<E> >
class basic_ifstream;
template <class E, class T = char_traits<E> >
class basic_ofstream;
typedef basic_ifstream<char, char_traits<char> > ifstream;
typedef basic_ofstream<char, char_traits<char> > ofstream;
}
using namespace std;
#endif

View File

@@ -0,0 +1,123 @@
// ScriptEngine.cpp : Defines the entry point for the DLL application.
//
#include "ScriptEngine.h"
#include "SyntaxTree.h"
#include "IntermediateCode.h"
#include "VirtualMachine.h"
#include "Message.h"
#include <stdarg.h>
#include <stdio.h>
#include <windows.h>
/*
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}*/
SCRIPT _SE_Create( const char * codeFile )
{
FILE * fp = fopen( codeFile, "r" );
if( fp == NULL )
{
ErrorMessage2( "Cannot open file : %s", codeFile );
return NULL;
}
CVirtualMachine * pVM = new CVirtualMachine;
char szFilename[128];
strcpy( szFilename, codeFile );
strlwr( szFilename );
if( strstr( szFilename, MACHINECODEFILEEXT ) != 0 )
{
pVM->Create( codeFile );
}
else if( strstr( szFilename, SCRIPTFILEEXT ) != 0 )
{
CSyntaxTree SyntaxTree;
CIntermediateCode IMCode;
SyntaxTree.Create( codeFile );
IMCode.Create( SyntaxTree );
pVM->Create( IMCode, *SyntaxTree.GetSymbolTable() );
}
else
{
return NULL;
}
return pVM;
}
void _SE_Destroy( SCRIPT Script )
{
delete Script;
}
bool _SE_Save( SCRIPT Script, const char * szFilename )
{
return Script->Save( szFilename );
}
void _SE_Execute( SCRIPT Script )
{
Script->Execute();
}
void _SE_RegisterFunction( SCRIPT Script, ANY_FUNCTION FuncPtr, eDataType RetType, const char * szFuncName, ... )
{
va_list args;
va_start( args, szFuncName );
Script->RegisterFunction( FuncPtr, RetType, szFuncName, args );
}
SE_FUNC _SE_GetScriptFunction( SCRIPT Script, eDataType RetType, const char * szFuncName, ... )
{
va_list args;
va_start( args, szFuncName );
return Script->GetScriptFunction( RetType, szFuncName, args );
}
void _SE_SetMessageFunction( MESSAGE_FUNCTION func )
{
SetCompilerMessageFunction( func );
}
AnyData _SE_CallScriptFunction( SCRIPT pScript, SE_FUNC Func )
{
return pScript->CallScriptFunction( Func );
}
AnyData _SE_CallScriptFunction( SCRIPT pScript, SE_FUNC Func, AnyData arg1 )
{
return pScript->CallScriptFunction( Func, arg1 );
}
AnyData _SE_CallScriptFunction( SCRIPT pScript, SE_FUNC Func, AnyData arg1, AnyData arg2 )
{
return pScript->CallScriptFunction( Func, arg1, arg2 );
}
AnyData _SE_CallScriptFunction( SCRIPT pScript, SE_FUNC Func, AnyData arg1, AnyData arg2, AnyData arg3 )
{
return pScript->CallScriptFunction( Func, arg1, arg2, arg3 );
}
AnyData _SE_CallScriptFunction( SCRIPT pScript, SE_FUNC Func, AnyData arg1, AnyData arg2, AnyData arg3, AnyData arg4 )
{
return pScript->CallScriptFunction( Func, arg1, arg2, arg3, arg4 );
}
AnyData _SE_CallScriptFunction( SCRIPT pScript, SE_FUNC Func, AnyData args[], int nArgs )
{
return pScript->CallScriptFunction( Func, args, nArgs );
}

View File

@@ -0,0 +1,201 @@
# Microsoft Developer Studio Project File - Name="ScriptEngine" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=ScriptEngine - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "ScriptEngine.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "ScriptEngine.mak" CFG="ScriptEngine - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "ScriptEngine - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "ScriptEngine - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""$/ScriptEngine", DOCAAAAA"
# PROP Scc_LocalPath "..\..\mp-project\scriptengine"
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "ScriptEngine - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /FAcs /YX /FD /c
# ADD BASE RSC /l 0x412 /d "NDEBUG"
# ADD RSC /l 0x412 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "ScriptEngine - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x412 /d "_DEBUG"
# ADD RSC /l 0x412 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "ScriptEngine - Win32 Release"
# Name "ScriptEngine - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\IMCodeGen.cpp
# End Source File
# Begin Source File
SOURCE=.\IMCodeUnits.cpp
# End Source File
# Begin Source File
SOURCE=.\IntermediateCode.cpp
# End Source File
# Begin Source File
SOURCE=.\lex.cpp
# End Source File
# Begin Source File
SOURCE=.\Message.cpp
# End Source File
# Begin Source File
SOURCE=.\parse.cpp
# End Source File
# Begin Source File
SOURCE=.\RelocTable.cpp
# End Source File
# Begin Source File
SOURCE=.\ScriptEngine.cpp
# End Source File
# Begin Source File
SOURCE=.\SymbolTable.cpp
# End Source File
# Begin Source File
SOURCE=.\SyntaxTree.cpp
# End Source File
# Begin Source File
SOURCE=.\VirtualMachine.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\BaseDef.h
# End Source File
# Begin Source File
SOURCE=.\IMCodeGen.h
# End Source File
# Begin Source File
SOURCE=.\IMCodeUnits.h
# End Source File
# Begin Source File
SOURCE=.\IntermediateCode.h
# End Source File
# Begin Source File
SOURCE=.\lex.h
# End Source File
# Begin Source File
SOURCE=.\lexsymb.h
# End Source File
# Begin Source File
SOURCE=.\Message.h
# End Source File
# Begin Source File
SOURCE=.\RelocTable.h
# End Source File
# Begin Source File
SOURCE=.\ScriptEngine.h
# End Source File
# Begin Source File
SOURCE=.\STL.h
# End Source File
# Begin Source File
SOURCE=.\SymbolTable.h
# End Source File
# Begin Source File
SOURCE=.\SyntaxTree.h
# End Source File
# Begin Source File
SOURCE=.\unistd.h
# End Source File
# Begin Source File
SOURCE=.\VirtualMachine.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\string.l
# End Source File
# Begin Source File
SOURCE=.\string.y
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,36 @@
#ifndef _ScriptEngine_H_
#define _ScriptEngine_H_
#include "BaseDef.h"
#define DllExport // __declspec( dllexport )
class CVirtualMachine;
typedef CVirtualMachine * SCRIPT;
typedef void (*MESSAGE_FUNCTION)( const char * ErrMsg );
typedef void (*MESSAGE_FUNCTION2)( const char *, ... );
typedef char * va_list;
////////////////////////////////////////////////////////////////////////////////
//
DllExport SCRIPT _SE_Create( const char * codeFile );
DllExport void _SE_Destroy( SCRIPT );
DllExport bool _SE_Save( SCRIPT, const char * );
DllExport void _SE_Execute( SCRIPT );
DllExport void _SE_RegisterFunction( SCRIPT, ANY_FUNCTION, eDataType, const char * FuncName, ... );
DllExport SE_FUNC _SE_GetScriptFunction( SCRIPT, eDataType, const char * FuncName, ... );
DllExport void _SE_SetMessageFunction( MESSAGE_FUNCTION );
DllExport AnyData _SE_CallScriptFunction( SCRIPT, SE_FUNC );
DllExport AnyData _SE_CallScriptFunction( SCRIPT, SE_FUNC, AnyData );
DllExport AnyData _SE_CallScriptFunction( SCRIPT, SE_FUNC, AnyData, AnyData );
DllExport AnyData _SE_CallScriptFunction( SCRIPT, SE_FUNC, AnyData, AnyData, AnyData );
DllExport AnyData _SE_CallScriptFunction( SCRIPT, SE_FUNC, AnyData, AnyData, AnyData, AnyData );
DllExport AnyData _SE_CallScriptFunction( SCRIPT, SE_FUNC, AnyData args[], int nArgs );
////////////////////////////////////////////////////////////////////////////////
#endif

View File

@@ -0,0 +1,69 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: ScriptEngine - Win32 Debug--------------------
</h3>
<h3>Command Lines</h3>
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP22.tmp" with contents
[
/nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
"C:\ryl\ScriptEngine\IMCodeGen.cpp"
"C:\ryl\ScriptEngine\IMCodeUnits.cpp"
"C:\ryl\ScriptEngine\IntermediateCode.cpp"
"C:\ryl\ScriptEngine\lex.cpp"
"C:\ryl\ScriptEngine\Message.cpp"
"C:\ryl\ScriptEngine\parse.cpp"
"C:\ryl\ScriptEngine\RelocTable.cpp"
"C:\ryl\ScriptEngine\ScriptEngine.cpp"
"C:\ryl\ScriptEngine\SymbolTable.cpp"
"C:\ryl\ScriptEngine\SyntaxTree.cpp"
"C:\ryl\ScriptEngine\VirtualMachine.cpp"
]
Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP22.tmp"
Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP23.tmp" with contents
[
/nologo /out:"Debug\ScriptEngine.lib"
.\Debug\IMCodeGen.obj
.\Debug\IMCodeUnits.obj
.\Debug\IntermediateCode.obj
.\Debug\lex.obj
.\Debug\Message.obj
.\Debug\parse.obj
.\Debug\RelocTable.obj
.\Debug\ScriptEngine.obj
.\Debug\SymbolTable.obj
.\Debug\SyntaxTree.obj
.\Debug\VirtualMachine.obj
]
Creating command line "link.exe -lib @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP23.tmp"
<h3>Output Window</h3>
Compiling...
IMCodeGen.cpp
IMCodeUnits.cpp
IntermediateCode.cpp
lex.cpp
Message.cpp
parse.cpp
RelocTable.cpp
ScriptEngine.cpp
SymbolTable.cpp
SyntaxTree.cpp
VirtualMachine.cpp
c:\ryl\scriptengine\virtualmachine.cpp(380) : warning C4035: 'CallScriptFunction' : no return value
c:\ryl\scriptengine\virtualmachine.cpp(390) : warning C4035: 'CallScriptFunction' : no return value
c:\ryl\scriptengine\virtualmachine.cpp(401) : warning C4035: 'CallScriptFunction' : no return value
c:\ryl\scriptengine\virtualmachine.cpp(413) : warning C4035: 'CallScriptFunction' : no return value
c:\ryl\scriptengine\virtualmachine.cpp(426) : warning C4035: 'CallScriptFunction' : no return value
c:\ryl\scriptengine\virtualmachine.cpp(438) : warning C4035: 'CallScriptFunction' : no return value
Generating Code...
Creating library...
<h3>Results</h3>
ScriptEngine.lib - 0 error(s), 6 warning(s)
</pre>
</body>
</html>

View File

@@ -0,0 +1,374 @@
<?xml version="1.0" encoding="ks_c_5601-1987"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="ScriptEngine"
ProjectGUID="{195948FE-13D7-48B9-B335-D8D29E1DFB2E}"
SccProjectName="&quot;$/ScriptEngine&quot;, DOCAAAAA"
SccLocalPath="..\..\mp-project\scriptengine">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="4"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\Debug/ScriptEngine.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile=".\Debug\ScriptEngine.lib"
SuppressStartupBanner="TRUE"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1042"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="4"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
StringPooling="TRUE"
RuntimeLibrary="0"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="2"
PrecompiledHeaderFile=".\Release/ScriptEngine.pch"
AssemblerOutput="2"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile=".\Release\ScriptEngine.lib"
SuppressStartupBanner="TRUE"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1042"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath="IMCodeGen.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="IMCodeUnits.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="IntermediateCode.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="lex.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="Message.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="parse.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="RelocTable.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="ScriptEngine.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="SymbolTable.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="SyntaxTree.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="VirtualMachine.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
<File
RelativePath="BaseDef.h">
</File>
<File
RelativePath="IMCodeGen.h">
</File>
<File
RelativePath="IMCodeUnits.h">
</File>
<File
RelativePath="IntermediateCode.h">
</File>
<File
RelativePath="lex.h">
</File>
<File
RelativePath="lexsymb.h">
</File>
<File
RelativePath="Message.h">
</File>
<File
RelativePath="RelocTable.h">
</File>
<File
RelativePath="ScriptEngine.h">
</File>
<File
RelativePath="STL.h">
</File>
<File
RelativePath="SymbolTable.h">
</File>
<File
RelativePath="SyntaxTree.h">
</File>
<File
RelativePath="unistd.h">
</File>
<File
RelativePath="VirtualMachine.h">
</File>
</Filter>
<File
RelativePath="string.l">
</File>
<File
RelativePath="string.y">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,101 @@
# Microsoft Developer Studio Project File - Name="ScriptTest" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=ScriptTest - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "ScriptTest.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "ScriptTest.mak" CFG="ScriptTest - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "ScriptTest - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "ScriptTest - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""$/ScriptEngine/ScriptTest", MFDAAAAA"
# PROP Scc_LocalPath "."
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "ScriptTest - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x412 /d "NDEBUG"
# ADD RSC /l 0x412 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "ScriptTest - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x412 /d "_DEBUG"
# ADD RSC /l 0x412 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"ScriptTest.exe" /pdbtype:sept
!ENDIF
# Begin Target
# Name "ScriptTest - Win32 Release"
# Name "ScriptTest - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\main.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@@ -0,0 +1,238 @@
void Print( int );
void Print( float );
void Print( string );
void Print( bool );
int getDouble( int n )
{
return n*n;
}
float getDouble( float f )
{
return f*f;
}
float TestFloat( float f1, float f2 )
{
return f1 * f2;
}
float TestFloat( float f1, float f2, float f3 )
{
return f1 * f2 * f3;
}
float TestFloat( float f1, float f2, float f3, float f4 )
{
return f1 * f2 * f3 * f4;
}
void TestArith()
{
Print( "--------<2D><><EFBFBD><EFBFBD> <20><>Ģ<EFBFBD><C4A2><EFBFBD><EFBFBD> <20>׽<EFBFBD>Ʈ---------" );
int iint1 = 54253;
int iint2 = 1840;
int iint3 = iint1 + iint2;
Print( iint3 );
Print( iint1 - iint2 );
iint3 = iint1 * iint2;
Print( iint3 );
iint3 = iint1 / iint2;
Print( iint3 );
iint3 = iint1 % iint2;
Print( iint3 );
Print( iint3++ );
Print( iint3-- );
Print( ++iint3 );
Print( --iint3 );
Print( iint3 += iint1 );
Print( iint1 - iint3 );
Print( iint3 -= iint1 );
Print( iint3 *= iint2 );
Print( iint3 /= iint2 );
Print( iint3 %= iint1 );
}
void ScriptMain()
{
string str1 = "str1<72><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>~";
string str2 = "str2<72><32><EFBFBD>շ<EFBFBD>~~";
float f1 = 0.43521;
float f2 = 98.3145;
int i1 = 4352;
int i2 = 986214;
bool b1 = true;
bool b2 = false;
Print( "--------string <20>׽<EFBFBD>Ʈ--------" );
string str3;
Print( str3 = str1 );
str3 = i1;
Print( str3 );
Print( str3 = f1 );
str3 = b1;
Print( str3 );
str3 = "ũũũ ";
str3 += str2;
Print( str3 );
str3 += i2;
Print( str3 );
str3 += f2;
Print( str3 );
str3 += b2;
Print( str3 );
Print( str1 + str2 );
Print( str1 + i1 );
Print( str1 + f1 );
Print( str1 + b1 );
Print( str2 + str1 );
Print( i2 + str2 );
Print( f2 + str2 );
Print( b2 + str2 );
str3 = str1 == str2;
Print( str3 );
str3 = str1 == "str1<72><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>~";
Print( str3 );
str3 = str1 != str2;
Print( str3 );
Print( "-------Init Declaration <20>׽<EFBFBD>Ʈ-------" );
string sstr1 = str1;
Print( sstr1 );
string sstr2 = i1;
Print( sstr2 );
string sstr3 = f1;
Print( sstr3 );
string sstr4 = b1;
Print( sstr4 );
string sstr5 = str1 + str2;
Print( sstr5 );
string sstr6 = str1 + i2;
Print( sstr6 );
string sstr7 = str1 + f2;
Print( sstr7 );
string sstr8 = str1 + b2;
Print( sstr8 );
string sstr9 = i1 + str2;
Print( sstr9 );
string sstr10 = f1 + str2;
Print( sstr10 );
string sstr11 = b1 + str2;
Print( sstr11 );
string sstr12 = str1 == "str1<72><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>~";
Print( sstr12 );
string sstr13 = str1 != str2;
Print( sstr13 );
string sstr14 = str2 == "ũũũ";
Print( sstr14 );
Print( "-------Float <20><>Ģ<EFBFBD><C4A2><EFBFBD><EFBFBD> <20>׽<EFBFBD>Ʈ--------" );
Print( f1 + f2 );
Print( f1 - f2 );
Print( f1 * f2 );
Print( f1 / f2 );
Print( ++f1 );
Print( --f1 );
Print( f1++ );
Print( f1-- );
Print( f1 );
Print( f1 += f2 );
Print( f1 -= f2 );
Print( f1 *= f2 );
Print( f1 /= f2 );
Print( "-------------<2D><20>׽<EFBFBD>Ʈ------------" );
int arrInt[] = { 2145, 124765, 7568, 7824, 23562351 };
float arrFloat[] = { 0.325, 85.235, 82.3523, 325.1216 };
bool arrBool[] = { true, false, true, str1!=str2 };
for( int i = 0; i < 5; i++ )
Print( arrInt[i] );
i = 0;
while( i < 4 )
{
if( i == 2 )
{
i++;
continue;
}
Print( arrFloat[i++] );
}
for( i = 0;; i++ )
{
if( i >= 4 )
break;
string strTemp;
strTemp = arrBool[i];
Print( strTemp );
}
string arrStr[] = { "str1<72>޷<EFBFBD>", "str2ũũ", "str3<72>ֱ۷<D6B1>?"
, "str4<72><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 425346, 4125.5636, true, str1 };
for( i = 0; i < 8; i++ )
Print( arrStr[i] );
if( arrInt[0] != 2145 )
Print( "<22>ٺ<EFBFBD>" );
else
TestArith();
switch( arrInt[1] )
{
case 2145 :
Print( "2145<34><35><EFBFBD><EFBFBD>~" );
break;
case 124765 :
Print( "124765<36><35><EFBFBD><EFBFBD>~" );
case 7568 :
Print( "7568<36><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD>~" );
break;
case 7824 :
Print( "7824<32><34><EFBFBD><EFBFBD>~" );
break;
case 23562351 :
Print( "23562351<35><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>~" );
break;
default :
Print( "default<6C><74><EFBFBD><EFBFBD>~" );
}
Print( getDouble( 10 ) );
Print( getDouble( 4.4 ) );
Print( true );
Print( false );
}

View File

@@ -0,0 +1,94 @@
#include <iostream>
#include <conio.h> //getch
using namespace std;
#include "..\ScriptEngine.h"
void PrintInt( int n )
{
cout << "Print( int ) ==> " << n << endl;
}
void PrintFloat( float f )
{
cout << "Print( float ) ==> " << f << endl;
}
void PrintStr( const char * str )
{
cout << "Print( const char * ) ==> " << str << endl;
}
void PrintBOOL( BOOL b )
{
cout << "Print( bool ) ==> ";
if( b )
cout << "true";
else
cout << "false";
cout << endl;
}
void ScriptMessage( const char * msg )
{
cout << "##" << msg << "##\n";
}
void main( int argc, char *argv[] )
{
_SE_SetMessageFunction( ScriptMessage );
SCRIPT Script;
if( argc != 2 )
{
Script = _SE_Create( "TestCode.gsf" );
}
else
{
Script = _SE_Create( argv[1] );
}
if( Script == 0 )
cout << "usage : ScriptTest [gsf filename]" << endl;
_SE_RegisterFunction( Script, PrintInt, T_VOID, "Print", T_INT, T_VOID );
_SE_RegisterFunction( Script, PrintFloat, T_VOID, "Print", T_FLOAT, T_VOID );
_SE_RegisterFunction( Script, PrintStr, T_VOID, "Print", T_STRING, T_VOID );
_SE_RegisterFunction( Script, PrintBOOL, T_VOID, "Print", T_BOOL, T_VOID );
_SE_Execute( Script );
SE_FUNC ScriptMain = _SE_GetScriptFunction( Script, T_VOID, "ScriptMain", 0 );
_SE_CallScriptFunction( Script, ScriptMain );
SE_FUNC getDoubleFunc = _SE_GetScriptFunction( Script, T_INT, "getDouble", T_INT, 0 );
AnyData result = _SE_CallScriptFunction( Script, getDoubleFunc, 1000 );
cout << "getDouble() ==> " << result.intValue << endl;
SE_FUNC getDoubleFunc2 = _SE_GetScriptFunction( Script, T_FLOAT, "getDouble", T_FLOAT, 0 );
AnyData result2 = _SE_CallScriptFunction( Script, getDoubleFunc2, 0.534f );
cout << "getDouble(float) ==> " << result2.floatValue << endl;
SE_FUNC TestFloat1 = _SE_GetScriptFunction( Script, T_FLOAT, "TestFloat", T_FLOAT, T_FLOAT, 0 );
result = _SE_CallScriptFunction( Script, TestFloat1, 0.325f, 13.535f ); //4.398875
cout << "TestFloat( float, float ) ==> " << result.floatValue << endl;
SE_FUNC TestFloat2 = _SE_GetScriptFunction( Script, T_FLOAT, "TestFloat", T_FLOAT, T_FLOAT, T_FLOAT, 0 );
result = _SE_CallScriptFunction( Script, TestFloat2, 0.23415f, 8412.5325f, 212.53f ); //418640.4218
cout << "TestFloat( float, float, float ) ==> " << result.floatValue << endl;
SE_FUNC TestFloat3 = _SE_GetScriptFunction( Script, T_FLOAT, "TestFloat", T_FLOAT, T_FLOAT, T_FLOAT, T_FLOAT, 0 );
result = _SE_CallScriptFunction( Script, TestFloat3, 32.3f, 35.2f, 8.2f, 93.66f );
cout << "TestFloat( float, float, float, float ) ==> " << result.floatValue << endl; //873198.92352
cout << "Press any key to continue...\n";
getch();
_SE_Destroy( Script );
}

View File

@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// ScriptEngine.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

View File

@@ -0,0 +1,24 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__BA59493D_1C58_4CCC_8997_52673E806120__INCLUDED_)
#define AFX_STDAFX_H__BA59493D_1C58_4CCC_8997_52673E806120__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Insert your headers here
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__BA59493D_1C58_4CCC_8997_52673E806120__INCLUDED_)

View File

@@ -0,0 +1,524 @@
#include "SymbolTable.h"
#include <assert.h>
#include <map>
#include <string>
#include <list>
///////////////////////////////////////////////////////////////////////////////////
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
const char * DataTypeString[] = { "void", "bool", "int", "float", "string" };
///////////////////////////////////////////////////////////////////////////////////
//
SFuncType::SFuncType()
: m_data( 0 )
{
}
SFuncType::SFuncType( unsigned long data )
: m_data( data )
{
}
int SFuncType::GetArgCount()
{
int i = 0;
for( ; i < 7; i++ )
{
if( GetArgType( i ) == T_VOID )
break;
}
return i;
}
const char* SFuncType::ToString( const char * szFuncName )
{
static char szBuffer[128];
int n = sprintf( szBuffer, "%s %s(", DataTypeString[GetReturnType()], szFuncName );
char * pBuffer = szBuffer + n;
eDataType argType = GetArgType( 0 );
if( argType != T_VOID )
{
n = sprintf( pBuffer, " %s", DataTypeString[ argType ] );
pBuffer += n;
for( int i = 1; i < 7; i++ )
{
argType = GetArgType( i );
if( argType == T_VOID )
break;
n = sprintf( pBuffer, ", %s", DataTypeString[ argType ] );
pBuffer += n;
}
strcpy( pBuffer, " " );
pBuffer += 1;
}
strcpy( pBuffer, ")" );
return szBuffer;
}
struct ConstInfo
{
eDataType m_dataType;
int m_iOffset;
ConstInfo()
: m_dataType( T_VOID ), m_iOffset( 0 )
{}
ConstInfo( eDataType type )
: m_dataType( type ), m_iOffset( 0 )
{}
ConstInfo( eDataType type, int offset )
: m_dataType( type ), m_iOffset( offset )
{}
};
struct VarInfo
{
eDataType m_dataType;
int m_iCount; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. <20>Ϲ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<>̰<EFBFBD> <20><EFBFBD><E8BFAD> <20><><EFBFBD><EFBFBD> <20><20><><EFBFBD><EFBFBD>.
int m_iOffset;
VarInfo()
: m_dataType( T_VOID ), m_iCount( 0 ), m_iOffset( 0 )
{}
VarInfo( eDataType dataType, int count )
: m_dataType( dataType ), m_iCount( count ), m_iOffset( 0 )
{}
VarInfo( eDataType dataType, int count, int offset )
: m_dataType( dataType ), m_iCount( count ), m_iOffset( offset )
{}
};
typedef CSymbolTable::VAR_CONTAINER VAR_CONTAINER;
typedef VAR_CONTAINER::value_type Value_Type;
typedef struct SLocalVarInfo
{
int m_iFuncID;
VAR_CONTAINER m_ArgContainer;
VAR_CONTAINER m_VarContainer;
SLocalVarInfo()
: m_iFuncID( 0 )
{}
} LOCALVARINFO;
///////////////////////////////////////////////////////////////////////////////////
//
CSymbolTable::CSymbolTable()
: m_pConstants( new CONST_CONTAINER )
, m_pGlobalVar( new VAR_CONTAINER )
, m_pLocalVars( new LOCALVAR_CONTAINER )
, m_pCurNameSpace( m_pGlobalVar )
, m_pNameSpace2( NULL )
, m_pFunctions( new FUNC_CONTAINER )
, m_eCurrentType( T_VOID )
, m_pCurrentLocalVar( NULL )
, m_iVarOffset( 0 )
, m_iVarOffsetGlobal( 0 )
, m_iOffsetFactor( 4 )
, m_iStringOffset( 0 )
{
}
CSymbolTable::~CSymbolTable()
{
delete m_pConstants;
delete m_pGlobalVar;
delete m_pLocalVars;
delete m_pFunctions;
}
void CSymbolTable::Create()
{
}
void CSymbolTable::Destroy()
{
m_pConstants->clear();
m_pGlobalVar->clear();
m_pLocalVars->clear();
m_pFunctions->clear();
m_eCurrentType = T_VOID;
}
int CSymbolTable::AddConst( const char * szName, eDataType type )
{
int finded = FindConst( szName );
if( finded != 0 )
return finded;
pair< CONST_CONTAINER::iterator, bool > result;
if( type == T_STRING )
{
result = m_pConstants->insert( CONST_CONTAINER::value_type( szName, ConstInfo( type, m_iStringOffset ) ) );
m_iStringOffset += strlen( szName ) + 1;
}
else
result = m_pConstants->insert( CONST_CONTAINER::value_type( szName, type ) );
return int(&(*result.first));
}
int CSymbolTable::AddArrVar( const char * szName, eDataType type, int nArray )
{
pair< VAR_CONTAINER::iterator, bool > result;
if( m_pCurrentLocalVar == NULL )
{
result = m_pCurNameSpace->insert( VAR_CONTAINER::value_type( szName, VARINFO( type, nArray, m_iVarOffset ) ) );
m_iVarOffset += m_iOffsetFactor * nArray;
}
else
{
m_iVarOffset += m_iOffsetFactor * nArray;
result = m_pCurNameSpace->insert( VAR_CONTAINER::value_type( szName, VARINFO( type, nArray, m_iVarOffset ) ) );
}
if( !result.second )
return 0;
return int(&(*result.first));
}
int CSymbolTable::AddFunc( bool hasDef, const char * szName, SFuncType type )
{
typedef FUNC_CONTAINER::value_type value_type;
int finded = FindFunc( szName, type );
if( hasDef )
{
if( finded != 0 )
{
if( IsFuncDefined( finded ) )
{
return 0;
}
else
{
value_type * pValue = (value_type*)finded;
pValue->second.second = true;
return finded;
}
}
else
{
FUNC_CONTAINER::iterator result = m_pFunctions->insert( FUNC_CONTAINER::value_type( szName, FUNCINFO( type, true ) ) );
return int(&(*result));
}
}
else
{
if( finded == 0 )
{
FUNC_CONTAINER::iterator result = m_pFunctions->insert( FUNC_CONTAINER::value_type( szName, FUNCINFO( type, false ) ) );
return int(&(*result));
}
else
return finded;
}
}
int CSymbolTable::FindConst( const char * szName )
{
CONST_CONTAINER::iterator result = m_pConstants->find( szName );
if( result == m_pConstants->end() )
return 0;
return int(&(*result));
}
int CSymbolTable::FindVar( const char * szName )
{
VAR_CONTAINER::iterator result = m_pCurNameSpace->find( szName );
if( result == m_pCurNameSpace->end() )
{
if( m_pNameSpace2 )
{
result = m_pNameSpace2->find( szName );
if( result == m_pNameSpace2->end() )
{
if( m_pCurNameSpace != m_pGlobalVar )
{
result = m_pGlobalVar->find( szName );
if( result == m_pGlobalVar->end() )
return 0;
}
else
return 0;
}
}
else
{
return 0;
}
}
return int(&(*result));
}
int CSymbolTable::FindFunc( const char * szName, SFuncType type )
{
typedef FUNC_CONTAINER::iterator iterator;
pair< iterator, iterator > result = m_pFunctions->equal_range( szName );
while( result.first != result.second )
{
if( result.first->second.first == type )
return int(&(*result.first));
result.first++;
}
return 0;
}
const char* CSymbolTable::GetNameOfConst( int symbolID )
{
typedef CONST_CONTAINER::value_type value_type;
value_type * pValue = (value_type*)symbolID;
return pValue->first.c_str();
}
eDataType CSymbolTable::GetTypeOfConst( int symbolID )
{
typedef CONST_CONTAINER::value_type value_type;
value_type * pValue = (value_type*)symbolID;
return pValue->second.m_dataType;
}
int CSymbolTable::GetOffsetOfConst( int symbolID )
{
typedef CONST_CONTAINER::value_type value_type;
value_type * pValue = (value_type*)symbolID;
return pValue->second.m_iOffset;
}
const char* CSymbolTable::GetNameOfVar( int symbolID )
{
typedef VAR_CONTAINER::value_type value_type;
value_type * pValue = (value_type*)symbolID;
return pValue->first.c_str();
}
eDataType CSymbolTable::GetTypeOfVar( int symbolID )
{
typedef VAR_CONTAINER::value_type value_type;
value_type * pValue = (value_type*)symbolID;
return pValue->second.m_dataType;
}
int CSymbolTable::GetCountOfVar( int symbolID )
{
typedef VAR_CONTAINER::value_type value_type;
value_type * pValue = (value_type*)symbolID;
return pValue->second.m_iCount;
}
int CSymbolTable::GetOffsetOfVar( int varID )
{
typedef VAR_CONTAINER::value_type value_type;
value_type * pValue = (value_type*)varID;
return pValue->second.m_iOffset;
}
const char* CSymbolTable::GetNameOfFunc( int symbolID )
{
typedef FUNC_CONTAINER::value_type value_type;
value_type * pValue = (value_type*)symbolID;
return pValue->first.c_str();
}
const char* CSymbolTable::GetTypeStringOfFunc( int symbolID )
{
SFuncType type = GetTypeOfFunc( symbolID );
return type.ToString( GetNameOfFunc( symbolID ) );
}
SFuncType CSymbolTable::GetTypeOfFunc( int symbolID )
{
typedef FUNC_CONTAINER::value_type value_type;
value_type * pValue = (value_type*)symbolID;
return pValue->second.first;
}
bool CSymbolTable::IsFuncDefined( int symbolID )
{
typedef FUNC_CONTAINER::value_type value_type;
value_type * pValue = (value_type*)symbolID;
return pValue->second.second;
}
void CSymbolTable::BeginLocalNameSpace()
{
m_pLocalVars->push_back( LOCALVARINFO() );
m_pCurrentLocalVar = &m_pLocalVars->back();
m_pCurNameSpace = &m_pCurrentLocalVar->m_ArgContainer;
m_pNameSpace2 = &m_pCurrentLocalVar->m_VarContainer;
m_iVarOffsetGlobal = m_iVarOffset;
m_iVarOffset = 4;
m_iOffsetFactor = 4;
}
void CSymbolTable::EndLocalNameSpace( int FuncID )
{
m_pCurNameSpace = m_pGlobalVar;
m_pNameSpace2 = NULL;
m_pCurrentLocalVar = NULL;
if( FuncID )
{
m_pLocalVars->back().m_iFuncID = FuncID;
}
else
m_pLocalVars->pop_back();
m_iVarOffset = m_iVarOffsetGlobal;
m_iOffsetFactor = 4;
}
void CSymbolTable::EndArgument()
{
if( m_pCurrentLocalVar )
{
m_pCurNameSpace = &m_pCurrentLocalVar->m_VarContainer;
m_pNameSpace2 = &m_pCurrentLocalVar->m_ArgContainer;
m_iVarOffset = 0;
m_iOffsetFactor = -4;
}
}
int CSymbolTable::GetLocalVarSize( int FuncID )
{
int size = 0;
VAR_CONTAINER * pNameSpace = NULL;
for( LOCALVAR_CONTAINER::iterator i = m_pLocalVars->begin(); i != m_pLocalVars->end(); i++ )
{
if( i->m_iFuncID == FuncID )
{
pNameSpace = &(i->m_VarContainer);
break;
}
}
if( pNameSpace == NULL )
{
ScriptSystemError( "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20≯<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ã<><C3A3> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. (CSymbolTable::GetLocalVarSize)" );
return 0;
}
for( VAR_CONTAINER::iterator j = pNameSpace->begin(); j != pNameSpace->end(); j++ )
{
size += j->second.m_iCount * 4;
}
return size;
}
int CSymbolTable::GetGlobalVarSize()
{
int size = 0;
for( VAR_CONTAINER::iterator i = m_pGlobalVar->begin(); i != m_pGlobalVar->end(); i++ )
{
size += i->second.m_iCount * 4;
}
return size;
}
int CSymbolTable::GetStringBufferSize()
{
return m_iStringOffset;
}
void CSymbolTable::StringBuffer( void * pBuffer )
{
char * pBuf = (char*)pBuffer;
for( CONST_CONTAINER::iterator i = m_pConstants->begin(); i != m_pConstants->end(); i++ )
{
if( i->second.m_dataType == T_STRING )
{
strcpy( pBuf + i->second.m_iOffset, i->first.c_str() );
}
}
}
void ShowVariables( CSymbolTable::VAR_CONTAINER & Container, MESSAGE_FUNCTION2 Print )
{
for( CSymbolTable::VAR_CONTAINER::iterator i = Container.begin(); i!= Container.end(); i++ )
{
Print( i->first.c_str() );
if( i->second.m_iCount != 1 )
{
Print( "[%d]", i->second.m_iCount );
}
Print( " : %s <%d>\n", DataTypeString[ i->second.m_dataType ], i->second.m_iOffset );
}
}
void CSymbolTable::Show( MESSAGE_FUNCTION2 Print )
{
const char * DataTypeString[] = { "void", "bool", "int", "float", "string" };
Print( "--Constants--\n" );
for( CONST_CONTAINER::iterator i = m_pConstants->begin(); i!= m_pConstants->end(); i++ )
{
Print( "%s : %s <%d>\n", i->first.c_str(), DataTypeString[ i->second.m_dataType ], i->second.m_iOffset );
}
Print( "--Global Variables--\n" );
ShowVariables( *m_pGlobalVar, Print );
Print( "--Local Variables--\n" );
for( LOCALVAR_CONTAINER::iterator l = m_pLocalVars->begin(); l != m_pLocalVars->end(); l++ )
{
Print( "<%s>\n", this->GetNameOfFunc( l->m_iFuncID ) );
ShowVariables( l->m_ArgContainer, Print );
ShowVariables( l->m_VarContainer, Print );
}
Print( "--Functions--\n" );
for( FUNC_CONTAINER::iterator k = m_pFunctions->begin(); k != m_pFunctions->end(); k++ )
{
Print( GetTypeStringOfFunc( int(&(*k)) ) );
Print( "\n" );
}
}
///////////////////////////////////////////////////////////////////////////////////
//

View File

@@ -0,0 +1,121 @@
#ifndef _SymbolTable_H_
#define _SymbolTable_H_
#include "STL.h"
#include "BaseDef.h"
#include "Message.h"
#define SYSVAR_SWITCHTEMP "<SwitchTempVar>"
#define SYSVAR_FLOATUNIT "<FloatUnit>"
#define SYSVAR_FLOATTEMP "<FloatTemp>"
#define SYSVAR_TRUE "<True>"
#define SYSVAR_FALSE "<False>"
#define SYSVAR_CONVBUFFER "<ConvBuffer>"
///////////////////////////////////////////////////////////////////////////////////
// <09>Լ<EFBFBD><D4BC><EFBFBD> <20><><EFBFBD>ڴ<EFBFBD> 7<><37><EFBFBD><EFBFBD> <20>Ѿ <20>ȵȴ<C8B5>.
struct SFuncType
{
public:
unsigned long m_data;
public:
SFuncType();
SFuncType( unsigned long );
void SetArgType( int nth, eDataType arg ) { m_data |= ( 0x0000000f & arg ) << (nth*4); }
void SetReturnType( eDataType retType ) { m_data |= ( 0x0000000f & retType ) << 28; }
eDataType GetArgType( int nth ) { return (eDataType)(m_data >> (nth*4) & 0x0000000f); }
eDataType GetReturnType() { return (eDataType)(m_data >> 28 & 0x0000000f); }
int GetArgCount();
const char* ToString( const char * szFuncName );
bool operator==( const SFuncType & rhs ) { return (m_data & 0x0fffffff) == (rhs.m_data & 0x0fffffff); }
bool operator!=( const SFuncType & rhs ) { return (m_data & 0x0fffffff) != (rhs.m_data & 0x0fffffff); }
};
///////////////////////////////////////////////////////////////////////////////////
//
class CSymbolTable
{
public:
typedef map< int, int > OFFSETMAP;
typedef unsigned char byte;
typedef struct ConstInfo CONSTINFO;
typedef map<string,CONSTINFO> CONST_CONTAINER;
typedef struct VarInfo VARINFO;
typedef map<string,VARINFO> VAR_CONTAINER;
typedef struct SLocalVarInfo LOCALVARINFO;
typedef list<LOCALVARINFO> LOCALVAR_CONTAINER;
typedef pair<SFuncType, bool> FUNCINFO;
typedef multimap<string,FUNCINFO> FUNC_CONTAINER;
protected:
CONST_CONTAINER * m_pConstants;
VAR_CONTAINER * m_pGlobalVar;
LOCALVAR_CONTAINER* m_pLocalVars;
VAR_CONTAINER * m_pCurNameSpace;
VAR_CONTAINER * m_pNameSpace2; //CurNameSpace<63><65> <20><><EFBFBD><EFBFBD> <20>̷<EFBFBD>( CurNameSpace<63><65> ArgContainer<65><72> <20><> <20>̰<EFBFBD><CCB0><EFBFBD> VarContainer, VarContainer<65><72> <20><> ArgContainer )
FUNC_CONTAINER * m_pFunctions;
LOCALVARINFO * m_pCurrentLocalVar;
eDataType m_eCurrentType;
int m_iVarOffset, m_iVarOffsetGlobal;
int m_iOffsetFactor;
int m_iStringOffset;
public:
CSymbolTable();
~CSymbolTable();
void Create();
void Destroy();
int AddConst( const char * szName, eDataType type );
int AddArrVar( const char * szName, eDataType, int nArray );
int AddArrVar( const char * szName, int nArray ) { return AddArrVar( szName, m_eCurrentType, nArray ); }
int AddVar( const char * szName, eDataType type ) { return AddArrVar( szName, type, 1 ); }
int AddVar( const char * szName ) { return AddVar( szName, m_eCurrentType ); }
int AddFunc( bool hasDef, const char * szName, SFuncType );
void SetCurrentType( eDataType type ) { m_eCurrentType = type; }
eDataType GetCurrentType() { return m_eCurrentType; }
int FindConst( const char * szName );
int FindVar( const char * szName );
int FindFunc( const char * szname, SFuncType );
void BeginLocalNameSpace();
void EndLocalNameSpace( int ); //<2F><><EFBFBD>ڷδ<DAB7> <20>Լ<EFBFBD><D4BC><EFBFBD> ID<49><44> <20>Ѱ<EFBFBD><D1B0>ش<EFBFBD>.
void EndArgument();
const char* GetNameOfConst( int );
eDataType GetTypeOfConst( int );
int GetOffsetOfConst( int );
const char* GetNameOfVar( int );
eDataType GetTypeOfVar( int );
int GetCountOfVar( int );
int GetOffsetOfVar( int ); //<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> EBP<42><50> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
//<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ּҿ<D6BC> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
const char* GetNameOfFunc( int );
const char* GetTypeStringOfFunc( int );
SFuncType GetTypeOfFunc( int );
bool IsFuncDefined( int );
int GetLocalVarSize( int );
int GetGlobalVarSize();
int GetStringBufferSize();
void StringBuffer( void * );
void Show( MESSAGE_FUNCTION2 Print );
};
///////////////////////////////////////////////////////////////////////////////////
#endif

View File

@@ -0,0 +1,547 @@
#include "SyntaxTree.h"
#include "SymbolTable.h"
#include "lex.h"
#include <assert.h>
#include <set>
///////////////////////////////////////////////////////////////////////////////
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CSyntaxTree * g_pSynTree = 0;
CSymbolTable * g_pSymbolTable = 0;
char szBuffer[1024];
///////////////////////////////////////////////////////////////////////////////
// Parser <20>Լ<EFBFBD>
void yyerror( char *msg )
{
CompilerMessage( msg );
}
extern "C" int yywrap(void) {
return 1;
}
////////////////////////////////////////////////////////////////////////////////
// <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD>
SNode::SNode( int line, eSyntaxType type, SNode * pNode1, SNode * pNode2, SNode * pNode3 )
: m_iLine( line ), m_eType( type ), m_SymbolID( 0 ), m_eReturnType( T_VOID )
{
m_ArrPtrChilds[0] = pNode1;
m_ArrPtrChilds[1] = pNode2;
m_ArrPtrChilds[2] = pNode3;
}
const char * SyntaxTypeName[] =
{
"TYPE_STATEMENT_LIST",
"TYPE_EMPTY_STATEMENT",
"TYPE_ERROR_STATEMENT",
"TYPE_EXPRESSION",
"TYPE_IF_STATEMENT",
"TYPE_IF_ELSE_STATEMENT",
"TYPE_SWITCH_STATEMENT",
"TYPE_SWITCH_CASES",
"TYPE_CASE_ONE",
"TYPE_DEFAULT",
"TYPE_FOR_STATEMENT",
"TYPE_WHILE_STATEMENT",
"TYPE_FOR_EXPRESSION",
"TYPE_BREAK_STATEMENT",
"TYPE_CONTINUE_STATEMENT",
"TYPE_RETURN_STATEMENT",
"TYPE_DECLARATION",
"TYPE_SPECIFIER_VOID",
"TYPE_SPECIFIER_INT",
"TYPE_SPECIFIER_FLOAT",
"TYPE_SPECIFIER_BOOL",
"TYPE_SPECIFIER_STRING",
"TYPE_VARIABLE",
"TYPE_DECLARATOR_LIST",
"TYPE_INIT_DECLARATION",
"TYPE_NORMAL_DECLARATION",
"TYPE_ARRAY_INITIALIZE",
"TYPE_ARRAY_INITIALIZE2",
"TYPE_ARRAY_DECLARATION",
"TYPE_FUNCTION_DECLARATION",
"TYPE_INITIALIZER_LIST",
"TYPE_ARGUMENT_DECLARATION_LIST",
"TYPE_ARGUMENT_DECLARATION",
"TYPE_FUNCTION_DEFINITION",
"TYPE_CONSTANT_EXPRESSION",
"TYPE_EXPRESSION_LIST",
"TYPE_ASSIGNMENT_EXPESSION",
"TYPE_OR_EXPRESSION",
"TYPE_AND_EXPRESSION",
"TYPE_NOT_EXPRESSION",
"TYPE_EQUALITY_EXPRESSION",
"TYPE_NOTEQAUL_EXPRESSION",
"TYPE_LESSTHAN_EXPRESSION",
"TYPE_MORETHAN_EXPRESSION",
"TYPE_LESSTHANOREQUAL_EXPRESSION",
"TYPE_MORETHANOREQUAL_EXPRESSION",
"TYPE_ADDITION_EXPRESSION",
"TYPE_SUBTRACTION_EXPRESSION",
"TYPE_MULTIPLICATION_EXPRESSION",
"TYPE_DIVISION_EXPRESSION",
"TYPE_REMINDER_EXPRESSION",
"TYPE_COMPOUND_ADDITION",
"TYPE_COMPOUND_SUBTRACTION",
"TYPE_COMPOUND_MULTIPLICATION",
"TYPE_COMPOUND_DIVISION",
"TYPE_COMPOUND_REMINDER",
"TYPE_PREFIXINCREMENT",
"TYPE_PREFIXDECREMENT",
"TYPE_ARRAY_INDEXING",
"TYPE_FUNCTION_CALL",
"TYPE_POSTFIXINCREMENT",
"TYPE_POSTFIXDECREMENT"
};
void SNode::Show( int level, MESSAGE_FUNCTION2 Print, CSymbolTable * pSymbolTable )
{
const char * DataTypeString[] = { "void", "bool", "int", "float", "string" };
int nl = level;
if (!this) return;
if( m_eType != TYPE_STATEMENT_LIST )
{
Print( itoa( m_iLine, szBuffer, 10 ) );
Print( ": " );
for ( int i = 0; i < level; i++ )
Print( " " );
Print( SyntaxTypeName[m_eType] );
switch( m_eType )
{
case TYPE_CONSTANT_EXPRESSION :
Print( " ( " );
Print( pSymbolTable->GetNameOfConst( m_SymbolID ) );
Print( " : " );
Print( DataTypeString[ pSymbolTable->GetTypeOfConst( m_SymbolID ) ] );
Print( " )" );
break;
case TYPE_INIT_DECLARATION :
case TYPE_NORMAL_DECLARATION :
case TYPE_ARRAY_INITIALIZE :
case TYPE_ARRAY_INITIALIZE2 :
case TYPE_ARRAY_DECLARATION :
case TYPE_ARGUMENT_DECLARATION :
case TYPE_VARIABLE :
case TYPE_PREFIXINCREMENT :
case TYPE_PREFIXDECREMENT :
case TYPE_POSTFIXINCREMENT :
case TYPE_POSTFIXDECREMENT :
case TYPE_COMPOUND_ADDITION :
case TYPE_COMPOUND_SUBTRACTION :
case TYPE_COMPOUND_MULTIPLICATION :
case TYPE_COMPOUND_DIVISION :
case TYPE_COMPOUND_REMINDER :
Print( " ( " );
Print( pSymbolTable->GetNameOfVar( m_SymbolID ) );
Print( " : " );
Print( DataTypeString[ pSymbolTable->GetTypeOfVar( m_SymbolID ) ] );
Print( " )" );
break;
}
nl++;
Print("\n");
}
for( int i = 0; m_ArrPtrChilds[i] != 0 && i < 3; i++ )
m_ArrPtrChilds[i]->Show( nl, Print, pSymbolTable );
}
bool SNode::SemanticCheck( CSymbolTable * pSymbolTable )
{
static eDataType tempType, tempType2;
switch( m_eType )
{
case TYPE_ARRAY_INDEXING :
//ù<><C3B9>° int<6E>϶<EFBFBD><CFB6><EFBFBD> <20><>ȿ<EFBFBD>ϰ<EFBFBD>, <20>ɺ<EFBFBD><C9BA><EFBFBD> Ÿ<>Կ<EFBFBD> <20><><EFBFBD><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
if( m_ArrPtrChilds[0]->m_eReturnType != T_INT )
return false;
else
m_eReturnType = pSymbolTable->GetTypeOfVar( m_SymbolID );
break;
case TYPE_EXPRESSION :
m_eReturnType = m_ArrPtrChilds[0]->m_eReturnType;
break;
case TYPE_ARRAY_DECLARATION :
//ù<><C3B9>° <20><><EFBFBD>ϵ尡 int<6E>϶<EFBFBD><CFB6><EFBFBD> <20><>ȿ<EFBFBD>ϰ<EFBFBD>, <20>ɺ<EFBFBD> Ÿ<>Կ<EFBFBD> <20><><EFBFBD><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
if( m_ArrPtrChilds[0]->m_eReturnType != T_INT )
return false;
else
m_eReturnType = pSymbolTable->GetTypeOfVar( m_SymbolID );
break;
case TYPE_ARRAY_INITIALIZE2 :
//<2F>ɺ<EFBFBD> Ÿ<>԰<EFBFBD> <20>ι<EFBFBD><CEB9><EFBFBD> <20><><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>˻<EFBFBD><CBBB>ϰ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20>ɺ<EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
//ù<><C3B9>° <20><><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> int<6E><74><EFBFBD>̾<EFBFBD><CCBE><EFBFBD> <20><>.
m_eReturnType = pSymbolTable->GetTypeOfVar( m_SymbolID );
if( m_ArrPtrChilds[0]->m_eReturnType != T_INT )
return false;
if( m_eReturnType != m_ArrPtrChilds[1]->m_eReturnType )
return false;
break;
case TYPE_ARRAY_INITIALIZE :
//<2F>ɺ<EFBFBD> Ÿ<>԰<EFBFBD> ù<><C3B9>° <20><><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD>ƾ<EFBFBD> <20><>.
m_eReturnType = pSymbolTable->GetTypeOfVar( m_SymbolID );
if( m_eReturnType != m_ArrPtrChilds[0]->m_eReturnType )
return false;
break;
case TYPE_INIT_DECLARATION :
case TYPE_ASSIGNMENT_EXPRESSION :
//<2F>ɺ<EFBFBD> Ÿ<>԰<EFBFBD> ù<><C3B9>° <20><><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>˻<EFBFBD><CBBB>ϰ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20>ɺ<EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
m_eReturnType = pSymbolTable->GetTypeOfVar( m_SymbolID );
if( m_eReturnType == T_VOID )
return false;
if( m_eReturnType != m_ArrPtrChilds[0]->m_eReturnType )
{
if( m_eReturnType != T_STRING )
return false;
}
break;
case TYPE_INITIALIZER_LIST :
m_eReturnType = m_ArrPtrChilds[0]->m_eReturnType;
if( m_eReturnType == T_STRING )
{
if( m_ArrPtrChilds[1]->m_eReturnType == T_VOID )
return false;
}
else if( m_ArrPtrChilds[1]->m_eReturnType == T_STRING )
{
if( m_eReturnType == T_VOID )
return false;
m_eReturnType = T_STRING;
}
else
{
if( m_eReturnType != m_ArrPtrChilds[1]->m_eReturnType )
break;
}
break;
case TYPE_DECLARATOR_LIST :
//ù<><C3B9>° <20><><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> <20>ι<EFBFBD>° <20><><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>˻<EFBFBD><CBBB>ϰ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><> ù<><C3B9>° <20><><EFBFBD>ϵ<EFBFBD> Ÿ<><C5B8> <20><><EFBFBD><EFBFBD>
if( m_ArrPtrChilds[0]->m_eReturnType != m_ArrPtrChilds[1]->m_eReturnType )
return false;
else
m_eReturnType = m_ArrPtrChilds[0]->m_eReturnType;
break;
case TYPE_ADDITION_EXPRESSION :
m_eReturnType = m_ArrPtrChilds[0]->m_eReturnType;
if( m_eReturnType == T_STRING )
{
if( m_ArrPtrChilds[1]->m_eReturnType == T_VOID )
return false;
}
else if( m_ArrPtrChilds[1]->m_eReturnType == T_STRING )
{
if( m_eReturnType == T_VOID )
return false;
m_eReturnType = T_STRING;
}
else
{
if( m_eReturnType != m_ArrPtrChilds[1]->m_eReturnType )
return false;
}
break;
case TYPE_SUBTRACTION_EXPRESSION :
case TYPE_MULTIPLICATION_EXPRESSION :
case TYPE_DIVISION_EXPRESSION :
//ù<><C3B9>° <20><><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> <20>ι<EFBFBD>° <20><><EFBFBD>ϵ尡 <20>ٸ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ȿ, int<6E><74> float<61><74><EFBFBD><EFBFBD> <20>ƴ<EFBFBD> <20><><EFBFBD><EFBFBD><ECBFA1> <20><>ȿ
if( m_ArrPtrChilds[0]->m_eReturnType != m_ArrPtrChilds[1]->m_eReturnType )
{
return false;
}
m_eReturnType = m_ArrPtrChilds[0]->m_eReturnType;
if( m_eReturnType != T_INT && m_eReturnType != T_FLOAT )
return false;
break;
case TYPE_REMINDER_EXPRESSION :
//ù<><C3B9>° <20><><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> <20>ι<EFBFBD>° <20><><EFBFBD>ϵ尡 <20>ٸ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ȿ, int<6E><74><EFBFBD><EFBFBD> <20>ƴ<EFBFBD> <20><><EFBFBD><EFBFBD><ECBFA1> <20><>ȿ
if( m_ArrPtrChilds[0]->m_eReturnType != m_ArrPtrChilds[1]->m_eReturnType )
{
return false;
break;
}
m_eReturnType = m_ArrPtrChilds[0]->m_eReturnType;
if( m_eReturnType != T_INT )
return false;
break;
case TYPE_PREFIXINCREMENT :
case TYPE_PREFIXDECREMENT :
case TYPE_POSTFIXINCREMENT :
case TYPE_POSTFIXDECREMENT :
//int<6E><74> float<61><74><EFBFBD><EFBFBD> <20>ƴ<EFBFBD> <20><><EFBFBD><EFBFBD><ECBFA1> <20><>ȿ.
m_eReturnType = pSymbolTable->GetTypeOfVar( m_SymbolID );
if( m_eReturnType != T_INT && m_eReturnType != T_FLOAT )
return false;
break;
case TYPE_NORMAL_DECLARATION :
case TYPE_CONSTANT_EXPRESSION :
case TYPE_VARIABLE :
//<2F>ɺ<EFBFBD><C9BA><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
m_eReturnType = pSymbolTable->GetTypeOfVar( m_SymbolID );
break;
case TYPE_NOT_EXPRESSION :
//ù<><C3B9>° <20><><EFBFBD>ϵ尡 BOOL<4F><4C><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><ECBFA1> <20><>ȿ<EFBFBD><C8BF>.
if( m_ArrPtrChilds[0]->m_eReturnType != T_BOOL )
return false;
else
m_eReturnType = T_BOOL;
break;
case TYPE_OR_EXPRESSION :
case TYPE_AND_EXPRESSION :
//ù<><C3B9>° <20><><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> <20>ι<EFBFBD>° <20><><EFBFBD>ϵ尡 <20><><EFBFBD><EFBFBD> bool<6F><6C><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ȿ<EFBFBD><C8BF>.
m_eReturnType = T_BOOL;
if( m_ArrPtrChilds[0]->m_eReturnType != T_BOOL || m_ArrPtrChilds[1]->m_eReturnType != T_BOOL )
{
return false;
}
break;
case TYPE_EQUALITY_EXPRESSION :
case TYPE_NOTEQAUL_EXPRESSION :
//<2F><><EFBFBD>ʰ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD>ƾ<EFBFBD> <20>ϸ<EFBFBD>, void<69><64> <20><><EFBFBD><EFBFBD> <20>ȵ<EFBFBD>.
tempType = m_ArrPtrChilds[0]->m_eReturnType;
if( tempType != m_ArrPtrChilds[1]->m_eReturnType || tempType == T_VOID )
return false;
else
m_eReturnType = T_BOOL;
break;
case TYPE_LESSTHAN_EXPRESSION :
case TYPE_MORETHAN_EXPRESSION :
case TYPE_LESSTHANOREQUAL_EXPRESSION :
case TYPE_MORETHANOREQUAL_EXPRESSION :
tempType = m_ArrPtrChilds[0]->m_eReturnType;
//ù <20><>° <20><><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> <20><> <20><>° <20><><EFBFBD>ϵ尡 <20>ٸ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ȿ, int, float<61><74><EFBFBD><EFBFBD> <20>ƴ<EFBFBD> <20><><EFBFBD><EFBFBD><ECBFA1> <20><><EFBFBD><EFBFBD>
if( tempType != m_ArrPtrChilds[1]->m_eReturnType )
return false;
if( tempType != T_INT && tempType != T_FLOAT )
return false;
m_eReturnType = T_BOOL;
break;
case TYPE_COMPOUND_ADDITION :
//<2F>ɺ<EFBFBD><C9BA><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
m_eReturnType = pSymbolTable->GetTypeOfVar( m_SymbolID );
//int<6E><74> float, string<6E><67><EFBFBD><EFBFBD> <20>ƴ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ȿ
if( m_eReturnType != T_INT && m_eReturnType != T_FLOAT && m_eReturnType != T_STRING )
return false;
//<2F>ɺ<EFBFBD> Ÿ<>԰<EFBFBD> ù<><C3B9>° <20><><EFBFBD>ϵ尡 <20>ٸ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>ɺ<EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> string<6E><67> <20><><EFBFBD><EFBFBD><ECBFA1> <20><>ȿ
if( m_eReturnType != m_ArrPtrChilds[0]->m_eReturnType )
{
if( m_eReturnType != T_STRING )
return false;
else
{
if( m_ArrPtrChilds[0]->m_eReturnType == T_VOID )
return false;
}
}
break;
case TYPE_COMPOUND_SUBTRACTION :
case TYPE_COMPOUND_MULTIPLICATION :
case TYPE_COMPOUND_DIVISION :
//<2F>ɺ<EFBFBD><C9BA><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
m_eReturnType = pSymbolTable->GetTypeOfVar( m_SymbolID );
//<2F>ɺ<EFBFBD> Ÿ<>԰<EFBFBD> ù<><C3B9>° <20><><EFBFBD>ϵ尡 <20>ٸ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ȿ, int<6E><74> float<61><74><EFBFBD><EFBFBD> <20>ƴ<EFBFBD> <20><><EFBFBD><EFBFBD><ECBFA1> <20><>ȿ
if( m_eReturnType != m_ArrPtrChilds[0]->m_eReturnType )
{
return false;
}
if( m_eReturnType != T_INT && m_eReturnType != T_FLOAT )
return false;
break;
case TYPE_COMPOUND_REMINDER :
//<2F>ɺ<EFBFBD><C9BA><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
m_eReturnType = pSymbolTable->GetTypeOfVar( m_SymbolID );
//<2F>ɺ<EFBFBD> Ÿ<>԰<EFBFBD> ù<><C3B9>° <20><><EFBFBD>ϵ尡 <20>ٸ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ȿ, int<6E><74><EFBFBD><EFBFBD> <20>ƴ<EFBFBD> <20><><EFBFBD><EFBFBD><ECBFA1> <20><>ȿ
if( m_eReturnType != m_ArrPtrChilds[0]->m_eReturnType )
{
return false;
}
if( m_eReturnType != T_INT )
return false;
break;
case TYPE_FUNCTION_CALL :
{
SFuncType type = pSymbolTable->GetTypeOfFunc( m_SymbolID );
m_eReturnType = type.GetReturnType();
break;
}
case TYPE_SWITCH_STATEMENT :
{
if( m_ArrPtrChilds[0]->m_eReturnType != T_INT )
return false;
m_eReturnType = T_VOID;
break;
}
case TYPE_CASE_ONE :
{
if( m_ArrPtrChilds[0]->m_eReturnType != T_INT )
return false;
m_eReturnType = T_VOID;
break;
}
default :
m_eReturnType = T_VOID;
break;
}
return true;
}
CSyntaxTree::CSyntaxTree()
: m_pRoot( 0 )
, m_pSymbolTable( new CSymbolTable )
, m_pPtrStorage( new PTRSTORAGE )
{
}
CSyntaxTree::~CSyntaxTree()
{
Destroy();
delete m_pSymbolTable;
delete m_pPtrStorage;
}
void CSyntaxTree::Create( const char * szFileName )
{
FILE * fp = fopen( szFileName, "rt" );
if( fp == NULL )
return;
yylloc.first_line = 1;
Create( fp );
}
void CSyntaxTree::Create( FILE * fp )
{
yyin = fp;
g_pSynTree = this;
g_pSymbolTable = m_pSymbolTable;
g_pSymbolTable->Create();
yylloc.first_line = 1;
yyparse();
}
void CSyntaxTree::Destroy()
{
typedef PTRSTORAGE::iterator ITERATOR;
for( ITERATOR i = m_pPtrStorage->begin(); i != m_pPtrStorage->end(); i++ )
{
delete (*i);
}
m_pPtrStorage->clear();
m_pSymbolTable->Destroy();
}
int CSyntaxTree::Insert( int line, eSyntaxType SynType, int childID1, int childID2, int childID3 )
{
SNode * pNode = new SNode( line, SynType, (SNode*)childID1, (SNode*)childID2, (SNode*)childID3 );
assert( m_pPtrStorage->insert( pNode ).second );
if( pNode->SemanticCheck( m_pSymbolTable ) == false )
ErrorMessage( pNode->m_iLine, "Ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>~\n" );
return (int)pNode;
}
int CSyntaxTree::Insert( int line, int symbolID, eSyntaxType SynType, int childID1, int childID2, int childID3 )
{
SNode * pNode = new SNode( line, SynType, (SNode*)childID1, (SNode*)childID2, (SNode*)childID3 );
assert( m_pPtrStorage->insert( pNode ).second );
pNode->m_SymbolID = symbolID;
if( pNode->SemanticCheck( m_pSymbolTable ) == false )
CompilerMessage2( "Error(line %d) : Ÿ<><C5B8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>~\n", pNode->m_iLine );
return (int)pNode;
}
void CSyntaxTree::SetRoot( int nodeID )
{
if( nodeID != 0 )
{
if( m_pRoot != NULL )
{
Destroy();
}
m_pRoot = (SNode*)nodeID;
}
}
void CSyntaxTree::Show( MESSAGE_FUNCTION2 Print )
{
if( m_pRoot != NULL )
{
m_pRoot->Show( 0, Print, m_pSymbolTable );
}
}

View File

@@ -0,0 +1,135 @@
#ifndef _SyntaxTree_H_
#define _SyntaxTree_H_
#include "BaseDef.h"
#include "Message.h"
#include "STL.h"
#define MAXCHILD 3
class CSymbol;
class CSyntaxTree;
class CSymbolTable;
struct _iobuf;
typedef struct _iobuf FILE;
enum eSyntaxType
{
TYPE_STATEMENT_LIST = 0,
TYPE_EMPTY_STATEMENT,
TYPE_ERROR_STATEMENT,
TYPE_EXPRESSION,
TYPE_IF_STATEMENT,
TYPE_IF_ELSE_STATEMENT,
TYPE_SWITCH_STATEMENT,
TYPE_SWITCH_CASES,
TYPE_CASE_ONE,
TYPE_DEFAULT,
TYPE_FOR_STATEMENT,
TYPE_WHILE_STATEMENT,
TYPE_FOR_EXPRESSION,
TYPE_BREAK_STATEMENT,
TYPE_CONTINUE_STATEMENT,
TYPE_RETURN_STATEMENT,
TYPE_DECLARATION,
TYPE_SPECIFIER_VOID,
TYPE_SPECIFIER_INT,
TYPE_SPECIFIER_FLOAT,
TYPE_SPECIFIER_BOOL,
TYPE_SPECIFIER_STRING,
TYPE_VARIABLE,
TYPE_DECLARATOR_LIST,
TYPE_INIT_DECLARATION,
TYPE_NORMAL_DECLARATION,
TYPE_ARRAY_INITIALIZE,
TYPE_ARRAY_INITIALIZE2,
TYPE_ARRAY_DECLARATION,
TYPE_FUNCTION_DECLARATION,
TYPE_INITIALIZER_LIST,
TYPE_ARGUMENT_DECLARATION_LIST,
TYPE_ARGUMENT_DECLARATION,
TYPE_FUNCTION_DEFINITION,
TYPE_CONSTANT_EXPRESSION,
TYPE_EXPRESSION_LIST,
TYPE_ASSIGNMENT_EXPRESSION,
TYPE_OR_EXPRESSION,
TYPE_AND_EXPRESSION,
TYPE_NOT_EXPRESSION,
TYPE_EQUALITY_EXPRESSION,
TYPE_NOTEQAUL_EXPRESSION,
TYPE_LESSTHAN_EXPRESSION,
TYPE_MORETHAN_EXPRESSION,
TYPE_LESSTHANOREQUAL_EXPRESSION,
TYPE_MORETHANOREQUAL_EXPRESSION,
TYPE_ADDITION_EXPRESSION,
TYPE_SUBTRACTION_EXPRESSION,
TYPE_MULTIPLICATION_EXPRESSION,
TYPE_DIVISION_EXPRESSION,
TYPE_REMINDER_EXPRESSION,
TYPE_COMPOUND_ADDITION,
TYPE_COMPOUND_SUBTRACTION,
TYPE_COMPOUND_MULTIPLICATION,
TYPE_COMPOUND_DIVISION,
TYPE_COMPOUND_REMINDER,
TYPE_PREFIXINCREMENT,
TYPE_PREFIXDECREMENT,
TYPE_ARRAY_INDEXING,
TYPE_FUNCTION_CALL,
TYPE_POSTFIXINCREMENT,
TYPE_POSTFIXDECREMENT = 61,
};
///////////////////////////////////////////////////////////////////////////////////
//
struct SNode
{
int m_iLine;
eSyntaxType m_eType;
SNode * m_ArrPtrChilds[MAXCHILD];
int m_SymbolID;
eDataType m_eReturnType;
public:
SNode( int, eSyntaxType, SNode *, SNode *, SNode * );
void Show( int, MESSAGE_FUNCTION2, CSymbolTable * );
bool SemanticCheck( CSymbolTable * );
};
class CSyntaxTree
{
protected:
SNode * m_pRoot;
CSymbolTable * m_pSymbolTable;
typedef set<void *> PTRSTORAGE;
PTRSTORAGE * m_pPtrStorage;
public:
CSyntaxTree();
~CSyntaxTree();
void Create( const char * ); //Ư<><C6AF> <20><>ũ<EFBFBD><C5A9>Ʈ ȭ<><C8AD><EFBFBD><EFBFBD> <20>о SyntaxƮ<78><C6AE><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
void Create( FILE * );
void Destroy();
int Insert( int line, eSyntaxType, int childID1 = 0, int childID2 = 0, int childID3 = 0 );
int Insert( int line, int symbolID, eSyntaxType, int childID1 = 0, int childID2 = 0, int childID3 = 0 );
void SetRoot( int nodeID );
void Show( MESSAGE_FUNCTION2 );
CSymbolTable * GetSymbolTable() { return m_pSymbolTable; }
SNode * GetRoot() { return m_pRoot; }
};
///////////////////////////////////////////////////////////////////////////////////
#endif

View File

@@ -0,0 +1,620 @@
#include "VirtualMachine.h"
#include "IntermediateCode.h"
#include "SymbolTable.h"
#include "RelocTable.h"
#include <map>
#include <string>
#include <stdarg.h>
#include <fstream>
#include <set>
typedef unsigned char byte;
static const int xor_key_value = 0x425529ac;
///////////////////////////////////////////////////////////////////////////////////
//
CVirtualMachine::ALLOCATED * pAllocatedPtrs = NULL;
void RegisterAllocatedMemory( void * p )
{
pAllocatedPtrs->insert( p );
// CompilerMessage2( "[[[Register Allocated Memory : %d]]]", int(p) );
}
void UnregisterAllocatedMemory( void * p )
{
pAllocatedPtrs->erase( p );
// CompilerMessage2( "[[[Unregister Allocated Memory : %d]]]", int(p) );
}
///////////////////////////////////////////////////////////////////////////////////
//
ScriptFunc::ScriptFunc( void * pfunc, long type )
: pFunc( pfunc ), Type( type )
{}
CVirtualMachine::CVirtualMachine()
: m_pBuffer( NULL )
, m_pGlobalVars( NULL )
, m_pStringBuffer( NULL )
, m_pCodeBuffer( NULL )
, m_iCodeSize( 0 )
, m_pFunctionMap( new FUNCMAP )
, m_pRelocation( new CRelocTable )
, m_bRelocated( false )
, m_pAllocatedPtrs( new ALLOCATED )
, m_pSysVarBuffer( new char[32] )
{
pAllocatedPtrs = m_pAllocatedPtrs;
}
CVirtualMachine::~CVirtualMachine()
{
Destroy();
delete m_pFunctionMap;
delete m_pRelocation;
delete m_pAllocatedPtrs;
delete [] m_pSysVarBuffer;
}
///////////////////////////////////////////////////////////////////////////////////
//
void Data_XOR( char * pDataBuf, unsigned size, int keyValue )
{
int * pIntData = (int*)pDataBuf;
int IntDataSize = size/sizeof(int);
for( unsigned i = 0; i < IntDataSize; i++ )
{
pIntData[i] = pIntData[i] ^ keyValue;
}
}
///////////////////////////////////////////////////////////////////////////////////
//
void File_XOR( const char * szSrcFilename, const char * szDstFilename, int keyValue )
{
fstream infile( szSrcFilename, ios_base::in | ios_base::binary );
if( !infile.is_open() )
{
ErrorMessage2( "ȭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.(At File_XOR) : %s", szSrcFilename );
}
fstream outfile( szDstFilename, ios_base::out | ios_base::binary );
if( !outfile.is_open() )
{
ErrorMessage2( "ȭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.(At File_XOR) : %s", szDstFilename );
}
infile.seekg( 0, ios_base::end );
unsigned filesize = infile.tellg();
infile.seekg( 0, ios_base::beg );
char * pDataBuf = new char[ filesize ];
infile.read( pDataBuf, filesize );
Data_XOR( pDataBuf, filesize, keyValue );
outfile.write( pDataBuf, filesize );
delete [] pDataBuf;
}
///////////////////////////////////////////////////////////////////////////////////
//
void CVirtualMachine::Create( const char * szFilename )
{
ifstream file( szFilename, ios::binary | ios::in );
if( !file.is_open() )
ErrorMessage2( "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ȭ<><C8AD><EFBFBD><EFBFBD> ã<><C3A3> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. (At CVirtualMachine::Create) : %s", szFilename );
file.seekg( 0, ios_base::end );
unsigned filesize = file.tellg();
file.seekg( 0, ios_base::beg );
char * pBuf = new char[filesize];
file.read( pBuf, filesize );
Data_XOR( pBuf, filesize, xor_key_value );
Create( pBuf, filesize );
delete [] pBuf;
file.close();
/*
Destroy();
ifstream file( szFilename, ios::binary | ios::in );
if( !file.is_open() )
ErrorMessage2( "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ȭ<><C8AD><EFBFBD><EFBFBD> ã<><C3A3> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. (At CVirtualMachine::Create) : %s", szFilename );
m_pRelocation->Create( file );
int GlobalVarBufferSize, StringBufferSize, TotalBufferSize;
file.read( (char*)&GlobalVarBufferSize, sizeof(int) );
file.read( (char*)&StringBufferSize, sizeof(int) );
file.read( (char*)&m_iCodeSize, sizeof(int) );
TotalBufferSize = GlobalVarBufferSize + StringBufferSize + m_iCodeSize;
m_pGlobalVars = m_pBuffer = new char[TotalBufferSize];
m_pStringBuffer = ((byte*)m_pGlobalVars) + GlobalVarBufferSize;
m_pCodeBuffer = ((byte*)m_pStringBuffer) + StringBufferSize;
memset( m_pGlobalVars, 0, GlobalVarBufferSize );
file.read( (char*)m_pStringBuffer, StringBufferSize );
file.read( (char*)m_pCodeBuffer, m_iCodeSize );
long FuncMapSize;
file.read( (char*)&FuncMapSize, sizeof(long) );
string str;
char endChar;
long type, offset;
for( int i = 0; i < FuncMapSize; i++ )
{
file >> str;
file.read( &endChar, 1 );
file.read( (char*)&type, sizeof(long) );
file.read( (char*)&offset, sizeof(long) );
offset += long( m_pCodeBuffer );
m_pFunctionMap->insert( FUNCMAP::value_type( str, FUNCINFO( type, (void*)offset ) ) );
}
file.read( (char*)m_pSysVarOffset, sizeof(int)*4 );
file.close();
m_pRelocation->Relocate( m_pGlobalVars, m_pStringBuffer, m_pCodeBuffer );
m_bRelocated = true;
SetSysVars();
*/
}
#define READ_INT( p, var ) { var = *((int*)p); p += sizeof(int); }
#define READ_LONG( p, var ) { var = *((long*)p); p += sizeof(long); }
#define READ_CHAR( p, var ) { var = *p; p += sizeof(char); }
const char * ReadLine( const char * szBuf, char * szOut, char endChar = '\0' )
{
const char * p = szBuf;
char * pDst = szOut;
while( *p != endChar )
{
*pDst = *p;
p++, pDst++;
}
*pDst = '\0';
return p + 1;
}
void CVirtualMachine::Create( const void * pDataBuf, unsigned DataSize )
{
Destroy();
const char * pData = (const char*)m_pRelocation->Create( pDataBuf, DataSize );
int GlobalVarBufferSize, StringBufferSize, TotalBufferSize;
READ_INT( pData, GlobalVarBufferSize );
READ_INT( pData, StringBufferSize );
READ_INT( pData, m_iCodeSize );
TotalBufferSize = GlobalVarBufferSize + StringBufferSize + m_iCodeSize;
m_pGlobalVars = m_pBuffer = new char[TotalBufferSize];
m_pStringBuffer = ((byte*)m_pGlobalVars) + GlobalVarBufferSize;
m_pCodeBuffer = ((byte*)m_pStringBuffer) + StringBufferSize;
memset( m_pGlobalVars, 0, GlobalVarBufferSize );
memcpy( m_pStringBuffer, pData, StringBufferSize );
pData += StringBufferSize;
memcpy( m_pCodeBuffer, pData, m_iCodeSize );
pData += m_iCodeSize;
long FuncMapSize;
READ_LONG( pData, FuncMapSize );
long type, offset;
for( int i = 0; i < FuncMapSize; i++ )
{
char szStr[256];
pData = ReadLine( pData, szStr, '\n' );
READ_LONG( pData, type );
READ_LONG( pData, offset );
offset += long( m_pCodeBuffer );
m_pFunctionMap->insert( FUNCMAP::value_type( szStr, FUNCINFO( type, (void*)offset ) ) );
}
memcpy( m_pSysVarOffset, pData, sizeof(int)*4 );
pData += sizeof(int)*4;
m_pRelocation->Relocate( m_pGlobalVars, m_pStringBuffer, m_pCodeBuffer );
m_bRelocated = true;
SetSysVars();
}
void CVirtualMachine::Create( CIntermediateCode & IMCode, CSymbolTable & SymbolTable )
{
Destroy();
m_iCodeSize = IMCode.Addressing( 0 );
int GlobalVarsSize = SymbolTable.GetGlobalVarSize();
int StringBufferSize = SymbolTable.GetStringBufferSize();
int BufSize = GlobalVarsSize + StringBufferSize + m_iCodeSize;
m_pGlobalVars = m_pBuffer = new char[ BufSize ];
memset( m_pGlobalVars, 0, GlobalVarsSize );
m_pStringBuffer = (char*)m_pBuffer + GlobalVarsSize;
SymbolTable.StringBuffer( m_pStringBuffer );
m_pCodeBuffer = (char*)m_pStringBuffer + StringBufferSize;
if( IMCode.ToMachineCode( m_pCodeBuffer, m_pRelocation ) != m_iCodeSize )
ScriptSystemError( "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><20>ٸ<EFBFBD><D9B8>ϴ<EFBFBD>.( at CVirtualMachine::Create )" );
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD>
m_pRelocation->Relocate( m_pGlobalVars, m_pStringBuffer, m_pCodeBuffer );
m_bRelocated = true;
//<2F>Լ<EFBFBD> <20><><EFBFBD>̺<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
typedef CIntermediateCode::FUNCTABLE FUNCTABLE;
FUNCTABLE & funcTable = IMCode.GetFuncTable();
byte * pCode = (byte*)m_pCodeBuffer;
for( FUNCTABLE::iterator i = funcTable.begin(); i != funcTable.end(); i++ )
{
const char * pFuncName = SymbolTable.GetNameOfFunc( i->first );
SFuncType FuncType = SymbolTable.GetTypeOfFunc( i->first );
void * pFunc = pCode + i->second;
m_pFunctionMap->insert( FUNCMAP::value_type( pFuncName, FUNCINFO( FuncType, pFunc ) ) );
}
m_pSysVarOffset[0] = SymbolTable.GetOffsetOfVar( SymbolTable.FindVar( SYSVAR_FLOATUNIT ) );
m_pSysVarOffset[1] = SymbolTable.GetOffsetOfVar( SymbolTable.FindVar( SYSVAR_TRUE ) );
m_pSysVarOffset[2] = SymbolTable.GetOffsetOfVar( SymbolTable.FindVar( SYSVAR_FALSE ) );
m_pSysVarOffset[3] = SymbolTable.GetOffsetOfVar( SymbolTable.FindVar( SYSVAR_CONVBUFFER ) );
SetSysVars();
}
void CVirtualMachine::SetSysVars()
{
int * pVarBuffer = (int*)m_pGlobalVars;
float floatunit = 1.0f;
pVarBuffer[ m_pSysVarOffset[0]/4 ] = *((int*)&floatunit); //0x3f800000
pVarBuffer[ m_pSysVarOffset[1]/4 ] = (int)strcpy( m_pSysVarBuffer, "true" );
pVarBuffer[ m_pSysVarOffset[2]/4 ] = (int)strcpy( m_pSysVarBuffer + 5, "false" );
pVarBuffer[ m_pSysVarOffset[3]/4 ] = int(m_pSysVarBuffer + 11);
}
void CVirtualMachine::Destroy()
{
delete [] m_pBuffer;
m_pBuffer = m_pGlobalVars = m_pStringBuffer = m_pCodeBuffer = NULL;
m_iCodeSize = 0;
m_pFunctionMap->clear();
m_pRelocation->Destroy();
for( ALLOCATED::iterator i = m_pAllocatedPtrs->begin(); i != m_pAllocatedPtrs->end(); i++ )
{
free( *i );
// CompilerMessage2( "[[[free : %d]]]", int(*i) );
}
m_pAllocatedPtrs->clear();
}
///////////////////////////////////////////////////////////////////////////////////
// ȭ<><C8AD> <20><><EFBFBD><EFBFBD>
// 1. <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> Relocation <20><><EFBFBD><EFBFBD>(int)
// 2. <20><><EFBFBD>ڿ<EFBFBD> <20><><EFBFBD><EFBFBD> Relocation <20><><EFBFBD><EFBFBD>(int)
// 3. <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> Relocation Table
// 4. <20><><EFBFBD>ڿ<EFBFBD> <20><><EFBFBD><EFBFBD> Relocation Table
// 5. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ũ<><C5A9>(int)
// 6. <20><><EFBFBD>ڿ<EFBFBD> <20><><EFBFBD><EFBFBD> ũ<><C5A9>(int)
// 7. <20>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD> ũ<><C5A9>(int)
// 8. <20><><EFBFBD>ڿ<EFBFBD> <20><><EFBFBD><EFBFBD>
// 9. <20>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD>
// 10. <20>Լ<EFBFBD><D4BC><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// 11. < <20><><EFBFBD>ڿ<EFBFBD>, <20>Լ<EFBFBD> Ÿ<><C5B8>(long), <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(long) > * <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
///////////////////////////////////////////////////////////////////////////////////
bool CVirtualMachine::Save( const char * szFilename )
{
if( m_pBuffer == NULL || m_pGlobalVars == NULL || m_pStringBuffer == NULL || m_pCodeBuffer == NULL )
return false;
ofstream file( szFilename, ios::binary | ios::out );
if( !file.is_open() )
ErrorMessage2( "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ȭ<>Ϸ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.(At CVirtualMachine::Save) : %s", szFilename );
if( m_bRelocated )
{
m_pRelocation->Unlocate( m_pGlobalVars, m_pStringBuffer, m_pCodeBuffer );
m_bRelocated = false;
}
m_pRelocation->Save( file );
int GlobalVarBufferSize = ((byte*)m_pStringBuffer) - ((byte*)m_pGlobalVars);
int StringBufferSize = ((byte*)m_pCodeBuffer) - ((byte*)m_pStringBuffer);
file.write( (const char*)&GlobalVarBufferSize, sizeof(int) );
file.write( (const char*)&StringBufferSize, sizeof(int) );
file.write( (const char*)&m_iCodeSize, sizeof(int) );
file.write( (const char*)m_pStringBuffer, StringBufferSize );
file.write( (const char*)m_pCodeBuffer, m_iCodeSize );
int FuncMapSize = m_pFunctionMap->size();
file.write( (const char*)&FuncMapSize, sizeof(int) );
for( FUNCMAP::iterator it = m_pFunctionMap->begin(); it != m_pFunctionMap->end(); it++ )
{
file << it->first << '\n';
file.write( (const char*)&it->second.first.m_data, sizeof(long) );
long offset = long( it->second.second ) - long(m_pCodeBuffer);
file.write( (const char*)&offset, sizeof(long) );
}
file.write( (const char*)m_pSysVarOffset, sizeof(int)*4 );
file.close();
m_pRelocation->Relocate( m_pGlobalVars, m_pStringBuffer, m_pCodeBuffer );
char tempFilename[256];
sprintf( tempFilename, "%s+", szFilename );
File_XOR( szFilename, tempFilename, xor_key_value );
remove( szFilename );
rename( tempFilename, szFilename );
return true;
}
void CVirtualMachine::Execute()
{
void * pCodeBuffer = m_pCodeBuffer;
__asm call pCodeBuffer;
}
SFuncType MakeFuncType( eDataType returnType, va_list args )
{
SFuncType type;
type.SetReturnType( returnType );
for( int i = 0; i < 7; i++ )
{
eDataType dataType = va_arg( args, eDataType );
if( dataType == T_VOID )
break;
type.SetArgType( i, dataType );
}
return type;
}
void * GetFuncPtr( CVirtualMachine::FUNCMAP & funcMap, const char * szFuncName, SFuncType funcType )
{
typedef CVirtualMachine::FUNCMAP::iterator iterator;
pair< iterator, iterator > result = funcMap.equal_range( szFuncName );
while( result.first != result.second )
{
SFuncType ftype = result.first->second.first;
if( ftype == funcType )
{
return result.first->second.second;
}
result.first++;
}
return NULL;
}
union long_byte
{
long longValue;
char byteValue[4];
};
///////////////////////////////////////////////////////////////////////////////////
//Native<76>Լ<EFBFBD><D4BC><EFBFBD> <20><>ũ<EFBFBD><C5A9>Ʈ<EFBFBD><C6AE> <20><><EFBFBD>ε<EFBFBD> <20>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD>
//
//<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> : <20>Լ<EFBFBD><D4BC><EFBFBD> <20><> <20><> <20><>ġ<EFBFBD><C4A1> <20>Ѵ<EFBFBD>. ( <20><><EFBFBD><EFBFBD> <20>ӵ<EFBFBD><D3B5><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. )
// 1-1. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ְ<EFBFBD>, <20><><EFBFBD>ǰ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><20>Լ<EFBFBD> <20>ڵ忡<DAB5><E5BFA1> ó<><C3B3> <20>κп<CEBA> 5<><35><EFBFBD><EFBFBD>Ʈ <20>̻<EFBFBD><CCBB><EFBFBD> <20><><EFBFBD><EFBFBD>(nop)<29><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>.
// 1-2. RegisterFunction<6F><6E> ȣ<><C8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 1-1<><31><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>κп<CEBA> call <native function><3E><> ret<65><74> <20><><EFBFBD><EFBFBD><EFBFBD>ִ´<D6B4>.
// <09>󸶳<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>? <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> nop<6F><70> 2<><32> <20>̻<EFBFBD> <20>߰<EFBFBD><DFB0>ǰ<EFBFBD>, native call<6C><6C> <20><><EFBFBD><EFBFBD> ȣ<><C8A3><EFBFBD><EFBFBD> <20>ȴ<EFBFBD>.
// Empty Function<6F><6E> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
//
//<2F>ٸ<EFBFBD> <20><><EFBFBD><EFBFBD> : <20><><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> ȣ<><C8A3><EFBFBD>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>κ<EFBFBD><CEBA><EFBFBD> <20>Լ<EFBFBD> <20>ּҸ<D6BC> <20>ٲ۴<D9B2>.( <20><><EFBFBD><EFBFBD> <20>ӵ<EFBFBD><D3B5><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. )
// 2-1. <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD> ȣ<><C8A3> <20>κ<EFBFBD><CEBA><EFBFBD> Relocation Tableó<65><C3B3> call table<6C><65> <20><><EFBFBD><EFBFBD><EFBFBD>صд<D8B5>.
// 2-2. RegisterFunction<6F><6E> ȣ<><C8A3><EFBFBD>Ǿ<EFBFBD><C7BE><EFBFBD> <20><> call table<6C><65> <20><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD> call<6C>ϰ<EFBFBD> <20>ִ<EFBFBD> <20>κ<EFBFBD><CEBA><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ٲ۴<D9B2>.
// call table<6C><65>? map< string, pair< SFuncType, vector<int> > >
///////////////////////////////////////////////////////////////////////////////////
void CVirtualMachine::RegisterFunction( ANY_FUNCTION FuncPtr, eDataType returnType, const char * szFuncName, ... )
{
va_list args;
va_start( args, szFuncName );
RegisterFunction( FuncPtr, returnType, szFuncName, args );
}
void CVirtualMachine::RegisterFunction( ANY_FUNCTION FuncPtr, eDataType returnType, const char * szFuncName, va_list args )
{
SFuncType funcType = MakeFuncType( returnType, args );
byte * pFunc = (byte*)GetFuncPtr( *m_pFunctionMap, szFuncName, funcType );
if( pFunc == NULL )
ErrorMessage2( "<EFBFBD>Լ<EFBFBD> <20><><EFBFBD>Ͽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>߽<EFBFBD><DFBD>ϴ<EFBFBD>. <20>Լ<EFBFBD><D4BC><EFBFBD> ã<><C3A3> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. : %s", funcType.ToString( szFuncName ) );
if( pFunc[3] != 0x90 ) //nop<6F><70> <20>ƴ<EFBFBD> <20><>
ScriptSystemError( "RegisterFunction Error!!( at CVirtualMachine::RegisterFunction )" );
int nArg = funcType.GetArgCount();
pFunc += 3;
for( int i = 0; i < nArg; i++ )
{
*(pFunc++) = 0xff;
*(pFunc++) = 0x75;
*(pFunc++) = 0xff & (8+4*i);
}
*(pFunc++) = 0xe8;
long_byte FuncOffset;
FuncOffset.longValue = long(FuncPtr) - long(pFunc+4);
*(pFunc++) = FuncOffset.byteValue[0];
*(pFunc++) = FuncOffset.byteValue[1];
*(pFunc++) = FuncOffset.byteValue[2];
*(pFunc++) = FuncOffset.byteValue[3];
}
ScriptFunc CVirtualMachine::GetScriptFunction( eDataType returnType, const char * szFuncName, ... )
{
va_list args;
va_start( args, szFuncName );
return GetScriptFunction( returnType, szFuncName, args );
}
ScriptFunc CVirtualMachine::GetScriptFunction( eDataType returnType, const char * szFuncName, va_list args )
{
SFuncType funcType = MakeFuncType( returnType, args );
void * pFunc = GetFuncPtr( *m_pFunctionMap, szFuncName, funcType );
if( pFunc == NULL )
ErrorMessage2( "<EFBFBD><EFBFBD>ũ<EFBFBD><EFBFBD>Ʈ <20>Լ<EFBFBD><D4BC><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>߽<EFBFBD><DFBD>ϴ<EFBFBD>. <20>Լ<EFBFBD><D4BC><EFBFBD> ã<><C3A3> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. : %s", funcType.ToString( szFuncName ) );
return ScriptFunc( pFunc, funcType.m_data );
}
void * CVirtualMachine::CallScriptFunction( ScriptFunc Func )
{
__asm call Func.pFunc;
}
void * CVirtualMachine::CallScriptFunction( ScriptFunc Func, AnyData arg1 )
{
__asm
{
push arg1;
call Func.pFunc;
add esp, 4;
}
}
void * CVirtualMachine::CallScriptFunction( ScriptFunc Func, AnyData arg1, AnyData arg2 )
{
__asm
{
push arg2;
push arg1;
call Func.pFunc;
add esp, 8;
}
}
void * CVirtualMachine::CallScriptFunction( ScriptFunc Func, AnyData arg1, AnyData arg2, AnyData arg3 )
{
__asm
{
push arg3;
push arg2;
push arg1;
call Func.pFunc;
add esp, 12;
}
}
void * CVirtualMachine::CallScriptFunction( ScriptFunc Func, AnyData arg1, AnyData arg2, AnyData arg3, AnyData arg4 )
{
__asm
{
push arg4;
push arg3;
push arg2;
push arg1;
call Func.pFunc;
add esp, 16;
}
}
void * CVirtualMachine::CallScriptFunction( ScriptFunc Func, AnyData args[], int nArgs )
{
for( int i = nArgs - 1; i >= 0; i-- )
__asm push args[i];
__asm call Func.pFunc;
nArgs *= 4;
__asm add esp, nArgs;
}
/*
int CVirtualMachine::CallScriptFunction( ScriptFunc Func, va_list args )
{
int nArgs = SFuncType( Func.Type ).GetArgCount();
for( int i = 0; i < nArgs; i++ )
{
AnyData data = va_arg( args, AnyData );
__asm push data;
}
void * pFunc = Func.pFunc;
int n = nArgs * 4;
__asm
{
call pFunc;
add esp, n;
}
}
int CVirtualMachine::CallScriptFunction( ScriptFunc Func, ... )
{
va_list args;
va_start( args, Func );
return CallScriptFunction( Func, args );
}
*/

View File

@@ -0,0 +1,77 @@
#ifndef _VirtualMachine_H_
#define _VirtualMachine_H_
#include "STL.h"
#include "BaseDef.h"
class CIntermediateCode;
class CSymbolTable;
struct SFuncType;
class CRelocTable;
typedef char * va_list;
///////////////////////////////////////////////////////////////////////////////////
//
void RegisterAllocatedMemory( void * );
void UnregisterAllocatedMemory( void * );
///////////////////////////////////////////////////////////////////////////////////
//
class CVirtualMachine
{
public:
typedef pair<SFuncType, void*> FUNCINFO;
typedef multimap<string, FUNCINFO> FUNCMAP;
typedef set<void*> ALLOCATED;
protected:
void * m_pBuffer;
void * m_pGlobalVars; //<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
void * m_pStringBuffer; //m_pBuffer<65><72><EFBFBD><EFBFBD> Const<73><74><EFBFBD>۰<EFBFBD> <20><><EFBFBD>۵Ǵ<DBB5> <20><><EFBFBD><EFBFBD>
void * m_pCodeBuffer; //m_pBuffer<65><72><EFBFBD><EFBFBD> Code<64><65><EFBFBD>۰<EFBFBD> <20><><EFBFBD>۵Ǵ<DBB5> <20><><EFBFBD><EFBFBD>
int m_iCodeSize;
FUNCMAP * m_pFunctionMap; //Ŀ<><C4BF><EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> <20≯<EFBFBD>, <20><><EFBFBD>ڿ<EFBFBD> <20>Լ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>̺<EFBFBD>
CRelocTable * m_pRelocation; //Relocation Table
int m_pSysVarOffset[4]; //<2F>ý<EFBFBD><C3BD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
char * m_pSysVarBuffer;
bool m_bRelocated;
ALLOCATED * m_pAllocatedPtrs;
protected:
void SetSysVars();
public:
CVirtualMachine();
~CVirtualMachine();
void Create( const char * szFilename );
void Create( const void * pDataBuf, unsigned DataSize ); //<2F>޸<EFBFBD><DEB8><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD> <20><><EFBFBD><EFBFBD>
void Create( CIntermediateCode &, CSymbolTable & );
void Destroy();
bool Save( const char * szFilename );
void Execute();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> T_VOID<49><44> <20><> <20>־<EFBFBD><D6BE>־<EFBFBD><D6BE><EFBFBD> <20><>!!!
void RegisterFunction( ANY_FUNCTION, eDataType returnType, const char *, ... );
void RegisterFunction( ANY_FUNCTION, eDataType, const char *, va_list );
ScriptFunc GetScriptFunction( eDataType returnType, const char *, ... );
ScriptFunc GetScriptFunction( eDataType, const char *, va_list );
void * CallScriptFunction( ScriptFunc );
void * CallScriptFunction( ScriptFunc, AnyData );
void * CallScriptFunction( ScriptFunc, AnyData, AnyData );
void * CallScriptFunction( ScriptFunc, AnyData, AnyData, AnyData );
void * CallScriptFunction( ScriptFunc, AnyData, AnyData, AnyData, AnyData );
void * CallScriptFunction( ScriptFunc, AnyData args[], int nArgs );
// int CallScriptFunction( ScriptFunc, va_list );
// int CallScriptFunction( ScriptFunc, ... );
};
///////////////////////////////////////////////////////////////////////////////////
#endif

Binary file not shown.

View File

@@ -0,0 +1,668 @@
extern int timeclock;
int yyerror; /* Yyerror and yycost are set by guards. */
int yycost; /* If yyerror is set to a nonzero value by a */
/* guard, the reduction with which the guard */
/* is associated is not performed, and the */
/* error recovery mechanism is invoked. */
/* Yycost indicates the cost of performing */
/* the reduction given the attributes of the */
/* symbols. */
/* YYMAXDEPTH indicates the size of the parser's state and value */
/* stacks. */
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 500
#endif
/* YYMAXRULES must be at least as large as the number of rules that */
/* could be placed in the rule queue. That number could be determined */
/* from the grammar and the size of the stack, but, as yet, it is not. */
#ifndef YYMAXRULES
#define YYMAXRULES 100
#endif
#ifndef YYMAXBACKUP
#define YYMAXBACKUP 100
#endif
short yyss[YYMAXDEPTH]; /* the state stack */
YYSTYPE yyvs[YYMAXDEPTH]; /* the semantic value stack */
YYLTYPE yyls[YYMAXDEPTH]; /* the location stack */
short yyrq[YYMAXRULES]; /* the rule queue */
int yychar; /* the lookahead symbol */
YYSTYPE yylval; /* the semantic value of the */
/* lookahead symbol */
YYSTYPE yytval; /* the semantic value for the state */
/* at the top of the state stack. */
YYSTYPE yyval; /* the variable used to return */
/* semantic values from the action */
/* routines */
YYLTYPE yylloc; /* location data for the lookahead */
/* symbol */
YYLTYPE yytloc; /* location data for the state at the */
/* top of the state stack */
int yynunlexed;
short yyunchar[YYMAXBACKUP];
YYSTYPE yyunval[YYMAXBACKUP];
YYLTYPE yyunloc[YYMAXBACKUP];
short *yygssp; /* a pointer to the top of the state */
/* stack; only set during error */
/* recovery. */
YYSTYPE *yygvsp; /* a pointer to the top of the value */
/* stack; only set during error */
/* recovery. */
YYLTYPE *yyglsp; /* a pointer to the top of the */
/* location stack; only set during */
/* error recovery. */
/* Yyget is an interface between the parser and the lexical analyzer. */
/* It is costly to provide such an interface, but it avoids requiring */
/* the lexical analyzer to be able to back up the scan. */
yyget()
{
if (yynunlexed > 0)
{
yynunlexed--;
yychar = yyunchar[yynunlexed];
yylval = yyunval[yynunlexed];
yylloc = yyunloc[yynunlexed];
}
else if (yychar <= 0)
yychar = 0;
else
{
yychar = yylex();
if (yychar < 0)
yychar = 0;
else yychar = YYTRANSLATE(yychar);
}
}
yyunlex(chr, val, loc)
int chr;
YYSTYPE val;
YYLTYPE loc;
{
yyunchar[yynunlexed] = chr;
yyunval[yynunlexed] = val;
yyunloc[yynunlexed] = loc;
yynunlexed++;
}
yyrestore(first, last)
register short *first;
register short *last;
{
register short *ssp;
register short *rp;
register int symbol;
register int state;
register int tvalsaved;
ssp = yygssp;
yyunlex(yychar, yylval, yylloc);
tvalsaved = 0;
while (first != last)
{
symbol = yystos[*ssp];
if (symbol < YYNTBASE)
{
yyunlex(symbol, yytval, yytloc);
tvalsaved = 1;
ssp--;
}
ssp--;
if (first == yyrq)
first = yyrq + YYMAXRULES;
first--;
for (rp = yyrhs + yyprhs[*first]; symbol = *rp; rp++)
{
if (symbol < YYNTBASE)
state = yytable[yypact[*ssp] + symbol];
else
{
state = yypgoto[symbol - YYNTBASE] + *ssp;
if (state >= 0 && state <= YYLAST && yycheck[state] == *ssp)
state = yytable[state];
else
state = yydefgoto[symbol - YYNTBASE];
}
*++ssp = state;
}
}
if ( ! tvalsaved && ssp > yyss)
{
yyunlex(yystos[*ssp], yytval, yytloc);
ssp--;
}
yygssp = ssp;
}
int
yyparse()
{
register int yystate;
register int yyn;
register short *yyssp;
register short *yyrq0;
register short *yyptr;
register YYSTYPE *yyvsp;
int yylen;
YYLTYPE *yylsp;
short *yyrq1;
short *yyrq2;
yystate = 0;
yyssp = yyss - 1;
yyvsp = yyvs - 1;
yylsp = yyls - 1;
yyrq0 = yyrq;
yyrq1 = yyrq0;
yyrq2 = yyrq0;
yychar = yylex();
if (yychar < 0)
yychar = 0;
else yychar = YYTRANSLATE(yychar);
yynewstate:
if (yyssp >= yyss + YYMAXDEPTH - 1)
{
yyabort("Parser Stack Overflow");
YYABORT;
}
*++yyssp = yystate;
yyresume:
yyn = yypact[yystate];
if (yyn == YYFLAG)
goto yydefault;
yyn += yychar;
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar)
goto yydefault;
yyn = yytable[yyn];
if (yyn < 0)
{
yyn = -yyn;
goto yyreduce;
}
else if (yyn == 0)
goto yyerrlab;
yystate = yyn;
yyptr = yyrq2;
while (yyptr != yyrq1)
{
yyn = *yyptr++;
yylen = yyr2[yyn];
yyvsp -= yylen;
yylsp -= yylen;
yyguard(yyn, yyvsp, yylsp);
if (yyerror)
goto yysemerr;
yyaction(yyn, yyvsp, yylsp);
*++yyvsp = yyval;
yylsp++;
if (yylen == 0)
{
yylsp->timestamp = timeclock;
yylsp->first_line = yytloc.first_line;
yylsp->first_column = yytloc.first_column;
yylsp->last_line = (yylsp-1)->last_line;
yylsp->last_column = (yylsp-1)->last_column;
yylsp->text = 0;
}
else
{
yylsp->last_line = (yylsp+yylen-1)->last_line;
yylsp->last_column = (yylsp+yylen-1)->last_column;
}
if (yyptr == yyrq + YYMAXRULES)
yyptr = yyrq;
}
if (yystate == YYFINAL)
YYACCEPT;
yyrq2 = yyptr;
yyrq1 = yyrq0;
*++yyvsp = yytval;
*++yylsp = yytloc;
yytval = yylval;
yytloc = yylloc;
yyget();
goto yynewstate;
yydefault:
yyn = yydefact[yystate];
if (yyn == 0)
goto yyerrlab;
yyreduce:
*yyrq0++ = yyn;
if (yyrq0 == yyrq + YYMAXRULES)
yyrq0 = yyrq;
if (yyrq0 == yyrq2)
{
yyabort("Parser Rule Queue Overflow");
YYABORT;
}
yyssp -= yyr2[yyn];
yyn = yyr1[yyn];
yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
yystate = yytable[yystate];
else
yystate = yydefgoto[yyn - YYNTBASE];
goto yynewstate;
yysemerr:
*--yyptr = yyn;
yyrq2 = yyptr;
yyvsp += yyr2[yyn];
yyerrlab:
yygssp = yyssp;
yygvsp = yyvsp;
yyglsp = yylsp;
yyrestore(yyrq0, yyrq2);
yyrecover();
yystate = *yygssp;
yyssp = yygssp;
yyvsp = yygvsp;
yyrq0 = yyrq;
yyrq1 = yyrq0;
yyrq2 = yyrq0;
goto yyresume;
}
$

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,167 @@
// lex.h: lexer defines & declarations
#ifndef _LEX_H_
#define _LEX_H_
#include <stdio.h>
#ifdef _LEX_CPP_
int lineno = 1; // line number count; this will be used for error messages later
#else
// Import some variables
extern int lineno;
extern FILE *yyin; // the input stream
// Function prototype
int yylex ();
#endif
int yyparse ();
#ifndef YYLTYPE
typedef
struct yyltype
{
int timestamp;
int first_line;
int first_column;
int last_line;
int last_column;
char *text;
}
yyltype;
#define YYLTYPE yyltype
#endif
extern YYLTYPE yylloc;
/*
enum {
TOKEN_BEGIN = 258,
TOKEN_INCLUDE,
TOKEN_DEFINE,
TOKEN_INTEGERVALUE,
TOKEN_FLOATVALUE,
TOKEN_BOOLVALUE,
TOKEN_STRINGVALUE,
TOKEN_VOID,
TOKEN_INT,
TOKEN_FLOAT,
TOKEN_BOOL,
TOKEN_STRING,
TOKEN_FOR,
TOKEN_WHILE,
TOKEN_IF,
TOKEN_ELSE,
TOKEN_SWITCH,
TOKEN_CASE,
TOKEN_DEFAULT,
TOKEN_CONTINUE,
TOKEN_BREAK,
TOKEN_RETURN,
TOKEN_ID,
TOKEN_ADDITION,
TOKEN_SUBTRACTION,
TOKEN_MULTIPLICATION,
TOKEN_DIVISION,
TOKEN_REMINDER,
TOKEN_ASSIGNMENT,
TOKEN_COMPOUNDADDITION,
TOKEN_COMPOUNDSUBTRACTION,
TOKEN_COMPOUNDMULTIPLICATION,
TOKEN_COMPOUNDDIVISION,
TOKEN_COMPOUNDREMINDER,
TOKEN_INCREMENT,
TOKEN_DECREMENT,
TOKEN_NOT,
TOKEN_LESSTHAN,
TOKEN_LESSTHANOREQUAL,
TOKEN_MORETHAN,
TOKEN_MORETHANOREQUAL,
TOKEN_EQUALITY,
TOKEN_NOTEQUAL,
TOKEN_AND,
TOKEN_OR,
TOKEN_ENDSTATEMENT,
TOKEN_LEFTPARENTHESIS,
TOKEN_RIGHTPARENTHESIS,
TOKEN_LEFTBRACE,
TOKEN_RIGHTBRACE,
TOKEN_LEFTBRACKET,
TOKEN_RIGHTBRACKET,
TOKEN_COMMA,
TOKEN_COLON,
TOKEN_ERROR,
TOKEN_END
};
*/
#define TOKEN_ID 258
#define TOKEN_INTEGERVALUE 259
#define TOKEN_FLOATVALUE 260
#define TOKEN_BOOLVALUE 261
#define TOKEN_STRINGVALUE 262
#define TOKEN_INT 263
#define TOKEN_FLOAT 264
#define TOKEN_BOOL 265
#define TOKEN_STRING 266
#define TOKEN_VOID 267
#define TOKEN_FOR 268
#define TOKEN_WHILE 269
#define TOKEN_IF 270
#define TOKEN_ELSE 271
#define TOKEN_SWITCH 272
#define TOKEN_CASE 273
#define TOKEN_DEFAULT 274
#define TOKEN_CONTINUE 275
#define TOKEN_BREAK 276
#define TOKEN_RETURN 277
#define TOKEN_ENDSTATEMENT 278
#define TOKEN_LEFTPARENTHESIS 279
#define TOKEN_RIGHTPARENTHESIS 280
#define TOKEN_LEFTBRACE 281
#define TOKEN_RIGHTBRACE 282
#define TOKEN_LEFTBRACKET 283
#define TOKEN_RIGHTBRACKET 284
#define TOKEN_ERROR 285
#define TOKEN_COMMA 286
#define TOKEN_COLON 287
#define TOKEN_ASSIGNMENT 288
#define TOKEN_COMPOUNDADDITION 289
#define TOKEN_COMPOUNDSUBTRACTION 290
#define TOKEN_COMPOUNDMULTIPLICATION 291
#define TOKEN_COMPOUNDDIVISION 292
#define TOKEN_COMPOUNDREMINDER 293
#define TOKEN_AND 294
#define TOKEN_OR 295
#define TOKEN_LESSTHAN 296
#define TOKEN_LESSTHANOREQUAL 297
#define TOKEN_MORETHAN 298
#define TOKEN_MORETHANOREQUAL 299
#define TOKEN_EQUALITY 300
#define TOKEN_NOTEQUAL 301
#define TOKEN_ADDITION 302
#define TOKEN_SUBTRACTION 303
#define TOKEN_MULTIPLICATION 304
#define TOKEN_DIVISION 305
#define TOKEN_REMINDER 306
#define TOKEN_NOT 307
#define PREFIXINCREMENT 308
#define PREFIXDECREMENT 309
#define TOKEN_INCREMENT 310
#define TOKEN_DECREMENT 311
#define TOKEN_INCLUDE 312
#define TOKEN_DEFINE 313
#endif

View File

@@ -0,0 +1,80 @@
typedef union {
int symbolID; // entry from symbol table
int nodeID; // node in the syntax tree
char szIdentifier[1024];
char szConstant[1024];
} YYSTYPE;
#ifndef YYLTYPE
typedef
struct yyltype
{
int timestamp;
int first_line;
int first_column;
int last_line;
int last_column;
char *text;
}
yyltype;
#define YYLTYPE yyltype
#endif
#define TOKEN_ID 258
#define TOKEN_INTEGERVALUE 259
#define TOKEN_FLOATVALUE 260
#define TOKEN_BOOLVALUE 261
#define TOKEN_STRINGVALUE 262
#define TOKEN_INT 263
#define TOKEN_FLOAT 264
#define TOKEN_BOOL 265
#define TOKEN_STRING 266
#define TOKEN_VOID 267
#define TOKEN_FOR 268
#define TOKEN_WHILE 269
#define TOKEN_IF 270
#define TOKEN_ELSE 271
#define TOKEN_SWITCH 272
#define TOKEN_CASE 273
#define TOKEN_DEFAULT 274
#define TOKEN_CONTINUE 275
#define TOKEN_BREAK 276
#define TOKEN_RETURN 277
#define TOKEN_ENDSTATEMENT 278
#define TOKEN_LEFTPARENTHESIS 279
#define TOKEN_RIGHTPARENTHESIS 280
#define TOKEN_LEFTBRACE 281
#define TOKEN_RIGHTBRACE 282
#define TOKEN_LEFTBRACKET 283
#define TOKEN_RIGHTBRACKET 284
#define TOKEN_ERROR 285
#define TOKEN_COMMA 286
#define TOKEN_COLON 287
#define TOKEN_ASSIGNMENT 288
#define TOKEN_COMPOUNDADDITION 289
#define TOKEN_COMPOUNDSUBTRACTION 290
#define TOKEN_COMPOUNDMULTIPLICATION 291
#define TOKEN_COMPOUNDDIVISION 292
#define TOKEN_COMPOUNDREMINDER 293
#define TOKEN_AND 294
#define TOKEN_OR 295
#define TOKEN_LESSTHAN 296
#define TOKEN_LESSTHANOREQUAL 297
#define TOKEN_MORETHAN 298
#define TOKEN_MORETHANOREQUAL 299
#define TOKEN_EQUALITY 300
#define TOKEN_NOTEQUAL 301
#define TOKEN_ADDITION 302
#define TOKEN_SUBTRACTION 303
#define TOKEN_MULTIPLICATION 304
#define TOKEN_DIVISION 305
#define TOKEN_REMINDER 306
#define TOKEN_NOT 307
#define PREFIXINCREMENT 308
#define PREFIXDECREMENT 309
#define TOKEN_INCREMENT 310
#define TOKEN_DECREMENT 311
extern YYSTYPE yylval;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,186 @@
%{
/* ------------------------------------------------------------------
Initial code (copied verbatim to the output file)
------------------------------------------------------------------ */
#include <io.h> // isatty
#define _LEX_CPP_ // make sure our variables get created
#include "lex.h"
#include "lexsymb.h"
#include "SymbolTable.h"
#include <string.h>
#ifdef MSVC
#define isatty _isatty // for some reason isatty is called _isatty in VC..
#endif
extern "C" int yywrap (); // the yywrap function is declared by the caller
void EatCComment();
void EatCppComment();
extern CSymbolTable * g_pSymbolTable;
%}
/* ------------------------------------------------------------------
Some macros (standard regular expressions)
------------------------------------------------------------------ */
LETTER [a-zA-Z_]
DIGIT [0-9]
HEXLETTER [a-fA-F0-9]
HEXVALUE 0[xX]{HEXLETTER}+
INTEGERVALUE {DIGIT}+
FLOATVALUE {DIGIT}+[.]{DIGIT}+
BOOLVALUE true|false
STRINGVALUE \"[^\"]*\"
ID {LETTER}({LETTER}|{DIGIT})*
WSPACE [ \t]+
INCLUDE "#include"{WSPACE}*{STRINGVALUE}
DEFINEoptPARAM {WSPACE}*","{WSPACE}*{ID}
DEFINEopt {WSPACE}*"("{WSPACE}*{ID}{DEFINEoptPARAM}*{WSPACE}*")"
DEFINEtokenstring {WSPACE}+{ID}
DEFINE "#define"{WSPACE}+{ID}{DEFINEopt}?{DEFINEtokenstring}?
/* ------------------------------------------------------------------
The lexer rules
------------------------------------------------------------------ */
%%
{INCLUDE} { return TOKEN_INCLUDE; }
{DEFINE} { return TOKEN_DEFINE; }
{HEXVALUE} { strcpy( yylval.szConstant, yytext );
return TOKEN_INTEGERVALUE; }
{INTEGERVALUE} { strcpy( yylval.szConstant, yytext );
return TOKEN_INTEGERVALUE; }
{FLOATVALUE} { strcpy( yylval.szConstant, yytext );
return TOKEN_FLOATVALUE; }
{BOOLVALUE} { strcpy( yylval.szConstant, yytext );
return TOKEN_BOOLVALUE; }
{STRINGVALUE} { strcpy( yylval.szConstant, yytext + 1 );
yylval.szConstant[ strlen( yylval.szConstant ) - 1 ] = '\0';
return TOKEN_STRINGVALUE; }
"void" { return TOKEN_VOID; }
"int" { return TOKEN_INT; }
"float" { return TOKEN_FLOAT; }
"bool" { return TOKEN_BOOL; }
"string" { return TOKEN_STRING; }
"for" { return TOKEN_FOR; }
"while" { return TOKEN_WHILE; }
"break" { return TOKEN_BREAK; }
"if" { return TOKEN_IF; }
"else" { return TOKEN_ELSE; }
"switch" { return TOKEN_SWITCH; }
"case" { return TOKEN_CASE; }
"default" { return TOKEN_DEFAULT; }
"continue" { return TOKEN_CONTINUE; }
"return" { return TOKEN_RETURN; }
{ID} { strcpy( yylval.szIdentifier, yytext );
return TOKEN_ID; }
"+" { return TOKEN_ADDITION; }
"-" { return TOKEN_SUBTRACTION; }
"*" { return TOKEN_MULTIPLICATION; }
"/" { return TOKEN_DIVISION; }
"%" { return TOKEN_REMINDER; }
"=" { return TOKEN_ASSIGNMENT; }
"+=" { return TOKEN_COMPOUNDADDITION; }
"-=" { return TOKEN_COMPOUNDSUBTRACTION; }
"*=" { return TOKEN_COMPOUNDMULTIPLICATION; }
"/=" { return TOKEN_COMPOUNDDIVISION; }
"%=" { return TOKEN_COMPOUNDREMINDER; }
"!" { return TOKEN_NOT; }
"<" { return TOKEN_LESSTHAN; }
"<=" { return TOKEN_LESSTHANOREQUAL; }
">" { return TOKEN_MORETHAN; }
">=" { return TOKEN_MORETHANOREQUAL; }
"==" { return TOKEN_EQUALITY; }
"!=" { return TOKEN_NOTEQUAL; }
"++" { return TOKEN_INCREMENT; }
"--" { return TOKEN_DECREMENT; }
";" { return TOKEN_ENDSTATEMENT; }
"(" { return TOKEN_LEFTPARENTHESIS; }
")" { return TOKEN_RIGHTPARENTHESIS; }
"[" { return TOKEN_LEFTBRACE; }
"]" { return TOKEN_RIGHTBRACE; }
"{" { return TOKEN_LEFTBRACKET; }
"}" { return TOKEN_RIGHTBRACKET; }
"," { return TOKEN_COMMA; }
":" { return TOKEN_COLON; }
"||" { return TOKEN_OR; }
"&&" { return TOKEN_AND; }
"//" { EatCppComment(); }
"/*" { EatCComment(); }
\n { yylloc.first_line = ++lineno; }
{WSPACE} {} //<2F><><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD><D8B9><EFBFBD>
. { return TOKEN_ERROR; } //<2F><> <20><><EFBFBD><EFBFBD> <20>͵<EFBFBD><CDB5><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>!
%%
/* ------------------------------------------------------------------
Additional code (again copied verbatim to the output file)
------------------------------------------------------------------ */
void EatCppComment()
{
char c;
while( (c = yyinput()) != '\n' && c != 0 );
yylloc.first_line = ++lineno;
}
void EatCComment()
{
char c, c0 = ' ';
while( true )
{
c = yyinput();
if( c0 == '*' && c == '/' )
break;
if( c == '\n' )
yylloc.first_line = ++lineno;
c0 = c;
}
}

View File

@@ -0,0 +1,588 @@
%{
/* ------------------------------------------------------------------
Initial code (copied verbatim to the output file)
------------------------------------------------------------------ */
#include <malloc.h> // _alloca is used by the parser
#include <string.h> // strcpy
#include <assert.h>
#include <stdlib.h>
#include "lex.h" // the lexer
#include "SyntaxTree.h"
#include "SymbolTable.h"
#include "BaseDef.h"
#include "Message.h"
// Some yacc (bison) defines
#define YYDEBUG 1 // Generate debug code; needed for YYERROR_VERBOSE
#define YYERROR_VERBOSE // Give a more specific parse error message
// Forward references
void yyerror (char *msg);
extern CSyntaxTree * g_pSynTree;
extern CSymbolTable * g_pSymbolTable;
SFuncType GetFunctionType( int nodeID );
SFuncType GetFunctionType( int nodeID1, int nodeID2 );
SFuncType GetFuncCallType( int nodeID );
int CountArrayElements( int nodeID );
int GetConstantValue( int nodeID );
%}
/* ------------------------------------------------------------------
Yacc declarations
------------------------------------------------------------------ */
%union {
int symbolID; // entry from symbol table
int nodeID; // node in the syntax tree
char szIdentifier[1024];
char szConstant[1024];
}
%type <symbolID> variable new_variable
%type <nodeID> program statement_list statement compound_statement expression_statement selection_statement
%type <nodeID> cases case_one default iteration_statement for_expression for_init_statement optional_expression
%type <nodeID> jump_statement declaration decl_specifiers declarator_list init_declarator
%type <nodeID> array_initializer initializer_list argument_declaration_list argument_declaration function_definition
%type <nodeID> constant_expression expression assignment_expression logical_or_expression logical_and_expression
%type <nodeID> equality_expression relational_expression additive_expression multiplicative_expression unary_expression
%type <nodeID> postfix_expression primary_expression
%type <szIdentifier> function_name
%type <nodeID> function_decl_end
%token <szIdentifier> TOKEN_ID
%token <szConstant> TOKEN_INTEGERVALUE TOKEN_FLOATVALUE TOKEN_BOOLVALUE TOKEN_STRINGVALUE
%token TOKEN_INT TOKEN_FLOAT TOKEN_BOOL TOKEN_STRING TOKEN_VOID
%token TOKEN_FOR TOKEN_WHILE TOKEN_IF TOKEN_ELSE TOKEN_SWITCH TOKEN_CASE
%token TOKEN_DEFAULT TOKEN_CONTINUE TOKEN_BREAK TOKEN_RETURN
%token TOKEN_ENDSTATEMENT TOKEN_LEFTPARENTHESIS TOKEN_RIGHTPARENTHESIS
%token TOKEN_LEFTBRACE TOKEN_RIGHTBRACE TOKEN_LEFTBRACKET TOKEN_RIGHTBRACKET
%token TOKEN_ERROR
/*<2A>ؿ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><EFBFBD><ECBCB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.*/
%left TOKEN_COMMA TOKEN_COLON
%right TOKEN_ASSIGNMENT TOKEN_COMPOUNDADDITION TOKEN_COMPOUNDSUBTRACTION TOKEN_COMPOUNDMULTIPLICATION TOKEN_COMPOUNDDIVISION TOKEN_COMPOUNDREMINDER
%left TOKEN_AND TOKEN_OR
%left TOKEN_LESSTHAN TOKEN_LESSTHANOREQUAL TOKEN_MORETHAN TOKEN_MORETHANOREQUAL TOKEN_EQUALITY TOKEN_NOTEQUAL
%left TOKEN_ADDITION TOKEN_SUBTRACTION
%right TOKEN_MULTIPLICATION TOKEN_DIVISION TOKEN_REMINDER
%right TOKEN_NOT
%left PREFIXINCREMENT PREFIXDECREMENT /*Context-Dependent Precedence(<28><>¥ <20>ɺ<EFBFBD>)*/
%left TOKEN_INCREMENT TOKEN_DECREMENT
%right TOKEN_LEFTPARENTHESIS
%left TOKEN_RIGHTPARENTHESIS
%expect 1 /* shift/reduce conflict: dangling ELSE */
/* declaration */
%%
/* ------------------------------------------------------------------
Yacc grammar rules
------------------------------------------------------------------ */
program
: statement_list { assert( g_pSynTree != NULL );
g_pSynTree->SetRoot( $1 ); }
;
statement_list
: statement_list statement { $$ = g_pSynTree->Insert( @1.first_line, TYPE_STATEMENT_LIST, $1, $2 ); }
| /* empty */ { $$ = g_pSynTree->Insert( @1.first_line, TYPE_EMPTY_STATEMENT ); }
;
statement
: compound_statement { $$ = $1; }
| expression_statement { $$ = $1; }
| selection_statement { $$ = $1; }
| iteration_statement { $$ = $1; }
| jump_statement { $$ = $1; }
| error TOKEN_ENDSTATEMENT { $$ = g_pSynTree->Insert( @1.first_line, TYPE_ERROR_STATEMENT ); }
| declaration { $$ = $1; }
| function_definition { $$ = $1; }
;
compound_statement
: TOKEN_LEFTBRACKET statement_list TOKEN_RIGHTBRACKET
{ $$ = $2; }
;
expression_statement
: TOKEN_ENDSTATEMENT { $$ = g_pSynTree->Insert( @1.first_line, TYPE_EMPTY_STATEMENT ); }
| expression TOKEN_ENDSTATEMENT { $$ = g_pSynTree->Insert( @1.first_line, TYPE_EXPRESSION, $1 ); }
;
selection_statement
: TOKEN_IF TOKEN_LEFTPARENTHESIS expression TOKEN_RIGHTPARENTHESIS statement
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_IF_STATEMENT, $3, $5 ); }
| TOKEN_IF TOKEN_LEFTPARENTHESIS expression TOKEN_RIGHTPARENTHESIS statement TOKEN_ELSE statement
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_IF_ELSE_STATEMENT, $3, $5, $7 ); }
| TOKEN_SWITCH TOKEN_LEFTPARENTHESIS expression TOKEN_RIGHTPARENTHESIS
TOKEN_LEFTBRACKET cases default TOKEN_RIGHTBRACKET
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_SWITCH_STATEMENT, $3, $6, $7 ); }
;
cases
: case_one cases { $$ = g_pSynTree->Insert( @1.first_line, TYPE_SWITCH_CASES, $1, $2 ); }
| case_one { $$ = $1; }
;
case_one
: TOKEN_CASE constant_expression TOKEN_COLON statement_list
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_CASE_ONE, $2, $4 ); }
;
default
: TOKEN_DEFAULT TOKEN_COLON statement_list { $$ = g_pSynTree->Insert( @1.first_line, TYPE_DEFAULT, $3 ); }
| { $$ = 0; }
;
iteration_statement
: TOKEN_FOR TOKEN_LEFTPARENTHESIS for_expression TOKEN_RIGHTPARENTHESIS statement
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_FOR_STATEMENT, $3, $5 ); }
| TOKEN_WHILE TOKEN_LEFTPARENTHESIS expression TOKEN_RIGHTPARENTHESIS statement
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_WHILE_STATEMENT, $3, $5 ); }
;
for_expression
: for_init_statement optional_expression TOKEN_ENDSTATEMENT optional_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_FOR_EXPRESSION, $1, $2, $4 ); }
;
for_init_statement
: expression_statement { $$ = $1; }
| declaration { $$ = $1; }
;
optional_expression
: expression { $$ = $1; }
| { $$ = 0; }
;
jump_statement
: TOKEN_BREAK TOKEN_ENDSTATEMENT { $$ = g_pSynTree->Insert( @1.first_line, TYPE_BREAK_STATEMENT ); }
| TOKEN_CONTINUE TOKEN_ENDSTATEMENT { $$ = g_pSynTree->Insert( @1.first_line, TYPE_CONTINUE_STATEMENT ); }
| TOKEN_RETURN optional_expression TOKEN_ENDSTATEMENT
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_RETURN_STATEMENT, $2 ); }
;
declaration
: decl_specifiers declarator_list TOKEN_ENDSTATEMENT
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_DECLARATION, $1, $2 );
g_pSymbolTable->SetCurrentType( T_VOID ); }
;
decl_specifiers
: TOKEN_VOID { $$ = g_pSynTree->Insert( @1.first_line, TYPE_SPECIFIER_VOID ); }
| TOKEN_INT { g_pSymbolTable->SetCurrentType( T_INT );
$$ = g_pSynTree->Insert( @1.first_line, TYPE_SPECIFIER_INT ); }
| TOKEN_FLOAT { g_pSymbolTable->SetCurrentType( T_FLOAT );
$$ = g_pSynTree->Insert( @1.first_line, TYPE_SPECIFIER_FLOAT ); }
| TOKEN_BOOL { g_pSymbolTable->SetCurrentType( T_BOOL );
$$ = g_pSynTree->Insert( @1.first_line, TYPE_SPECIFIER_BOOL ); }
| TOKEN_STRING { g_pSymbolTable->SetCurrentType( T_STRING );
$$ = g_pSynTree->Insert( @1.first_line, TYPE_SPECIFIER_STRING ); }
;
variable
: TOKEN_ID {
$$ = g_pSymbolTable->FindVar( $1 );
if( $$ == 0 )
ErrorMessage2( @1.first_line, "undefined symbol : %s", $1 );
}
;
new_variable
: TOKEN_ID {
$$ = g_pSymbolTable->AddVar( $1 );
if( $$ == 0 )
ErrorMessage2( @1.first_line, "<22>̹<EFBFBD> <20><><EFBFBD><EFBFBD> <20>Ǿ<EFBFBD> <20>ִ<EFBFBD> <20>ɺ<EFBFBD><C9BA>Դϴ<D4B4>. : %s", $1 );
}
;
declarator_list
: init_declarator { $$ = $1; }
| declarator_list TOKEN_COMMA init_declarator { $$ = g_pSynTree->Insert( @1.first_line, TYPE_DECLARATOR_LIST, $1, $3 ); }
;
init_declarator
: new_variable TOKEN_ASSIGNMENT assignment_expression { $$ = g_pSynTree->Insert( @1.first_line, $1, TYPE_INIT_DECLARATION, $3 ); }
| new_variable { $$ = g_pSynTree->Insert( @1.first_line, $1, TYPE_NORMAL_DECLARATION ); }
| TOKEN_ID TOKEN_LEFTBRACE TOKEN_RIGHTBRACE array_initializer
{ $$ = g_pSynTree->Insert( @1.first_line, g_pSymbolTable->AddArrVar( $1, CountArrayElements( $4 ) ), TYPE_ARRAY_INITIALIZE, $4 ); }
| TOKEN_ID TOKEN_LEFTBRACE constant_expression TOKEN_RIGHTBRACE array_initializer
{ $$ = g_pSynTree->Insert( @1.first_line, g_pSymbolTable->AddArrVar( $1, GetConstantValue( $3 ) ), TYPE_ARRAY_INITIALIZE2, $3, $5 ); }
| TOKEN_ID TOKEN_LEFTBRACE constant_expression TOKEN_RIGHTBRACE
{ $$ = g_pSynTree->Insert( @1.first_line, g_pSymbolTable->AddArrVar( $1, GetConstantValue( $3 ) ), TYPE_ARRAY_DECLARATION, $3 ); }
;
array_initializer
: TOKEN_ASSIGNMENT TOKEN_LEFTBRACKET initializer_list TOKEN_RIGHTBRACKET
{ $$ = $3; }
;
initializer_list
: assignment_expression { $$ = $1; }
| assignment_expression TOKEN_COMMA initializer_list
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_INITIALIZER_LIST, $1, $3 ); }
;
argument_declaration_list
: argument_declaration { $$ = $1; }
| argument_declaration TOKEN_COMMA argument_declaration_list
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_ARGUMENT_DECLARATION_LIST, $1, $3 ); }
| { $$ = 0; }
;
argument_declaration
: decl_specifiers new_variable { $$ = g_pSynTree->Insert( @1.first_line, $2, TYPE_ARGUMENT_DECLARATION, $1 ); }
| decl_specifiers { $$ = $1; }
;
function_name
: TOKEN_ID { strcpy( $$, $1 );
g_pSymbolTable->BeginLocalNameSpace(); }
;
function_decl_end
: TOKEN_ENDSTATEMENT { g_pSymbolTable->EndLocalNameSpace( 0 ); }
;
function_def_start
: TOKEN_LEFTBRACKET { g_pSymbolTable->EndArgument(); }
;
function_definition
: decl_specifiers function_name TOKEN_LEFTPARENTHESIS argument_declaration_list TOKEN_RIGHTPARENTHESIS function_def_start statement_list TOKEN_RIGHTBRACKET
{
int symbID = g_pSymbolTable->AddFunc( true, $2, GetFunctionType( $1, $4 ) );
if( symbID == 0 )
ErrorMessage( @1.first_line, "<22><><EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> <20>ߺ<EFBFBD><DFBA>Ͽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>߽<EFBFBD><DFBD>ϴ<EFBFBD>." );
$$ = g_pSynTree->Insert( @1.first_line, symbID, TYPE_FUNCTION_DEFINITION, $4, $7 );
g_pSymbolTable->SetCurrentType( T_VOID );
g_pSymbolTable->EndLocalNameSpace( symbID );
}
| decl_specifiers function_name TOKEN_LEFTPARENTHESIS argument_declaration_list TOKEN_RIGHTPARENTHESIS function_decl_end
{ $$ = g_pSynTree->Insert( @1.first_line, g_pSymbolTable->AddFunc( false, $2, GetFunctionType( $1, $4 ) ), TYPE_FUNCTION_DECLARATION, $4 );
g_pSymbolTable->SetCurrentType( T_VOID ); }
;
constant_expression
: TOKEN_INTEGERVALUE { $$ = g_pSynTree->Insert( @1.first_line, g_pSymbolTable->AddConst( $1, T_INT ), TYPE_CONSTANT_EXPRESSION ); }
| TOKEN_FLOATVALUE { $$ = g_pSynTree->Insert( @1.first_line, g_pSymbolTable->AddConst( $1, T_FLOAT ), TYPE_CONSTANT_EXPRESSION ); }
| TOKEN_BOOLVALUE { $$ = g_pSynTree->Insert( @1.first_line, g_pSymbolTable->AddConst( $1, T_BOOL ), TYPE_CONSTANT_EXPRESSION ); }
| TOKEN_STRINGVALUE { $$ = g_pSynTree->Insert( @1.first_line, g_pSymbolTable->AddConst( $1, T_STRING ), TYPE_CONSTANT_EXPRESSION ); }
;
expression
: assignment_expression { $$ = $1; }
| assignment_expression TOKEN_COMMA expression { $$ = g_pSynTree->Insert( @1.first_line, TYPE_EXPRESSION_LIST, $1, $3 ); }
;
assignment_expression
: logical_or_expression { $$ = $1; }
| variable TOKEN_ASSIGNMENT assignment_expression
{ $$ = g_pSynTree->Insert( @1.first_line, $1, TYPE_ASSIGNMENT_EXPRESSION, $3 ); }
| variable TOKEN_COMPOUNDADDITION assignment_expression
{ $$ = g_pSynTree->Insert( @1.first_line, $1, TYPE_COMPOUND_ADDITION, $3 ); }
| variable TOKEN_COMPOUNDSUBTRACTION assignment_expression
{ $$ = g_pSynTree->Insert( @1.first_line, $1, TYPE_COMPOUND_SUBTRACTION, $3 ); }
| variable TOKEN_COMPOUNDMULTIPLICATION assignment_expression
{ $$ = g_pSynTree->Insert( @1.first_line, $1, TYPE_COMPOUND_MULTIPLICATION, $3 ); }
| variable TOKEN_COMPOUNDDIVISION assignment_expression
{ $$ = g_pSynTree->Insert( @1.first_line, $1, TYPE_COMPOUND_DIVISION, $3 ); }
| variable TOKEN_COMPOUNDREMINDER assignment_expression
{ $$ = g_pSynTree->Insert( @1.first_line, $1, TYPE_COMPOUND_REMINDER, $3 ); }
;
logical_or_expression
: logical_and_expression { $$ = $1; }
| logical_or_expression TOKEN_OR logical_and_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_OR_EXPRESSION, $1, $3 ); }
;
logical_and_expression
: equality_expression { $$ = $1; }
| logical_and_expression TOKEN_AND equality_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_AND_EXPRESSION, $1, $3 ); }
;
equality_expression
: relational_expression { $$ = $1; }
| equality_expression TOKEN_EQUALITY relational_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_EQUALITY_EXPRESSION, $1, $3 ); }
| equality_expression TOKEN_NOTEQUAL relational_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_NOTEQAUL_EXPRESSION, $1, $3 ); }
;
relational_expression
: additive_expression { $$ = $1; }
| relational_expression TOKEN_LESSTHAN additive_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_LESSTHAN_EXPRESSION, $1, $3 ); }
| relational_expression TOKEN_MORETHAN additive_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_MORETHAN_EXPRESSION, $1, $3 ); }
| relational_expression TOKEN_LESSTHANOREQUAL additive_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_LESSTHANOREQUAL_EXPRESSION, $1, $3 ); }
| relational_expression TOKEN_MORETHANOREQUAL additive_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_MORETHANOREQUAL_EXPRESSION, $1, $3 ); }
;
additive_expression
: multiplicative_expression { $$ = $1; }
| additive_expression TOKEN_ADDITION multiplicative_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_ADDITION_EXPRESSION, $1, $3 ); }
| additive_expression TOKEN_SUBTRACTION multiplicative_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_SUBTRACTION_EXPRESSION, $1, $3 ); }
;
multiplicative_expression
: unary_expression { $$ = $1; }
| multiplicative_expression TOKEN_MULTIPLICATION unary_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_MULTIPLICATION_EXPRESSION, $1, $3 ); }
| multiplicative_expression TOKEN_DIVISION unary_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_DIVISION_EXPRESSION, $1, $3 ); }
| multiplicative_expression TOKEN_REMINDER unary_expression
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_REMINDER_EXPRESSION, $1, $3 ); }
;
unary_expression
: postfix_expression { $$ = $1; }
| TOKEN_INCREMENT variable %prec PREFIXINCREMENT
{ $$ = g_pSynTree->Insert( @1.first_line, $2, TYPE_PREFIXINCREMENT ); }
| TOKEN_DECREMENT variable %prec PREFIXDECREMENT
{ $$ = g_pSynTree->Insert( @1.first_line, $2, TYPE_PREFIXDECREMENT ); }
| TOKEN_NOT unary_expression { $$ = g_pSynTree->Insert( @1.first_line, TYPE_NOT_EXPRESSION, $2 ); }
;
postfix_expression
: primary_expression { $$ = $1; }
| variable TOKEN_LEFTBRACE expression TOKEN_RIGHTBRACE
{ $$ = g_pSynTree->Insert( @1.first_line, $1, TYPE_ARRAY_INDEXING, $3 ); }
| TOKEN_ID TOKEN_LEFTPARENTHESIS expression TOKEN_RIGHTPARENTHESIS
{
int symbolID = g_pSymbolTable->FindFunc( $1, GetFuncCallType( $3 ) );
if( symbolID == 0 )
ErrorMessage2( "Error(line %d) : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> ã<><C3A3> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.\n", @1.first_line );
$$ = g_pSynTree->Insert( @1.first_line, symbolID, TYPE_FUNCTION_CALL, $3 );
}
| TOKEN_ID TOKEN_LEFTPARENTHESIS TOKEN_RIGHTPARENTHESIS
{
int symbolID = g_pSymbolTable->FindFunc( $1, 0 );
if( symbolID == 0 )
ErrorMessage2( "Error(line %d) : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> ã<><C3A3> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.\n", @1.first_line );
$$ = g_pSynTree->Insert( @1.first_line, symbolID, TYPE_FUNCTION_CALL );
}
| variable TOKEN_INCREMENT { $$ = g_pSynTree->Insert( @1.first_line, $1, TYPE_POSTFIXINCREMENT ); }
| variable TOKEN_DECREMENT { $$ = g_pSynTree->Insert( @1.first_line, $1, TYPE_POSTFIXDECREMENT ); }
;
primary_expression
: constant_expression { $$ = $1; }
| TOKEN_LEFTPARENTHESIS expression TOKEN_RIGHTPARENTHESIS
{ $$ = g_pSynTree->Insert( @1.first_line, TYPE_EXPRESSION, $2 ); }
| variable { $$ = g_pSynTree->Insert( @1.first_line, $1, TYPE_VARIABLE ); }
;
%%
/* ------------------------------------------------------------------
Additional code (again copied verbatim to the output file)
------------------------------------------------------------------ */
eDataType GetType( SNode * pNode )
{
switch( pNode->m_eType )
{
case TYPE_ARGUMENT_DECLARATION :
return GetType( pNode->m_ArrPtrChilds[0] );
case TYPE_SPECIFIER_INT :
return T_INT;
case TYPE_SPECIFIER_FLOAT :
return T_FLOAT;
case TYPE_SPECIFIER_BOOL :
return T_BOOL;
case TYPE_SPECIFIER_STRING :
return T_STRING;
}
return T_VOID;
}
SFuncType GetFunctionType( eDataType retType, int nodeID )
{
SNode * pNode = (SNode*)nodeID;
SFuncType FuncType;
int i = 0;
while( pNode != NULL )
{
if( pNode->m_eType == TYPE_ARGUMENT_DECLARATION_LIST )
{
FuncType.SetArgType( i++, GetType( pNode->m_ArrPtrChilds[0] ) );
pNode = pNode->m_ArrPtrChilds[1];
}
else //TYPE_ARGUMENT_DECLARATION<4F><4E> TYPE_SPECIFIER_XXX <20><EFBFBD><E8BFAD> <20><>
{
FuncType.SetArgType( i++, GetType( pNode ) );
break;
}
}
assert( i <= 8 );
FuncType.SetReturnType( retType );
return FuncType;
}
SFuncType GetFunctionType( int nodeID )
{
return GetFunctionType( g_pSymbolTable->GetCurrentType(), nodeID );
}
SFuncType GetFunctionType( int nodeID1, int nodeID2 )
{
SNode * pNode = (SNode*)nodeID1;
if( pNode != NULL )
{
return GetFunctionType( GetType( pNode ), nodeID2 );
}
return 0;
}
SFuncType GetFuncCallType( int nodeID )
{
SNode * pNode = (SNode*)nodeID;
SFuncType FuncType;
int i = 0;
while( pNode != NULL )
{
if( pNode->m_eType == TYPE_EXPRESSION_LIST )
{
FuncType.SetArgType( i++, pNode->m_ArrPtrChilds[0]->m_eReturnType );
pNode = pNode->m_ArrPtrChilds[1];
}
else
{
FuncType.SetArgType( i++, pNode->m_eReturnType );
break;
}
}
assert( i <= 8 );
FuncType.SetReturnType( T_VOID );
return FuncType;
}
int CountArrayElements( int nodeID )
{
if( nodeID == 0 )
return 0;
SNode * pNode = (SNode*)nodeID;
//initializer_list
int i = 0;
while( pNode != NULL )
{
if( pNode->m_eType == TYPE_INITIALIZER_LIST )
{
i++;
pNode = pNode->m_ArrPtrChilds[1];
}
else
{
i++;
break;
}
}
return i;
}
int GetConstantValue( int nodeID )
{
//constant expression
SNode * pNode = (SNode*)nodeID;
if( pNode->m_eType == TYPE_CONSTANT_EXPRESSION )
{
if( g_pSymbolTable->GetTypeOfConst( pNode->m_SymbolID ) == T_INT )
{
const char * pStr = g_pSymbolTable->GetNameOfConst( pNode->m_SymbolID );
return strtol( pStr, NULL, 0 );
}
}
return 0;
}

View File

View File

@@ -0,0 +1,137 @@
[[[<5B>ذ<EFBFBD><D8B0>ؾ<EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]]]
=> <20>޴<EFBFBD><DEB4><EFBFBD> <20><><EFBFBD><EFBFBD>
=> <20><>ó<EFBFBD><C3B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ֱ<EFBFBD>
=> <20>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD>ȭ <20>˰<EFBFBD><CBB0><EFBFBD><EFBFBD><EFBFBD> <20>ֱ<EFBFBD>
=> ++, --, =<3D><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> <20>س<EFBFBD><D8B3>µ<EFBFBD>, <20><20>ε<EFBFBD><CEB5><EFBFBD>(a[2])<29><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> <20>ٲ<EFBFBD> <20><>.
=> <20>Լ<EFBFBD><D4BC><EFBFBD> <20><EFBFBD><E8BFAD> <20>Ѱ<EFBFBD><D1B0><EFBFBD> <20><> <20>ֵ<EFBFBD><D6B5><EFBFBD> <20><> <20><>.
=> <20><><EFBFBD>κ<EFBFBD><CEBA><EFBFBD> <20><><EFBFBD>ɿ<EFBFBD><C9BF><EFBFBD> <20>ӽ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>μ<EFBFBD> ECX, EDX<44><58><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD> <20><><EFBFBD>µ<EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><CCB6><EFBFBD>
<20>ߺ<EFBFBD><DFBA><EFBFBD> <20><><EFBFBD><20><><EFBFBD><EFBFBD> <20><> <20>ִµ<D6B4>, <20>̷<EFBFBD> <20><><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>߸<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ȴ<EFBFBD>.
<09><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> int a = func( 4 ) + 10; <20>̷<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ<EFBFBD><DAB5><EFBFBD> <20>ٲ<EFBFBD> <20><>
1.MOV ECX, 10
2.MOV ECX, 4
3.PUSH ECX
4.CALL func
5.ADD ESP, 4
6.ADD ECX, EDX
7.MOV a, ECX
<09>̷<EFBFBD><CCB7><EFBFBD> <20>ٲ<EFBFBD><D9B2>µ<EFBFBD>, 1<><31> <20><><EFBFBD>ɿ<EFBFBD><C9BF><EFBFBD> ECX<43><58><EFBFBD><EFBFBD> <20>ӽ÷<D3BD> 10<31><30> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>µ<EFBFBD>
2<><32> <20><><EFBFBD>ɿ<EFBFBD><C9BF><EFBFBD> <20>ӽ÷<D3BD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ִ´ٰ<C2B4> 4<><34> <20>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20≯<EFBFBD> <20>־<EFBFBD>
<09><><EFBFBD><EFBFBD> <20><> 10<31><30> <20>Ҿ<EFBFBD><D2BE><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><20><><EFBFBD><EFBFBD> <20><> <20>ִ<EFBFBD>.
->PUSH, POP<4F><50><EFBFBD><EFBFBD> <20>ذ<EFBFBD><D8B0><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ִµ<D6B4>... <20>̷<EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʹ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ȴ<EFBFBD>.
-><3E><> <20><><EFBFBD>ɸ<EFBFBD><C9B8><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>¸<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, <20><><EFBFBD>ο<EFBFBD> Statement<6E><74> <20><><EFBFBD>۵ɶ<DBB5><C9B6><EFBFBD><EFBFBD><EFBFBD>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>¸<EFBFBD> <20>ʱ<EFBFBD>ȭ <20>ϵ<EFBFBD><CFB5><EFBFBD> <20>س<EFBFBD><D8B3><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>¿<EFBFBD> <20><><EFBFBD><EFBFBD>
<20>ӽ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> <20>ϴ<EFBFBD> <20>͵<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>...
=> EAX <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> <20><><EFBFBD>ϰ<EFBFBD><CFB0><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>س<EFBFBD><D8B3><EFBFBD> <20><><EFBFBD>µ<EFBFBD>, <20>̰Ͱ<CCB0> <20>ߺ<EFBFBD><DFBA><EFBFBD> <20><><EFBFBD><EFBFBD><ECBFA1>
<09><><EFBFBD><EFBFBD>ġ <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20>ִ<EFBFBD>.
=> <20><><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20>ӽ<EFBFBD> <20><><EFBFBD>ڿ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ǵµ<C7B4>, <20>̰<EFBFBD><CCB0><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD> <20>˰<EFBFBD><CBB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<09><><EFBFBD>߿<EFBFBD> <20><><EFBFBD><EFBFBD> <20><>.
[0.9]
[0.8]
=>string<6E><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>߰<EFBFBD>.( +, +=, = )
[0.78]
=>VirtualMachine Ŭ<><C5AC><EFBFBD><EFBFBD> <20>߰<EFBFBD>, <20>Լ<EFBFBD> <20><><EFBFBD>ε<EFBFBD> <20>߰<EFBFBD>
[0.77]
=>IntermediateCode -> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ<EFBFBD> <20>κп<CEBA> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>׵<EFBFBD> <20><><EFBFBD><EFBFBD>.
[0.75]
=>IntermediateCode -> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ<EFBFBD> <20>κ<EFBFBD> <20>߰<EFBFBD>.
=>TYPE_FUNCTION_CALL<4C><4C> <20><><EFBFBD><EFBFBD> Ÿ<><C5B8> üũ <20>߰<EFBFBD>
[0.7]
=>IntermediateCode<64><65><EFBFBD><EFBFBD> <20>ٷ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ带 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ֵ<EFBFBD><D6B5><EFBFBD> <20>ϱ<EFBFBD> <20><><EFBFBD><EFBFBD>
IntermediateCode Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20>ڵ<EFBFBD>
[0.6.2]
=>0.5 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> Intermediate<74>ڵ<EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> <20><EFBFBD><E8BFAD> <20><><EFBFBD><EFBFBD> <20>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>
=>IntermediateCode Ŭ<><C5AC><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD>
[0.6.1]
=><3E>Լ<EFBFBD><D4BC><EFBFBD> <20><EFBFBD><E8BFAD> <20><><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD> SymbolTable<6C><65> SyntaxTree<65><65> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
[0.6]
=>Virtual Machine<6E><65> <20><><EFBFBD><EFBFBD><EFBFBD> Intermediate <20>ڵ尡 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ֵ<EFBFBD><D6B5><EFBFBD> <20><>.
[0.5]
=>Intermediate <20>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>.
[0.4]
=>syntax tree<65><65><EFBFBD><EFBFBD> Ÿ<><C5B8> üŷ <20>߰<EFBFBD>
[0.3]
=>symbol table<6C><65> syntax tree <20>߰<EFBFBD>
[0.2]
=><3E><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> parser <20>ڵ<EFBFBD>
[0.1]
=><3E><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> lexer <20>ڵ<EFBFBD>
<20><>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʾ<EFBFBD><CABE><EFBFBD>.
[<5B><>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>]
#include
#define
[<5B>ּ<EFBFBD>]
//
/* ... */
[<5B><><EFBFBD><EFBFBD>]
int<6E><74><EFBFBD><EFBFBD>
float<61><74><EFBFBD><EFBFBD>
bool<6F><6C><EFBFBD><EFBFBD>
string<6E><67><EFBFBD><EFBFBD>
vector<6F><72><EFBFBD><EFBFBD>
<><C5B0><EFBFBD><EFBFBD>]
(<28><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> Ű<><C5B0><EFBFBD><EFBFBD>)
int
float
bool
string
vector
(<28><><EFBFBD><EFBFBD> Ű<><C5B0><EFBFBD><EFBFBD>)
for
while
(<28>б<EFBFBD> Ű<><C5B0><EFBFBD><EFBFBD>)
if
else
switch
(<28><><EFBFBD><EFBFBD> Ű<><C5B0><EFBFBD><EFBFBD>)
break
continue
default
case
return
[<5B>ɺ<EFBFBD>]
[<5B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>]
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
+, -, *, /, %
+=, -=, *=, /=, %=
++, --
=
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
&&, ||
<09>񱳿<EFBFBD><F1B1B3BF><EFBFBD><EFBFBD><EFBFBD>
<, <=, >, >=, ==, !=
[<5B><>Ÿ]
;
()
[] - <20>ε<EFBFBD><CEB5><EFBFBD>
{}
[<5B>Լ<EFBFBD>]
<09><><EFBFBD><EFBFBD>
ȣ<><C8A3>
<09><><EFBFBD><EFBFBD>