Forum
AttributeError: 'SymbolSTRSLICE' object has... (*solved*) - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15)
+---- Thread: AttributeError: 'SymbolSTRSLICE' object has... (*solved*) (/showthread.php?tid=203)



AttributeError: 'SymbolSTRSLICE' object has... (*solved*) - programandala.net - 04-18-2010

For the second time, I get the following output (version 1.2.5):

Quote:marcos$ zxb.py --tap --autorun --BASIC --sinclair colegio_erevest_4.bas
Generating LALR tables
Generating LALR tables
WARNING: Token 'UMINUS' defined, but not used
WARNING: There is 1 unused token
Traceback (most recent call last):
File "/home/marcos/bin/zxb.py", line 255, in <module>
sys.exit(main(sys.argv)) # Exit
File "/home/marcos/bin/zxb.py", line 203, in main
zxbtrad.traverse(zxbtrad.FUNCTIONS) # This will fill MEMORY with pending functions
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 250, in traverse
traverse(l)
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 959, in traverse
traverse(i)
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 257, in traverse
traverse(i)
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 770, in traverse
traverse(tree.next[1])
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 720, in traverse
traverse(tree.next[0])
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 1004, in traverse
traverse(tree.next[i])
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 1008, in traverse
traverse(tree.next[0])
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 569, in traverse
traverse(tree.next[0])
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 375, in traverse
traverse(tree.next[0])
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 530, in traverse
if tree.next[0].token != 'STRING' and tree.next[0].token != 'ID' and tree.next[0].symbol._mangled[0] != '_':
AttributeError: 'SymbolSTRSLICE' object has no attribute '_mangled'

I've searched for "mangled" in the forums, but there's no message about it.

It seems it happens when no more syntax errors are found in the source, but I'm not sure. Any clue? Is it a compiler issue or is it caused by my program?


Re: AttributeError: 'SymbolSTRSLICE' object has no attribute '_m - boriel - 04-18-2010

You should paste the code snippet producing this error, if possible. If you want your code not disclosed for whatever reason, please send it to me in a private message.


Re: AttributeError: 'SymbolSTRSLICE' object has no attribute '_m - programandala.net - 04-18-2010

boriel Wrote:You should paste the code snippet producing this error, if possible. If you want your code not disclosed for whatever reason, please send it to me in a private message.

No snippet... the program has more than 1500 lines Smile

I'll try to figure out what's the wrong piece and I will post it.


Re: AttributeError: 'SymbolSTRSLICE' object has no attribute '_m - programandala.net - 04-18-2010

More clues:

It happens with 1.2.5 and 1.2.6.

It seems it happens when there are no more syntax errors in the code, but warnings don't make any difference: If I add a final line at the bottom of the source, to force a warning, the error happens anyway; but if the line creates a syntax error, the error doesn't happen. So it seems something is wrong in the next step, after the parsing.

I'll comment out chunks of code, in order to find out any difference.


Re: AttributeError: 'SymbolSTRSLICE' object has no attribute '_m - programandala.net - 04-18-2010

I've found out the line that caused the compiling error:

Code:
let ending = genderEnding(val(genderTypes(thing-firstPortableThing+1)))

In fact the same calculation is used in two functions, with the same effect.

The context is:

Code:
dim genderEnding(1 to 3) as string
dim genderTypes as string

let genderTypes="12333131333" ' gender type for every portable thing
let genderEnding(1)="A" ' ending for gender type 1
let genderEnding(2)="AS" ' ending for gender type 2
let genderEnding(3)="" ' ending for gender type 3 (or "O", calculated in the function)

function undefinedArticleEnding(thing as ubyte) as string

    dim ending as string

    let ending = genderEnding(val(genderTypes(thing-firstPortableThing+1)))

    return ending

end function

I isolated the function and the needed DIMs into another file, to debug it. Here you are the results, in chronological order. Every try is marked "!!!ERROR" or "!!!fine and then commented out:

Code:
dim genderEnding(1 to 3) as string
dim genderTypes as string

let genderTypes="12333131333" ' gender type for every portable thing
let genderEnding(1)="A" ' ending for gender type 1
let genderEnding(2)="AS" ' ending for gender type 2
let genderEnding(3)="" ' ending for gender type 3 (or "O", calculated in the function)

function undefinedArticleEnding(thing as ubyte) as string

    dim ending as string

    ' let ending = genderEnding(val(genderTypes(thing-firstPortableThing+1))) ' !!!ERROR

    ' let ending = genderEnding(val(genderTypes(thing-firstPortableThing))) ' !!!ERROR

    ' let ending = "O" ' !!!fine

    ' let ending = genderEnding(val(genderTypes(thing))) ' !!!ERROR

    ' let ending = genderEnding(1) ' !!!fine

    ' let ending = genderEnding(val("1")) ' !!!fine

    ' let ending = genderEnding(val(genderTypes(1))) ' !!!ERROR

    ' let ending = genderEnding(val(genderTypes(0))) ' !!!ERROR

    ' let ending = genderEnding(val("0")) ' !!!fine, a different error: out of range

    ' In parts !!ERROR    
    ' dim gt as ubyte
    ' let gt = val(genderTypes(1))
    ' let ending = genderEnding(gt)
    
    ' In parts !!!fine
    ' dim gt as ubyte
    ' let gt = val("1")
    ' let ending = genderEnding(gt)

    ' In parts !!!fine
    ' dim gt as ubyte
    ' dim gs as string
    ' let gs = "1"
    ' let gt = val(gs)
    ' let ending = genderEnding(gt)

    ' In parts !!!fine
    ' dim gt as ubyte
    ' dim gs as string
    ' let gs = genderTypes(1)
    ' let gt = val(gs)
    ' let ending = genderEnding(gt)

    ' In parts !!!fine
    dim gs as string
    let gs = genderTypes(1)
    let ending = genderEnding(val(gs))

    return ending

end function

I don't understand what's wrong in the code. I suspect it's a compiler issue. I think it has something to do with nesting, don't you think so?


Re: AttributeError: 'SymbolSTRSLICE' object has no attribute '_m - boriel - 04-18-2010

programandala.net Wrote:I don't understand what's wrong in the code. I suspect it's a compiler issue. I think it has something to do with nesting, don't you think so?
Your code is Ok! :!: It was a compiler bug and has been fixed. Please download 1.2.6r1542b and install.
And please, CHECK the compiler is now working. The problem was in the VAL function:
Code:
REM This code crashes the compiler if version < 1.2.6
LET a$ = "TEST"
PRINT VAL(a$(1))
Download link: <!-- m --><a class="postlink" href="http://www.boriel.com/files/zxb/zxbasic-1.2.6r1542b.msi">http://www.boriel.com/files/zxb/zxbasic-1.2.6r1542b.msi</a><!-- m -->


Re: AttributeError: 'SymbolSTRSLICE' object has no attribute '_m - programandala.net - 04-19-2010

boriel Wrote:Your code is Ok! :!: It was a compiler bug and has been fixed. Please download 1.2.6r1542b and install.
And please, CHECK the compiler is now working. The problem was in the VAL function:

Now it works fine. Thank you. I have succeeded in compiling my large program by the first time! No warning, no error, no message. It's great. The only inconvenience is the need to put some string functions at the top of the source.

boriel Wrote:Download link: <!-- m --><a class="postlink" href="http://www.boriel.com/files/zxb/zxbasic-1.2.6r1542b.msi">http://www.boriel.com/files/zxb/zxbasic-1.2.6r1542b.msi</a><!-- m -->

It seems the tar.gz is corrupted. I could'nt open it. I used the .zip instead.