Syntax error : System verilog keyword 'void' is not expected to b used in this context

i made a simple code but I am getting error… Can anyone help me in solving the error… the solution wud be pretty simple… but i m not clicking to it

class A extends B;
ovm_object_utils_begin (A) ovm_object_utils_end

static void main ()
{
string mode1 = [“chip”, “boundary”, “chain”]

}

endclass:A
`endif

Result:
Syntax error : System verilog keyword ‘void’ is not expected to b used in this context

The first error is that you are missing the ‘function’ keyword in the declaration of main().
Also I’m not sure if your assignment to mode1 is correct.

In reply to dwikle:

thanks…

mode1 is my string array. Is there anyother way I can define my string array? I want to declare the mode1 string array in a such a way so that I can pass it to my other function

The problem is that you’re mixing up c syntax with SystemVerilog syntax.

The main function - do you really mean this given what the main function does in c? - should be implemented something along the lines of:

static function void main() string mode1[3] = '{"chip", "boundary", "chain"}; endfunction: main

In reply to mperyer:

@mperyer
You are right. I was mixing system verilog wid C++… Sorry but I am new in system verilog. I modified my program now but i again got an error:

Modified program:
static function void main()
{
string mode1[3] = '{“chip”, “boundary”, “chain”};
string mode2[2] = {“chip”, “chain”};
}
endfunction: main

Error:
syntax error:token is ‘{’
{

Another thing is that if I want to pass the string array as an argument to some other function. example

tester (mode1);

Is it the correct way to pass a string array to a function?

You’re still mixing up the syntax - in SystemVerilog you don’t need the { } braces around the function call body, that’s what the compiler is complaining about.

The ’ in front of the RHS side of the array assignment is important, it says that what comes inside the braces is the content of the array.

If you want to pass an array to another function call you have to code the target function call like this:

function void print_array(string ip_info[3]); foreach(ip_info[i]) begin $display(ip_info[i]); end endfunction

In reply to mperyer:

@mperyer

I changed the syntax now but again I am getting the syntax error:

Modified program:
static function void main()

string mode1[3] = '{“chip”, “boundary”, “chain”};
string mode2[2] = '{“chip”, “chain”};

endfunction: main

Error:
string mode1[3] = '{“chip”, “boundary”, “chain”};

syntax error: system verilog keyword ‘string’ is not expected to be used in this context.

The following code works fine for me:

class A;

static function void main();

string mode1[3] = '{“chip”, “boundary”, “chain”};
string mode2[2] = '{“chip”, “chain”};

print_it(mode1);
print_it(mode2);

endfunction: main

static function void print_it(string details);
foreach(details[i]) begin
$display(details[i]);
end
endfunction: print_it
endclass: A

module tb;

A a_h;

initial begin
a_h = new;
a_h.main();
end

endmodule: tb

I think the error message may be because you didn’t include the semi-colon at the end of the function header. Take care.

In reply to mperyer:

hi mperyer,

Many Thanks for the info. It worked for me. Now I am trying to do the following:

class A;
static function void main();
string mode1[3] = '{“chip”, “boundary”, “chain”};
string mode2[2] = '{“chip”, “chain”};
endfunction: main
endclass: A

class B;
static function void print_it(string details);
foreach(details[i]) begin
$display(details[i]);
end
endfunction: print_it
endclass:B

class C;
A test_mode;
B printing;
printing.print_it(test_mode.mode1);
endclass:C

This is what I am trying to do and I get the following error:
Member not found
Could not find member ‘mode1’ in class A

In reply to debuggerzc:

Because your member ‘mode1’ is defined in a static function, not in class A. You still mixed the syntax between C and SV. If you want to use a string in class , you wont define it in a main function. That is wrong.
This code maybe fit for you:

class A;
string mode1[3]=xxxxx;
string mode2[2]=xxxxx;
endclass : A

class B;

endclass : B

class C;
A test_mode;
B printing;
test_mode = new();
printing = new();
printing.print_it(test_mode.mode1);
endclass:C

You can try it again.

In reply to gaurson:

@gaurson
thanks.The issue is solved. Now there is no syntax error but when i run the testcase I get the following error:

Error-[NOA] Null object access
Please make sure that the object is newed before using it.
The object is being used before it was constructed.

It is complaining about the following line of code below:
test_mode.mode1=xxx

The complete code is:

class A;
function new(string name = “A”);
super.new(name);
endfunction:new
string mode1[3] = '{“chip”, “boundary”, “chain”};
string mode2[2] = '{“chip”, “chain”};
endclass : A

class B;
function new(string name = “B”);
super.new(name);
endfunction:new
function void print_it(string details);
A test_mode;
foreach(details[i]) begin
test_mode.mode1=xxx
$display(details[i]);
end
endfunction: print_it
endclass : B

class C;
function new(string name = “C”);
super.new(name);
endfunction:new
A test_mode;
B printing;
test_mode = new();
printing = new();
printing.print_it(test_mode.mode1);
endclass:C

Do you have any idea what is missing in the code?

In reply to debuggerzc:

I think your knowledge of OVM or SV is so pitty. I suggest you that read some book about it and do some research by yourself. So maybe you have a great development.
By the way, this problem is that you dont execute class A’s new() to instantiate a instance of A in class B. You just do so in class C.
Oh, my god. You must have a deep study on OVM or SV.

In reply to gaurson:

@gaurson

well I made a blunder in typing on forum… I did the following in Class B instead of Class C:

test_mode = new();
printing = new();

and got the error I wrote in my previous post. Yes I am new to OVM and system verilog.

In reply to debuggerzc:

This is what I did in class B:

class B;
function new(string name = “B”);
super.new(name);
endfunction:new

function void print_it(string details);
A test_mode;
test_mode = new();

foreach(details[i]) begin
test_mode.mode1=xxx
$display(details[i]);
end
endfunction: print_it
endclass : B