文档库

最新最全的文档下载
当前位置:文档库 > 语法语义错误1

语法语义错误1

指出程序中的错误并解释原因:

1. PROGRAM error1(input);

LABEL

20,12345,12.66, n, ’aa’;

CONST

e = 2.71828;

pi = ;

c =-2.55e-5;

b=i;

TYPE

Int=integer;

num=(1, 2, 3, 4, 5);

abc=(‘a hcds’, ’b fdfd’, ’c’, ’d’, ’e’);

set1=20 .. 10;

week=(Mon,Tues,Sun);

VAR

i, b, c, d, b-1, n, abc : integer;

a : array[1..10] of real;

ch : char;

BEGIN

readln(n); b:=c:=10;

b-1:=3 ; a[8]:=33;

ch:='abc';

ch1:=‘ ’;

FOR i:=1 TO n DO

BEGIN

20: CASE i OF

1 : write(i);

2 :write(i/10);

ch1 :ch:='a';

b+2: write(b+2);

END;

IF i=10 THEN BEGIN i:=1; n:=10; END;

END;

IF 0 < i < 100

THEN GOTO 20 ;

ELSE GOTO ‘END’;

FOR i:=1 TO 20 DO

BEGIN a[i]:=i; a[a[i]]:=i+1 END;

writeln(a);

END.

Program error;

Const

sc= [1, 2, 3, 5, 8];

c = 10;

Type

int=1..10;

ftype=file of text;

Var

i, j : integer;

s1: set of integer;

a : array [ 1 .. sqr ( c ) ] of integer;

f : ftype;

pf: ↑ftype;

Procedure Err1(s: integer; c: char);

Begin

If s>0 Then writeln ( c, ’=' , s)

Else Begin Err1( s, c ); s:=s+1 End End;

Function Err2(var a: int; b: int;s: set of 1 .. 20);

Begin

a:=a+b; s:=s+a;

writeln(‘set=’, s)

End;

Begin

i := 3; err1( ‘a’, i ); read( j );

j := Err2( i+j, i j );

For a[1] :=1 To 100 Do

writeln(a[1]) ;

k := 1;

s1:=[4, 2, 3, 5, 9, 6];

While k In s1 do;

Begin

writeln( ‘k=’, k ); k:=k+1;

End

End.