Recent

Author Topic: Illegal expression error  (Read 14731 times)

pashbrown

  • New Member
  • *
  • Posts: 25
Illegal expression error
« on: September 21, 2012, 01:15:05 pm »
Code: [Select]
calculation[first[x]..last[x]]:=floattostr(answer);
Calculation is a string. First and last are integers, x is an integer, answer is real. I get the 'illegal expression' error, not sure why, please halp
« Last Edit: September 21, 2012, 05:15:07 pm by pashbrown »
Cruse™ Powered

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Illegal expression error
« Reply #1 on: September 21, 2012, 05:33:50 pm »
1) you can't use a range of characters like that. eg. Calculations[5] is ok Calculations[1..100] is not
2) floattostr returns a string you can't assign a string to a character. eg Calculation := floatToStr(answer) is ok Calculation[10] := floatToStr(answer)[2] is ok too but Calculation[10] := floatToStr(answer) is not ok.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Bart

  • Hero Member
  • *****
  • Posts: 5288
    • Bart en Mariska's Webstek
Re: Illegal expression error
« Reply #2 on: September 21, 2012, 05:34:36 pm »
My compiler crashes when trying to compile similar code (which b.t.w. is illegal pascal).

Code: [Select]
program test;

{$mode objfpc}
{$h+}

var
  s: string;

begin
  s[1..3] := '123';
end.

Code: [Select]
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>fpc test.pas
Free Pascal Compiler version 2.6.0 [2011/12/25] for i386
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.pas
test.pas(10,3) Warning: Variable "s" does not seem to be initialized
Fatal: Compilation aborted
An unhandled exception occurred at $00409E9A :
EOutOfMemory : Out of memory
  $00409E9A
  $0040A1E9
  $004A5ADF
  $0043FB40
  $004A1E37
  $0043FB40
  $004DC1C7
  $004D4C3E
  $0042FA0B
  $0041165D

Error: C:\devel\fpc\bin\i386-Win32\ppc386.exe returned an error exitcode (normal
 if you did not specify a source file to be compiled)

Bart

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Illegal expression error
« Reply #3 on: September 21, 2012, 05:38:28 pm »
@Bart interesting. FPC 2.6.1 x86 and FPC trunk x86 on Windows... seems there's some improvements in trunk :)

Code: [Select]
Free Pascal Compiler version 2.6.1 [2012/09/21] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.pas
test.pas(10,3) Warning: Variable "s" does not seem to be initialized
Fatal: Compilation aborted
An unhandled exception occurred at $00409E3A :
EOutOfMemory : Out of memory
  $00409E3A
  $0040A189
  $004A68EF
  $004406E0
  $004A2C47
  $004406E0
  $004DD257
  $004D5C8E
  $0043058B
  $004115ED

Error: c:\Development\Fpc\bin\i386-win32\ppc386.exe returned an error exitcode (normal if you did not specify a source file to be compiled)

D:\Cop\t>fpcdev test.pas
Free Pascal Compiler version 2.7.1 [2012/09/21] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.pas
test.pas(10,3) Warning: Variable "s" does not seem to be initialized
Fatal: No memory left
Error: c:\development\fpctrunk\bin\i386-win32\ppc386.exe returned an error exitcode
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Bart

  • Hero Member
  • *****
  • Posts: 5288
    • Bart en Mariska's Webstek
Re: Illegal expression error
« Reply #4 on: September 21, 2012, 05:51:04 pm »
Reported as bug #22941

Bart

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Illegal expression error
« Reply #5 on: September 22, 2012, 10:20:04 am »
Bug was fixed in FPC trunk by Jonas Maebe:
Code: [Select]
Free Pascal Compiler version 2.7.1 [2012/09/22] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.pas
test.pas(10,3) Warning: Variable "s" does not seem to be initialized
test.pas(10,9) Error: Illegal expression
test.pas(12) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: c:\development\fpctrunk\bin\i386-win32\ppc386.exe returned an error exitcode

Thanks,
BigChimp
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Bart

  • Hero Member
  • *****
  • Posts: 5288
    • Bart en Mariska's Webstek
Re: Illegal expression error
« Reply #6 on: September 22, 2012, 05:48:58 pm »
@BigChimp: Thanks for testing. I only have stable fpc.
I closed the bugreport.

Bart

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Illegal expression error
« Reply #7 on: September 22, 2012, 05:50:38 pm »
@Bart: perhaps a good idea to download trunk? That would certainly help when reporting bugs...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018