Results 1 to 9 of 9

Thread: array question

  1. #1
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    52
    Posts
    944
    Rep Power
    111

    array question

    what's the difference between "dim heroes(10) as string" and "dim heroes as string" in parsing technology? for me it would be great to get more info about that one. you can't use both in my example "heroes(10)" and simple "dim heroes as string", but why don't thinbasic makes that important different?

    ' Empty GUI script created on 05-02-2012 10:14:40 by  (ThinAIR)
    
        Dim heroes(10) As String
        'Dim heroes As String ' variable name already exist (duplicated generic)
        ' heroes = "black widow"
        
        heroes(1) = "THOR "
        heroes(2) = "HULK "
        heroes(3) = "CAPTAIN AMERICA "
        MsgBox 0, heroes(1) +  heroes(2) + heroes(3)
        'MsgBox 0, heroes
    
    '    
    ' my question: 'heroes(10)' is an own variable type and 
    ' has to define extra in 'dim variableArray() as string' 
    ' And has his own assignment ?
    ' what's the difference in parsing between normal varialbe like 'heroes' and
    ' array type like 'heroes(10)' ?                                                                                                                
    ' 
    ' I thought that 'heroes(10)' and "heroes" as variable type must be entirely different things!? :)
    
    best regards, frank
    Attached Files Attached Files
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    Frank,

    in all languages variable names must be unique inside each scope (scope means: Global, Functions, blocks, ...) .
    For this reason heroes(10) and heroes inside the same scope are the same name so they cannot represent different things.
    The variable is named heroes.

    But your question is quite interesting because in reality if used in different ways (one is an array, the other is a scalar variable) it could be possible to identify what is what.
    But what could be the problem? The code would be much more "Error prone" because it would be impossible to understand if you are using wrongly or correctly the term heroes: are you using as scalar or as array? Ho can the parser or the interpreter be sure?

    From an internal point of view, the 2 variables are completely different.
    • A dynamic string in thinBasic is 4 bytes pointer that points to an 8 bytes (2 LONGs) memory area used to store string length (in the first LONG) and a pointer (second LONG) to a dynamic allocated area that contains the real string.
    • A dynamic array (arrays can shrink or increase) of dynamic strings is very similar but a little more complicated.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    52
    Posts
    944
    Rep Power
    111
    thank you for this infos eros. my added question: is if you are using for dynamic string (dynamic array) an own dimension? (new assignment and new add_variable function?) I've tested this for my own project and only the scalar variable works fine, but I think I have to add a new key ("add_key", dictionary module) to that dynamic string and parsed this too, but the result is empty here for example for

    dim heroes(10) as string
    heroes(1) = "batman"

    variable type in my case included for example such thing "stringArray() as string*length" and I added a new key to that dynamic array, but the message box is empty, there is no returning a value or in my case the word "batman". hard stuff, but I think I am on the right way, but some parts are missing to get right result.

    thanks, frank
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    Dim heroes(10) As String
    heroes(1) = "batman"
    
    MsgBox 0, heroes(1)
    
    The above code is perfectly working so I'm sure I'm missing something here.

    Are you talking about:
    1. thinBasic scripts
    2. developing thinbasic modules
    They are two completely different worlds and if I do not get what you are talking about I will reply in the wrong way.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    I think Frank is asking about redim

  6. #6
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    52
    Posts
    944
    Rep Power
    111
    thank you both, my interests concerned primalary to "dynamic arrays" and how to parse a complicated thing like "dim heroes(1 to 10) as string" and give the right result. I am thinking a) about my module "fundialox" and b) my own interpreter project ("funbasic") and dived onto the ground (looking at bint32 examples) and I have understand how to set the string value (dim_array) and saw the variable structures working here well too.

    now I am asking if it's possible to create an own dynamic array for my "fundialox module" without using thinbasic power and I wanted to understand how that's working to detect that "dim heroes(1 to 10) as string" is an array and not a single string value (scalar). I have managed to detect that there is an array but not more. for "heroes(1) = "hulk" (for example) to get the right result "hulk" from a dynamice string that's my main problem here.

    it's necessary to change the varialbe type for a dynamic array like "dim heroes(1 to 10) as string" ? there are a lot of questions here. "redim" wasn't my problem charles sorry for unclear words or question.

    dim heroes(1 to 10) as string
    heroes(1) = "hulk"
    heroes(2) = "captain america"
    heroes(3) = "ironman"
    ...
    msgbox 0, heroes(1)
    msgbox 0, heroes(2)
    ..
    
    thanks, nice day, frank
    Last edited by Lionheart008; 04-05-2012 at 17:48.
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    Frank,

    writing a tokenizer/parser/interpreter is not something trivial

    I suggest to have a look at my old interpreter called BINT32. You can find it at: http://www.thinbasic.com/index.php?o...tegory&catid=6
    It contains full PowerBasic source code and can be used to get started.
    BINT32 parser is built using "Recursive descendant parser" technique: http://en.wikipedia.org/wiki/Recursive_descent_parser

    You can find many examples on the web using different languages: https://www.google.com/#hl=en&sugexp...&bih=1019&bs=1

    thinBasic itself is built over the same technique but more advanced.

    There is quite a lot to study and master but if you get it I'm sure you will get a lot of satisfactions


    Another option could be to get Charles Oxygen language and study its source code.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #8
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348
    A very good tool create a parser is Coco/R which I have used personally too. And the lecture that got me started by coding a parser by hand was Jack Crenshaws "Let's build a compiler" tutorials.

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    Very interesting lecture Michael.
    I didn't know that document (here attached for convenience)
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. Array question
    By TheOne in forum Tips and Tricks
    Replies: 5
    Last Post: 10-05-2013, 12:29
  2. array question multiple assignment
    By Lionheart008 in forum thinAir General
    Replies: 2
    Last Post: 19-03-2012, 10:21
  3. Using MAT on an array within a Union
    By dcromley in forum Core module
    Replies: 5
    Last Post: 09-04-2009, 11:51
  4. ARRAY SHUFFLE??
    By marcuslee in forum Core module
    Replies: 18
    Last Post: 07-09-2008, 05:30

Members who have read this thread: 1

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •