im working on a a scripting language...called EASL (Easy Ass Scripting Language) just for learning.
Code:
// Main.cpp
#include "VirtualMachine.h"
using std::vector;
void main()
{
VirtualMachine VM;
vector <Instruction> InstrList;
InstrList.push_back(Instruction(op_hello));
InstrList.push_back(Instruction(op_hello));
InstrList.push_back(Instruction(op_end));
Script script(InstrList);
int scriptId = VM.Load(script);
VM.Execute(scriptId);
}
Code:
// VirtualMachine.h
#ifndef VirtualMachine_H__
#define VirtualMachine_H__
#include <iostream.h>
#include <vector>
using std::vector;
enum OpCode
{
op_hello,
op_end
};
// The Basic Instruction
class Instruction
{
private:
OpCode code;
public:
Instruction(OpCode _code) { code = _code; }
OpCode Code() const { return code; )
};
// The Basic Script, a vector of instructions...
class Script
{
private:
vector <Instruction> instrList;
public:
Script(const vector <Instruction> & _instrList) { instrList = _instrList; }
const Instruction *InstrPtr() const { return &instrList[0]; };
};
// Basic Virtual Machine to process commands
class VirtualMachine
{
private:
// pointers for non-modifying dynamic references
typedef const Script *ScriptRef;
typedef const Instruction *InstrRef;
// data members
vector <Script> scriptList;
ScriptRef scriptPtr;
InstrRef instrPtr;
InstrRef instr;
int scriptCount;
// utilities
int AddScript(const Script &script)
{ scriptList.push_back(script); return scriptCount++; }
void SelectScript(int index)
{ assert(index < scriptCount); scriptPtr = &scriptList[index];
instrPtr = scriptPtr->InstrPtr(); }
public:
VirtualMachine()
{ scriptPtr = 0; instrPtr = 0; instr = 0; scriptCount = 0; }
void Execute(int scriptId);
int Load(const Script &script) { return AddScript(script); }
};
//Implementation of VirtualMachine::Execute
void VirtualMachine::Execute(int scriptId)
{
SelectScript(scriptId);
instr = instrPtr;
while(instr)
{
switch(instr->Code())
{
case op_hello:
cout << "Hello World." << endl;
instr++;
break;
case op_end:
instr = 0;
break;
case default:
cout << "Command is invalid dumbass." << endl;
}
}
}
#endif
These are the errors i get in VC 6:
Code:
d:\programming\easl\virtualmachine.h(70) : error C2838: illegal qualified name in member declaration
d:\programming\easl\virtualmachine.h(71) : error C2061: syntax error : identifier 'scriptId'
d:\programming\easl\virtualmachine.h(72) : error C2065: 'instrPtr' : undeclared identifier
d:\programming\easl\virtualmachine.h(72) : error C2258: illegal pure syntax, must be '= 0'
d:\programming\easl\virtualmachine.h(72) : error C2501: 'instr' : missing storage-class or type specifiers
d:\programming\easl\virtualmachine.h(74) : error C2059: syntax error : 'while'
d:\programming\easl\virtualmachine.h(75) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
d:\programming\easl\main.cpp(3) : error C2143: syntax error : missing ';' before 'PCH creation point'
d:\programming\easl\main.cpp(7) : error C2065: 'VirtualMachine' : undeclared identifier
d:\programming\easl\main.cpp(7) : error C2146: syntax error : missing ';' before identifier 'VM'
d:\programming\easl\main.cpp(7) : error C2065: 'VM' : undeclared identifier
d:\programming\easl\main.cpp(15) : error C2065: 'Script' : undeclared identifier
d:\programming\easl\main.cpp(15) : error C2146: syntax error : missing ';' before identifier 'script'
d:\programming\easl\main.cpp(15) : error C2065: 'script' : undeclared identifier
d:\programming\easl\main.cpp(17) : error C2228: left of '.Load' must have class/struct/union type
d:\programming\easl\main.cpp(19) : error C2228: left of '.Execute' must have class/struct/union type
Error executing cl.exe.
I dont see anything thing wrong with the code. I know i'm overlooking something. Two head are definetly better than one.
Thanks!