Class inside a package

HI,
I would like to get the following clarified:

There is a package inside which a class is defined

file name: packageA.sv
Line 1:

package A;

class xyz;

function1();
function2();

endclass

class abc;

function3();
function4();

endclass

endpackage

In a class which uses this package, I say:

`include "packageA.sv";
import packageA::*;
  
  class stim;

     abc obj1;
     obj1 = new();

..
endclass

When I try to compile this , it gives error pointing to packageA.sv (1):
near “package”: syntax error, unexpected package, expecting class.

what is it that is wrong here. Can you please help me out.

Thanks

In reply to Ramyas:

You should have gotten a nested set of filenames in you error message. What is the name of the file that has the `include “packageA.sv”;, and is that the first line of the file?

Somethat that come before that could be the problem.

In reply to dave_59:

Name of the file that has the `include and import of packageA is stim.sv .

I’m not clear about this question : "and is that the first line of the file?2

Somethat that come before that could be the problem. : Thanks for your response, dave. But I’m not sure I get this point.

In reply to Ramyas:

Syntax error messages can be very cryptic. Sometimes there is nothing wrong with the line it is pointing to, but there is a problem with the source text that comes just before it. The pre-processor is just going to inline all the `include files, so think only of the single stream of text that is being compiled.

So I’ll ask again, what source text comes before the `include statement in the stim.sv file?

In reply to dave_59:

the stim.sv is compiled separately. As in, in a package , there are a list of files included, one of them is stim.sv: like:

package bus_agent;

include "file1.sv" include “stim.sv”

endpackage

Another thing I tried was : in the above stim.sv file, I removed the import packageA and used only include , like as follows:

`include “packageA.sv”;

class stim;

 abc obj1;
 packageA::obj1 = new();


endclass

Now, the error is: packageA.sv(1) near “package”: syntax error, unexpected package, expecting class.

Can a package have a class within it as I’ve shown above and what would be a correct way to include/import packageA in stim.sv. Note: packageA comes from a different directory structure (from another team. This is suposed to be shared). So, I can only include/import packageA and use it.

In reply to Ramyas:

*include "packageA.sv";* I think include should not end with a semicolon. Just remove the semicolon on this line and try again.

In reply to Ramyas:

You’ve nested package declarations. Follow this:

package bus_agent;

`include "file1.sv"
`include "stim.sv"

  // stim.sv does an include of pkgA.sv
  // So a pre-processor ends up with:
  package A; // Syntax error

HTH
Srini
www.go2uvm.org

In reply to NANDA KUMAR:

The semicolon is a typo. thats not present in the actual file.

In reply to Srini @ CVCblr.com:

As I said earlier, packageA is a shared package/file. I have to use it as is. I can only include/import in my files.

In reply to Ramyas:

Move that include stim.sv to outside the package
package bus_agent

Good luck
Srini

In reply to Ramyas:

It might help if you had a clearer picture of the differences between import and `include. See http://go.mentor.com/package-import-versus-include