Author Topic: The script about “if” statement bug  (Read 8230 times)

Offline Chun Jiu

  • Multiple posting newcomer
  • *
  • Posts: 71
  • My Girlfriend
    • EasilyGCC
The script about “if” statement bug
« on: April 08, 2018, 10:43:03 am »
Test in the script console :
-----------------------------

if (1) print(_T("1")); else print(_T("2")); print(_T("3"));

or

if (1) {print(_T("1"));}  else  {print(_T("2"));}  print(_T("3"));

------------------------
Will produce an error:
------------------------

Filename: ScriptConsole
Error:end of statement expected (; or If)
Details: ScriptConsole line = (1) column = (49) : error end of statement expected (; or If)

=================

As long as the "IF" statement does not follow the statement, there will be no error.

For example:

print(_T("3"));if (1) print(_T("1")); else print(_T("2"));


====================================================

I originally wanted to insert the version number of the library file in the path, so I used the following settings.
If the project does not provide a version number variable "wx_ver", the global variable "wx.ver" is used:

The compile variable :

path_inc =

$(CODEBLOCKS)\..\..\include\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\include" -I"$(CODEBLOCKS)\..\..\lib\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\shared\dll_i686\mswu$(debug_wx)

My project build option -> search directories ->Compiler :
$(path_inc)

-------------------------------------------

No error if there is no second [[ ... ]] .

--------------------------------------------

After a lot of combination tests, I found that it was the kind of error I encountered earlier.

I couldn't add any script content after the "if" statement, otherwise it would go wrong.





I love my girlfriend like c++!    :-)

http://pan.baidu.com/s/1feNwU
easilygcc is a gmail's email.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: The script about “if” statement bug
« Reply #1 on: April 08, 2018, 11:36:12 am »
Test in the script console :
-----------------------------

if (1) print(_T("1")); else print(_T("2")); print(_T("3"));

or

if (1) {print(_T("1"));}  else  {print(_T("2"));}  print(_T("3"));

------------------------
Will produce an error:
------------------------

Filename: ScriptConsole
Error:end of statement expected (; or If)
Details: ScriptConsole line = (1) column = (49) : error end of statement expected (; or If)

=================

As long as the "IF" statement does not follow the statement, there will be no error.

For example:

print(_T("3"));if (1) print(_T("1")); else print(_T("2"));


====================================================

I originally wanted to insert the version number of the library file in the path, so I used the following settings.
If the project does not provide a version number variable "wx_ver", the global variable "wx.ver" is used:

The compile variable :

path_inc =

$(CODEBLOCKS)\..\..\include\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\include" -I"$(CODEBLOCKS)\..\..\lib\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\shared\dll_i686\mswu$(debug_wx)

My project build option -> search directories ->Compiler :
$(path_inc)

-------------------------------------------

No error if there is no second [[ ... ]] .

--------------------------------------------

After a lot of combination tests, I found that it was the kind of error I encountered earlier.

I couldn't add any script content after the "if" statement, otherwise it would go wrong.

You should copy and paste the error message, if ever possible.
The error message is:
Quote
ScriptConsole line = (1) column = (49) : error end of statement expected (; or lf)
and not
Quote
ScriptConsole line = (1) column = (49) : error end of statement expected (; or If)

It misses a linefeed (or a semicoln), not an If-statement.
If you add a semicolon after the else-clause or place curly brackets ({and}) around the whole If-statement, it works:
Code
> {if (1) {print(_T("1"));} else {print(_T("2"));}} print(_T("3"));
1
3
> if (1) print(_T("1")); else print(_T("2"));; print(_T("3"));
1
3

I assume, that only the first print belongs to the if-statement, otherwise you need to put the whole else-clause in curly-brackets.
Code
> if (1) {print(_T("1"));} else {print(_T("2")); print(_T("3"));};
1
> if (0) {print(_T("1"));} else {print(_T("2")); print(_T("3"));};
2
3

Offline Chun Jiu

  • Multiple posting newcomer
  • *
  • Posts: 71
  • My Girlfriend
    • EasilyGCC
Re: The script about “if” statement bug
« Reply #2 on: April 08, 2018, 03:42:32 pm »
Test in the script console :
-----------------------------

if (1) print(_T("1")); else print(_T("2")); print(_T("3"));

or

if (1) {print(_T("1"));}  else  {print(_T("2"));}  print(_T("3"));

------------------------
Will produce an error:
------------------------

Filename: ScriptConsole
Error:end of statement expected (; or If)
Details: ScriptConsole line = (1) column = (49) : error end of statement expected (; or If)

=================

As long as the "IF" statement does not follow the statement, there will be no error.

For example:

print(_T("3"));if (1) print(_T("1")); else print(_T("2"));


====================================================

I originally wanted to insert the version number of the library file in the path, so I used the following settings.
If the project does not provide a version number variable "wx_ver", the global variable "wx.ver" is used:

The compile variable :

path_inc =

$(CODEBLOCKS)\..\..\include\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\include" -I"$(CODEBLOCKS)\..\..\lib\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\shared\dll_i686\mswu$(debug_wx)

My project build option -> search directories ->Compiler :
$(path_inc)

-------------------------------------------

No error if there is no second [[ ... ]] .

--------------------------------------------

After a lot of combination tests, I found that it was the kind of error I encountered earlier.

I couldn't add any script content after the "if" statement, otherwise it would go wrong.

You should copy and paste the error message, if ever possible.
The error message is:
Quote
ScriptConsole line = (1) column = (49) : error end of statement expected (; or lf)
and not
Quote
ScriptConsole line = (1) column = (49) : error end of statement expected (; or If)

It misses a linefeed (or a semicoln), not an If-statement.
If you add a semicolon after the else-clause or place curly brackets ({and}) around the whole If-statement, it works:
Code
> {if (1) {print(_T("1"));} else {print(_T("2"));}} print(_T("3"));
1
3
> if (1) print(_T("1")); else print(_T("2"));; print(_T("3"));
1
3

I assume, that only the first print belongs to the if-statement, otherwise you need to put the whole else-clause in curly-brackets.
Code
> if (1) {print(_T("1"));} else {print(_T("2")); print(_T("3"));};
1
> if (0) {print(_T("1"));} else {print(_T("2")); print(_T("3"));};
2
3


Thank you!

I did not notice the difference between "if" and "lf"!

=============================
$(CODEBLOCKS)\..\..\include\wxWidgets\[[local v_1=ReplaceMacros(_T("$(wx_ver)")); local s_1=ReplaceMacros(_T("$(#wx.ver)")); if (!(v_1.IsEmpty() || v_1.len()<3)) print(s_1); else print(v_1);]]\include
=============================

I used the "print" statement in the options script may have generated unnecessary LF, so I got an error.

I continue to study how to generate the required complete compilation symbol string without the LF.
I love my girlfriend like c++!    :-)

http://pan.baidu.com/s/1feNwU
easilygcc is a gmail's email.