Recent

Author Topic: illegal expression  (Read 4069 times)

achref

  • New Member
  • *
  • Posts: 12
illegal expression
« on: March 19, 2021, 11:35:04 am »
i have this error it says (while pointing at the last ligne)illegal expression ligne 172 col 1 while the main program is 10 lines
here is the program
Code: Pascal  [Select][+][-]
  1. Program sakkd;
  2. Uses jack;
  3. Var
  4.     s : string;
  5. Begin
  6.     readln(s);
  7.     s := clean(s);
  8.     writeln(S);
  9. End.
  10.  
here is the unit jack i put a comment next to the ligne 172
Code: Pascal  [Select][+][-]
  1. Unit jack;
  2. Interface
  3. Type
  4.     recoo = Record
  5.         wrd : string[50];
  6.         emo : real;
  7.     End;
  8.     tab = array[1..50] Of recoo;
  9. Function clean(l:String) : string;
  10. Function fill(l:String;Var table:tab) : real;
  11. Function lengtho(l:String) : integer;
  12. Function tlength(t:tab) : integer;
  13. Procedure delreptab(Var t:tab);
  14. Procedure deletee(Var t:tab;l:integer);
  15. Procedure sep(Var t,t1,t2:tab);
  16. Procedure hertz(Var t:tab);
  17. Procedure fillt(l:String;t:tab);
  18. Procedure readt(Var t:tab;n:integer);
  19.  
  20.  
  21.  
  22.  
  23.  
  24. //--------------------------------------------------------------------------
  25. Implementation
  26. Function clean(l:String) : string;
  27. Var
  28.     j,i : integer;
  29.     c1,clower,cspace,cupper : boolean;
  30. Begin
  31.  
  32.     j := 1;
  33.     While j<=length(l) Do
  34.         Begin
  35.             clower := ((ord(l[j])>64)And(ord(l[j])<91));
  36.             cspace := ord(l[j])=32;
  37.             cupper := ((ord(l[j])>96 )And (ord(l[j])<123));
  38.  
  39.             If Not(clower Or cspace Or cupper) Then
  40.                 delete(l,j,1);
  41.             If (clower Or cspace Or cupper) Then
  42.                 j := j+1;
  43.         End;
  44.     j := 1;
  45.     While j<=length(l) Do
  46.         Begin
  47.             If ( (l[j]=' ') And (ord(l[j+1])<65 ) ) Then
  48.                 delete (l,j,1)
  49.             Else
  50.                 j := j+1;
  51.         End;
  52.     clean := l;
  53.  
  54. End;
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//-------------------
  62.  
  63.  
  64.  
  65. Function fill(l:String; Var table:tab) : real;
  66. Var
  67.     i,j : integer;
  68.     answer : real;
  69. Begin
  70.     For i:=1 To 50 Do
  71.         table[i].emo := 0;
  72.     j := 1;
  73.     For i:=1 To length(l) Do
  74.         Begin
  75.             If l[i]<>' ' Then
  76.                 table[j].wrd := table[j].wrd+l[i]
  77.             Else
  78.                 j := j+1;
  79.         End;
  80.     If (table[j].wrd='positive') Then
  81.         fill := 1
  82.     Else
  83.         fill := -1;
  84.     answer := fill(l,table);
  85.     For i:=1 To j Do
  86.         Begin
  87.             table[i].emo := table[i].emo+answer;
  88.         End;
  89.  
  90. End;
  91. //----------------------------------------------------------------------------------------------
  92. Function lengtho(l:String) : integer;
  93. Var
  94.     i,j : integer;
  95. Begin
  96.     j := 1;
  97.     For i:=1 To length(l) Do
  98.         Begin
  99.             If (l[i]=' ' ) Then
  100.                 j := j+1;
  101.         End;
  102.     lengtho := j;
  103.  
  104. End;
  105.  
  106. //---------------------------------------------------------------------------------------------------
  107. Function tlength(t:tab) : integer;
  108. Var
  109.     i,j : integer;
  110.     empty : boolean;
  111. Begin
  112.     empty := t[i].wrd='';
  113.     i := 1;
  114.     While ((i<=50) And (Not(empty))) Do
  115.         Begin
  116.             j := j+1
  117.         End;
  118.     tlength := j;
  119. End;
  120. //--------------------------------------------------------------------------------------------------
  121. Procedure delreptab(Var t:tab);
  122. Var
  123.     j,k,n : integer;
  124. Begin
  125.     For j:=1 To tlength(t) Do
  126.         Begin
  127.             For k:=j To  tlength(t) Do
  128.                 Begin
  129.                     If t[j].wrd=t[k].wrd Then
  130.                         Begin
  131.                             If t[j].emo=t[k].emo Then
  132.                                 Begin
  133.                                     t[j].emo := t[j].emo+t[j].emo;
  134.                                     For n:=j To tlength(T) Do
  135.                                         t[n] := t[n+1];
  136.                                 End;
  137.                         End;
  138.  
  139.                 End;
  140.  
  141.         End;
  142.  
  143. End;
  144.  
  145. //---------------------------------------------------------------------------------------------------
  146. Procedure deletee(Var t:tab;l:integer);
  147. Var
  148.     i,j : integer;
  149. Begin
  150.  
  151.     For i:=l To 50 Do
  152.         Begin
  153.             t[i] := t[i+1];
  154.  
  155.         End;
  156.  
  157. End;
  158. //--------------------------------------------------------------------------------------------------
  159. Procedure sep(Var t,t1,t2:tab);
  160. Var
  161.     i,k,j : integer;
  162. Begin
  163.     For i:=1 To 50 Do
  164.         Begin
  165.             j := 1;
  166.             k := 1;
  167.             If t[i].emo>0 Then
  168.                 Begin
  169.                     t1[j] := t[i];
  170.                     j := j+1;
  171.                 End;
  172.             if t[i].emo<0 then  ////this is the ligne  172 <<((------------------------(<
  173.                 Begin
  174.                     t2[k] := t[i];
  175.                     k := k+1;
  176.                 End;
  177.  
  178.         End;
  179. End;
  180.  
  181. //---------------------------------------------------------------------------------------------------
  182. Procedure hertz (Var t:tab);
  183. Var
  184.     i,j : integer;
  185.     k : real;
  186. Begin
  187.     For i:=1 To 50 Do
  188.         k := t[i].emo;
  189.     Begin
  190.         For j:=i To 50 Do
  191.             Begin
  192.                 If t[i].wrd =t[j].wrd Then
  193.                     Begin
  194.                         t[i].emo := t[i].emo+k;
  195.                         deletee(t,j);
  196.                     End;
  197.  
  198.             End;
  199.  
  200.     End;
  201.  
  202. End;
  203.  
  204.  
  205. //---------------------------------------------------------------------------------------------------
  206. Procedure readt(Var t:tab;n:integer);
  207. Var
  208.     i,j : integer;
  209.     k : real;
  210.     s : string;
  211. Begin
  212.     For i:=1 To n Do
  213.         Begin
  214.             readln(s);
  215.             t[i].wrd := s;
  216.             readln(k);
  217.             t[i].emo := k;
  218.         End;
  219. End;
  220.  
  221.  
  222. //---------------------------------------------------------------------------------------------------
  223. Procedure fillt(l:String;t:tab);
  224. Var
  225.     i,j : integer;
  226. Begin
  227.     For i:=1 To length(l) Do
  228.         Begin
  229.             j := 1;
  230.             If l[i]<>' ' Then
  231.                 t[j].wrd := t[j].wrd+l[i]
  232.             Else
  233.                 j := j+1;
  234.         End;
  235.  
  236. End;
  237.  
  238.  
  239.  
  240.  
  241. End.
  242.  

dseligo

  • Hero Member
  • *****
  • Posts: 1653
Re: illegal expression
« Reply #1 on: March 19, 2021, 01:05:55 pm »
You program compiles without errors.

You don't call procedure 'sep' anywhere in your program. Are you sure code you sent is exactly the same as code giving you an error?

egsuh

  • Hero Member
  • *****
  • Posts: 1738
Re: illegal expression
« Reply #2 on: March 19, 2021, 01:12:41 pm »
Delete the line, type it again, and compile. There could be not displayed characters.

bytebites

  • Hero Member
  • *****
  • Posts: 778
Re: illegal expression
« Reply #3 on: March 19, 2021, 01:22:13 pm »
I and j are not initialized in function tlength.

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: illegal expression
« Reply #4 on: March 19, 2021, 01:30:19 pm »
For me, too, the program compiles without any error. Did you try a "clean" compilation, Menu "Run" > "Clean up and Build"?

MarkMLl

  • Hero Member
  • *****
  • Posts: 8533
Re: illegal expression
« Reply #5 on: March 19, 2021, 02:18:17 pm »
i have this error it says (while pointing at the last ligne)illegal expression ligne 172 col 1 while the main program is 10 lines
here is the program

Kudos for properly boxing your code but

(1) There's no need to shout.

(2) Cut-and-paste the EXACT AND COMPLETE error message.

(3) Tell us the EXACT version of FPC/Lazarus that you're running, and your operating system etc.

This sort of thing is usually caused by unexpected garbage after the expected end of a line, or an unterminated literal string or comment. Hence

(4) Trim that ridiculously long comment line and try again, but tell us if that improves it since inability to handle that might be a compiler bug.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

achref

  • New Member
  • *
  • Posts: 12
Re: illegal expression
« Reply #6 on: March 19, 2021, 02:41:57 pm »
using mypascal ide

achref

  • New Member
  • *
  • Posts: 12
Re: illegal expression
« Reply #7 on: March 19, 2021, 02:43:36 pm »
.2

MarkMLl

  • Hero Member
  • *****
  • Posts: 8533
Re: illegal expression
« Reply #8 on: March 19, 2021, 02:46:39 pm »
using mypascal ide

What version of FPC are you using?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

achref

  • New Member
  • *
  • Posts: 12
Re: illegal expression
« Reply #9 on: March 19, 2021, 02:48:30 pm »
I and j are not initialized in function tlength.
thanks i think i fixed the function  it was broken anyway ig
ty ty

achref

  • New Member
  • *
  • Posts: 12
Re: illegal expression
« Reply #10 on: March 19, 2021, 02:48:50 pm »
3.2.0 ig

MarkMLl

  • Hero Member
  • *****
  • Posts: 8533
Re: illegal expression
« Reply #11 on: March 19, 2021, 02:51:03 pm »
3.2.0 ig

OK, that helps :-)

What did you find broken in the function?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

achref

  • New Member
  • *
  • Posts: 12
Re: illegal expression
« Reply #12 on: March 19, 2021, 02:53:53 pm »
what function?/
the tlength?
didnt intialize the var i and i assigned to the boolean var using a junk value
(cuz i didnt initialize the i)
but the problem of the illegal expression is still there

achref

  • New Member
  • *
  • Posts: 12
Re: illegal expression
« Reply #13 on: March 19, 2021, 03:12:06 pm »
btw i also have the "impossible to find the unite" error even tho i checked multiple times and almost not much of difference between functionning ones
b4 i changed the names and it worked
now i change the names and still does not work

achref

  • New Member
  • *
  • Posts: 12
Re: illegal expression
« Reply #14 on: March 19, 2021, 03:20:33 pm »
note:
now im trying with a different unit
im testing to see  the function causing the problem

 

TinyPortal © 2005-2018