Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Руководство NL5.pdf
Скачиваний:
86
Добавлен:
15.03.2016
Размер:
6.44 Mб
Скачать

NL5 circuit simulator

Руководство Пользователя

Язык C

В NL5 реализован упрощенный интерпретатор языка C. Он используется в скрипте и в C модели компонента Code. Несмотря на то, что поддерживаются не все возможности стандартного языка C, имеющиеся функции позволяют эффективно решать многие задачи.

Реализованы следующие ключевые слова и операторы:

bool

if…else

continue

int

for

break

float

while

return

double

do…while

 

complex

switch

 

 

case

 

 

default

 

Следующие возможности языка C не поддерживаются в этой версии NL5:

структуры и объединения (structure, union).

указатели и ссылки.

оператор goto.

многомерные массивы.

Comments (комментарии)

Use // to comment text until the end of the line, or delimiters /* and */ to comment block of the text. Delimiters /* and */ can be nested.

for( i=0; i<10; ++i ) { // this is a comment /* This block is commented out

x=i*2;

y=i/10;

*/

x=i;

}

Data types (типы данных)

The following data types are supported:

bool – boolean (true/false).

int – 32-bit signed integer.

float – same as double.

double – 8-byte floating point.

complex – consists of double real and imaginary parts.

69

NL5 circuit simulator

Руководство Пользователя

Variables (переменные)

All variables must be declared before use. To declare a new variable, use keyword bool, int, float, double, or complex with the variable name. A variable can be initialized in the declaration:

double x; double x, y, z; double x=1.0; int i=2, j=5; bool flag;

complex c = 0.5+0.5j;

Arrays (массивы)

Only one-dimensional arrays are supported. Index is zero-based. An array can be initialized in the declaration:

double x[100];

int array[] = { 1, 2, 3, 4, 5 };

Statements and operators

if…else. Conditional statement.

if(i<=0) R1=1.0k;

else if(i==1) R1=2.0k; else {

R1=3.0k;

C1=1n;

}

for. Loop operator.

for( i=0; i<10; ++i ) { x[i]=1<<i;

y+=x[i];

}

―Foreach‖ loop operator. The code is executed for all values from the comma-separated list.

for( i=1,5,10,50,100 ) { y*=i;

}

while. Loop operator.

i=0;

while( i<10 ) { x[i]=1<<i; ++i;

}

70

NL5 circuit simulator

Руководство Пользователя

do…while. Loop operator.

i=0; do {

x[i]=1<<i;

++i;

}

while( i<10 );

switch. Selective structure.

switch(i) {

case 1: x=1; break; case 2: x=2; break; default: x=3; break;

}

continue. Skip the rest of the code in the current loop.

for( i=0; i<10; ++i ) { x[i]=1<<i;

if(i==5) continue; y+=x[i];

}

break. Leave current loop or switch statement.

for( i=0; i<10; ++i ) { x[i]=1<<i;

if(i==5) break; y+=x[i];

}

return. Stop execution of the code immediately and exit.

for( i=0; i<10; ++i ) { x[i]=1<<i; if(x[i]==0) return; y/=x[i];

}

Общую информацию о синтаксисе и использовании языка C вы можете найти во множестве доступных источников.

71