help with errors...

This is a discussion on help with errors... within the C++ Programming forums, part of the General Programming Boards category; im working on a a scripting language...called EASL (Easy Ass Scripting Language) just for learning. Code: // Main.cpp #include "VirtualMachine.h" ...

  1. #1
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186

    Question help with errors...

    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!
    the best things in life are simple.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    The first one means that you can't implement a member function in the header file unless it is inline. Place this stuff in a file called VirtualMachine.cpp

    //Implementation of VirtualMachine::Execute
    void VirtualMachine::Execute(int scriptId)
    {
    //etc.

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    It will compile without having to place it in a separate cpp file. Your problem is that in your Instruction::Code( ) declaration, you have a closing bracket, instead of a brace.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186
    Awesome thanks guys! It works!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 05:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21