Author Topic: Bug with UDT Memory Allocation?  (Read 2548 times)

0 Members and 1 Guest are viewing this topic.

Mike Lobanovsky

  • Guest
Bug with UDT Memory Allocation?
« on: May 25, 2014, 11:07:54 AM »
Hello Charles,

The following code crashes vigorously for me. Why should it?

Code: [Select]
type key_words
keyword as string
sym as long
end type

const as long MAX_KEYWORDS = 13

dim key_words_tab(MAX_KEYWORDS) as key_words

const as long sym_unknown = 0, sym_eoi = 1, sym_string_const = 2, sym_lparen = 3, sym_rparen = 4
const as long sym_multiply = 5, sym_plus = 6, sym_comma = 7, sym_minus = 8, sym_divide = 9
const as long sym_integer_const = 10, sym_ident = 11, sym_print = 12, sym_while = 13
const as long sym_do = 14, sym_end = 15, sym_halt = 16, sym_if = 17, sym_then = 18
const as long sym_else = 19, sym_integer_var = 20, sym_equal = 21, sym_mod = 22, sym_or = 23
const as long sym_and = 24, sym_neq = 25, sym_lss = 26, sym_leq = 27, sym_gtr = 28
const as long sym_geq = 29, sym_neg = 30, sym_not = 31, sym_whtspc = 32

dim as string codebuf = "bla bla bla"

sub init_lex()
key_words_tab( 1).sym = sym_and
key_words_tab( 2).sym = sym_do
key_words_tab( 3).sym = sym_else
key_words_tab( 4).sym = sym_end
key_words_tab( 5).sym = sym_halt
key_words_tab( 6).sym = sym_if
key_words_tab( 7).sym = sym_integer_var
key_words_tab( 8).sym = sym_mod
key_words_tab( 9).sym = sym_not
key_words_tab(10).sym = sym_or
key_words_tab(11).sym = sym_print
key_words_tab(12).sym = sym_then
key_words_tab(13).sym = sym_while

key_words_tab( 1).keyword = "and"
key_words_tab( 2).keyword = "do"
key_words_tab( 3).keyword = "else"
key_words_tab( 4).keyword = "end"
key_words_tab( 5).keyword = "halt"
key_words_tab( 6).keyword = "if"
key_words_tab( 7).keyword = "integer"
key_words_tab( 8).keyword = "mod"
key_words_tab( 9).keyword = "not"
key_words_tab(10).keyword = "or"
key_words_tab(11).keyword = "print"
key_words_tab(12).keyword = "then"
key_words_tab(13).keyword = "while"
end sub

init_lex
print codebuf

Aurel

  • Guest
Re: Bug with UDT Memory Allocation?
« Reply #1 on: May 25, 2014, 03:24:36 PM »
Maybe i am wrong
but i think that problem might be in
dim key_words_tab[MAX_KEYWORDS] as Key_words
i see this problem before and i think that oxygen dont like litteral
variable index when is declared,maybe something :
dim key_words_tab[13] as Key_words

Mike Lobanovsky

  • Guest
Re: Bug with UDT Memory Allocation?
« Reply #2 on: May 25, 2014, 03:43:30 PM »
Charles,

Is there any preference as to how Oxygen arrays should be indexed: [] or ()?

Charles Pegge

  • Guest
Re: Bug with UDT Memory Allocation?
« Reply #3 on: May 25, 2014, 03:55:06 PM »
Mike,

Just looking at your code with the string member, this is the bug I fixed yesterday.

You can use (..) or [..] with arrays generally, but when making C style declarations, square brackets have to be used to distinguish an array from a function declaration.

int a[4]

int f(...)


http://www.oxygenbasic.org/o2zips/Oxygen.zip

Mike Lobanovsky

  • Guest
Re: Bug with UDT Memory Allocation?
« Reply #4 on: May 25, 2014, 04:02:11 PM »
No way Charles,

Doesn't work for me with the new Oxygen.dll and this script either way, [] or (). :-\

But if I change [MAX_KEYWORDS] to literal [13] as Aurel says, it works!  :o