CONST errors

Questions about the BASICtools and MakeItC
olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

CONST errors

Post by olzeke51 »

using win10, ARMbasic[9.37m] and BASICtools[6.00] that I downloaded/installed today.
getting this error - even though the Stamp_Pins.bas CONST assignments worked!!
'
Compiling C:/Users/Zwanster/AppData/Local/Temp/Coridium/prot0-dice.bpp

CONST num0 = {segA, segB, segC, segD, segE, segF}
-ERROR C:/Users/Zwanster/DOCUME~1/Coridium/prot0-dice.bas: 37: Expected a Constant

CONST num1 AS BYTE = {segB, segC}
-ERROR C:/Users/Zwanster/DOCUME~1/Coridium/prot0-dice.bas: 38: Expected a Constant

******************************************************** SUPPORTING INFO **************
**MY PROGRAM SNIPPETS

Code: Select all

' Testing routines with 3 7-segment LEDs common cathode
'
#include <LPC11U3x.bas>
'
' DEFINES  - redefine with Production PCB!!
' segments
CONST segA = SP35
CONST segB = SP27
'.....
CONST num0 = {segA, segB, segC, segD, segE, segF}
CONST num1 AS BYTE = {segB, segC}
CONST num2 AS BYTE = {segA,segB,segG,segE,segD}
'...
'
'
****** user/AppData/Local/Temp/Coridium files *******
__errors.tmp is EMPTY
__temp.bas hhas the following ****

Code: Select all

string of HEX numbers
[u]Your Stamp_Pins.bas    <b> CONST is shown !!!!</b>[/u]
'
# 112 "C:/Users/Zwanster/Documents/Coridium/BASIClib/STAMP_PINS.bas"
CONST SPINS = {2, 52, 21, 56, 7, 63, 8, 22,
               61, 12, 45, 54, 16, 23, 17, 57,......
'
'
'               
[i]then my program :*******[/i]
CONST segA = 15
CONST segB = 60
CONST segC = 1    and a bunch more   ** so are getting defined****
'
'
[u]then this -- what is #54 ??  ...it isn't line 54 per my numbered program lines[/u]
'
CONST num0 = {segA, segB, segC, segD, segE, segF}
CONST num1 AS BYTE = {segB, segC}
CONST num2 AS BYTE = {segA,segB,segG,segE,segD}
CONST num3 AS BYTE = {segA,segB,segG,segC,segD}
CONST num4 AS BYTE = {segF,segG,segB,segC}
CONST num5 AS BYTE = {segA,segF,segG,segC,segD}
CONST num6 AS BYTE = {segA,segF,segG,segC,segD,segE}
# 54 "C:/Users/Zwanster/DOCUME~1/Coridium/prot0-dice.bas"
CONST die1 AS BYTE ={segG}



olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: CONST errors

Post by olzeke51 »

If I replace the CONST with #define -- no errors on those lines!!!
updated my basic to [6.02d] thanks to @jepalza

Code: Select all

#define NUM0 = {segA, segB, segC, segD, segE, segF}
#define num1 AS BYTE = {segB, segC}
'
it appears that CONST arrays may be an issue

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: CONST errors

Post by basicchip »

The current BASIC compiler is not smart enough to know that segA is a constant in your use case

Code: Select all

CONST sega = 5
CONST segb =7
CONST lista = {segA, segB}
So this is a compiler feature, will it get fixed, its on the list. But there are lots of work arounds like #define

olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: CONST errors

Post by olzeke51 »

another 'clue' ??
I replace the CONST arrays with #define arrays so they didn't fail or generate a compiler message
It looks like #define has issues with AS BYTE arrays
but now

OUT(AS BYTE ={9,10,8}(X))=1
-ERROR C:/Users/Zwanster/DOCUME~1/Coridium/prot0-dice.bas: 72: Expected Operand

NEXT
-ERROR C:/Users/Zwanster/DOCUME~1/Coridium/prot0-dice.bas: 73: NEXT Without FOR

OUT(AS BYTE ={11,13}(X))=0
-ERROR C:/Users/Zwanster/DOCUME~1/Coridium/prot0-dice.bas: 76: Expected Operand
'
here is the corresponding code:

Code: Select all

'
#define pinsK AS BYTE ={SP29,SP7,SP6}
#define pinsDP AS BYTE ={SP31,SP32}
#define pinsSEG AS BYTE ={SP35,SP27,SP12,SP8,SP30,SP5,SP13}
'
DIM Valu, R, M
'
'***************** SUBROUTINES
'
clearDISP:
DIM X
' clear cathode
FOR X = 0 TO 2
	OUT(pinsK(X))=1	<<<line 72
NEXT

' clear DP datapoints
FOR X = 0 TO 5
	OUT(pinsDP(X))=0	<<<line 76
NEXT

' clear SEGments
FOR X = 0 TO 5
	OUT(pinsSEG(X))=0
NEXT
RETURN
'
changed two lines of code but I still get the whole BYTE array in the error message
Valu = AS BYTE ={9,10,8}(X)
-ERROR C:/Users/Zwanster/DOCUME~1/Coridium/prot0-dice.bas: 72: Expected Operand

Code: Select all

FOR X = 0 TO 2
	Valu =	pinsK(X)
	OUT(Valu)=1 <<<<***was line 72
NEXT
'
It looks like #define has issues with AS BYTE arrays

olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: CONST errors

Post by olzeke51 »

Bascichip wroted:
So this is a compiler feature, will it get fixed, its on the list. But there are lots of work arounds like #define
'
its not the single CONST that appears to be the issue,
its the CONST arrays
'
and the #define doesn't seem to handle arrays - as I get weird assignments in my OUT statement
when I try to pick one element of the array.

Workaround - looks like I will have to do manual arrays
Good thing the ARMstamp has lots of room

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: CONST errors

Post by basicchip »

STAMP_PINS.bas has a working CONST array declaration, so check that syntax.

olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: CONST errors

Post by olzeke51 »

Basicchip wrote:
STAMP_PINS.bas has a working CONST array declaration, so check that syntax.
'
I did earlier , and again now. STAMP_PINS also worked as 'AS BYTE' array - BTW
copied it to my program, PUT in my "segA" and it fails, SPx values are okay
'
it looks like ...?? my CONST array doesn't see my previous CONST segA = SP35 assignment
but the __test.bpp file shows "segA" being assign to "15" [SP35]
?? so a later CONST appears to not be able to acquire/use/reference an earlier CONST??
**************
EDIT - NOPE!!!! I did get the #define AS BYTE to work -- I left the "=" sign in the statement when I
JUST no error messages'replaced' CONST iwth #define
*******
I have replaced my earlier CONST to #define for the "segA" values --and it is well at that point

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: CONST errors

Post by basicchip »

Your are mixing C pre-processor and BASIC and getting ???

#define is handled by the C-pre-processor

#define AS BYTE

will replace all AS in the BASIC source with BYTE, which is definitely not what you want.

AS BYTE is a modifier for BASIC DIM statements.

In the help files there is the 90 page reference to what #defines in the C pre-processor does, written by Red Hat, or lots of examples on the web about the C pre-processor

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: CONST errors

Post by basicchip »

And I called the bug ie. feature of the BASIC compiler that

Code: Select all

CONST a = 1
CONST b = 2
CONST c = {a,b}  ' fails
Because right now the BASIC compiler does not recognize that a and b have been defined as constants. On the list of things to fix, but there are lots of ways to get around it. It was something I never thought someone would do.

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: CONST errors

Post by basicchip »

For BASIC, compiling is a 2 step process.

The source code is read by the C-pre-processor and those transformations are applied. This includes #define, #ifdef, #if...

The C pre-processor just replaces some text with some other text. Or drops/inserts text between #if #endif. It really does no error checking only reporting files it can't find in a #include or some expression errors in #if

I typically use #define for simple constants. Why because I have been writing C for 30 some years and I'm use to it. Is there any reason to use it over CONST? Not really, except CONST declarations do consume symbol table space, not that there are any real limits on the PC.

The output of the pre-processor is Your_Souce.bpp kept in %temp%\coridium directory.

That .bpp source is then compiled by the ARMbasic compiler, that outputs an expanded hexfile. Hex data is the compiled BASIC and written into flash. But it also has some comments on compiler version and program size. In addition there is symbol table information that is used by BASICtools to dump variables.

Post Reply