Recent posts

#1
OxygenBasic Examples / Parser example and question
Last post by Frank Brübach - Today at 11:47:09 PM
Hello Charles..

Perhaps you can Help to Fix my freebasic Translation to oxygen. My freebasic example is running fine.

I am Not quite Sure how to handle String Tokens() and my Error or Problem zones I have marked in my o2 example. Thanks in advance, frank


' test of my parser example of freebasic (its running fine there)
' to oxygen by frank bruebach, 24-06 + 25-06-2024
'
uses console

' test -------------------------
dim tokens() as string
Dim token As String = ""
Dim tokenCount As Integer = 0 '
ReDim string tokens(tokenCount) '
' test -------------------------

printl "ok"   


' Split() function ' may be an error inside cause of tokens() ?
Function Split(string inputs, delimiter, tokens() ) As Integer
    Dim token As String = ""
    Dim tokenCount As Integer = 0
    int i
    For i = 1 To Len(inputs)
        If Mid(inputs, i, 1) = delimiter Then
            If token <> "" Then
                'ReDim Preserve tokens(0 To tokenCount)
                ReDim string tokens(tokenCount) 'redim string s(n)
                tokens(tokenCount) = token
                tokenCount += 1
                token = ""
            End If
        Else
            token += Mid(inputs, i, 1)
        End If
    Next
    If token <> "" Then
        ReDim string tokens(tokenCount)
        tokens(tokenCount) = token
    End If

    Return tokenCount
End Function

printl "ok2"

' IsNumeric() function ok
Function IsNumeric(string value ) As Integer
    Static string numericChars
    numericChars = "0123456789.-"
    If Len(value) = 0 Then Return False
    int i
    int dotCount = 0
    For i = 1 To Len(value)
        string c = Mid(value, i, 1)
        If InStr(numericChars, c) = 0 Then
            Return False
        ElseIf c = "." Then
            dotCount += 1
            If dotCount > 1 Then
                Return False
            End If
        End If
    Next

    Return True
End Function

printl "ok3"

' new build in: EvaluateExpression function
' error inside split() functions
'
Function EvaluateExpression(string inputs) As Double
    Dim tokens() As String

'------------------ problem zone 1 ------------ //
    Split(inputs," ", tokens())
'------------------ problem zone 1 ------------ //

    Dim total As Double = 0
    Dim currentNumber As Double = 0
    Dim operators As String = "+"
    int i
    For i = 0 To UBound(tokens)
        Dim token As String = tokens(i)

        If IsNumeric(token) Then
            currentNumber = Val(token)
            If operators = "+" Then
                total += currentNumber
            ElseIf operators = "-" Then
                total -= currentNumber
            ElseIf operators = "*" Then
                total *= currentNumber
            ElseIf operators = "/" Then
                If currentNumber <> 0 Then
                    total /= currentNumber
                Else
                    Print "Error: Division by zero"
                    Exit For
                End If
            End If
            operators = "+"
        Else
            operators = token
        End If
    Next

    Return total
End Function

printl "ok4"


' Test my code with different inputs
Dim inputs As String = "2 + 3 * 10" ' 50 result ok
Dim result As Double

'------------------------ problem zone 2 ------------- //
' result = EvaluateExpression(inputs) ' error
'------------------------ problem zone 2 ------------- //

' all tests are running fine here for calculations
' + - * /
' Test my code with different inputs
' Dim inputs As String = "2 + 3 * 10" ' 50 ok
' Dim inputs As String = "5 + 6 + 10" ' 21 ok
' Dim inputs As String = "8 * 5" ' 40 ok
' Dim inputs As String = "20 / 4 " ' 5 ok
' Dim inputs As String = "-20 10" ' -10 ok
' Dim inputs As String = "-10  20" ' ok
 Dim inputs As String = "30 -20" ' 10 ok 


If result <> 0 Then
    Printl "The total is " + result
Else
    Printl "Error: Invalid input"
End If

printl result 'test was 0

' Wait for a key press before closing the console
Printl "Press any key to continue..."
'Sleep
wait
'While Inkey <> "" : Wend

print "ok5"
#2
OxygenBasic / Re: sprintf / sprintf_s in 64-...
Last post by Charles Pegge - Yesterday at 08:58:52 PM
To match the %f sprintf specification, your diameter variable must be a double, and it must be cast (quad) as previously.

This is certainly an edge-case for unprototyped calls :)
#3
🚀 Exciting news for coders!
The new Claude 3.5 model is a game-changer for PowerBASIC, Assembler, and PureBasic programming! 💻✨

Key advantages:

🧠 Enhanced understanding of complex code structures
🔍 Improved code analysis and debugging assistance
💡 More accurate and context-aware code suggestions
📚 Expanded knowledge base for obscure language features
🔧 Better optimization recommendations for efficiency
🌐 Improved integration of multiple language paradigms

Whether you're crafting tight assembly routines, leveraging PowerBASIC's simplicity, or building robust applications in PureBasic, Claude 3.5 is here to supercharge your coding experience! 💪

From my standpoint, GPT-4 was most often the best support for coding - until now!
The new Model from Anthropic beats GPT-4 single-handed.
It makes complete, nearly bug free code - for example in x86 Assembler - often ready to compile.
It will uphold the programming style that you show in samples and the Focus-Window is large enough for complete include files!

Example use?
It can convert Include files, search for bugs, change code.
Design complete Subprograms. Like before only humans did that.

Has anyone tried it yet? Share your experiences below! 👇

Try it:
Anthropic Claude-3-5-sonnet-20240620
#4
OxygenBasic / Re: sprintf / sprintf_s in 64-...
Last post by Roland Stowasser - Yesterday at 05:00:34 PM
Maybe I can use this strategy, which works in 32-bit and 64-bit mode and it does not interfere with the original Msvcrt.inc file:

$filename "test_sprintf.exe"

'uses rtl32
uses rtl64

uses corewin
uses console

#ifdef mode64bit
! sprintf   lib "msvcrt.dll" (char *buffer, const char *format, ...) as sys
! sprintf_s lib "msvcrt.dll" (char *buffer, int size, const char *format, ...) as sys
#endif

SetConsoleTitle "sprintf / sprintf_s Examples"
double num
char buff[64]

num = 333 * 1.5
sprintf (buff, "%.2f", num)
printl "333*1.5 = " buff

num = 100 / 13
sprintf_s (buff,64, "%.4f" , num)
printl "100/13 = "buff

printl
printl
double my_pi = pi
sprintf (buff, "Value of pi = %.2f", pi)
printl buff
sprintf (buff, "Value of my_pi = %.2f", my_pi)
printl buff

int arg1 = 27, arg2 = 9, result
result = arg1 * arg2
sprintf(buff, "When %d is multiplied with %d the result is: %d", arg1, arg2, result)
printl buff

int age = 30
double height = 1.75
string name = "John"
sprintf(buff, "%s is %d years old and %.2f meters tall.", name, age, height)
'Result: "John is 30 years old and 1.75 meters tall."
printl buff

int diameter = 10
sprintf (buff, "Circumference: %d * %.3f = %.2f", diameter, pi, diameter * pi)
printl buff

printl
printl "Enter ..."

waitkey

#5
OxygenBasic / Re: sprintf / sprintf_s in 64-...
Last post by Roland Stowasser - Yesterday at 03:36:57 PM
Hi Charles,

this is really curious. If I use (quad) num, I can use sprintf unprototyped. But (quad)pi does not work. I have to define: double my_pi = pi and  (quad)my_pi to get the correct result.

I tried these statements:

int diameter = 10
sprintf (buff, "Circumferece: %d * %.3f = %.2f", diameter, pi, diameter * pi)
printl buff

the output is:
Circumference: 10 * 0.000 = 31.42

But if all else fails, I can use prototyped functions in 64-bit mode for these cases

#6
OxygenBasic / Re: sprintf / sprintf_s in 64-...
Last post by Charles Pegge - Yesterday at 12:10:21 PM
Hi Roland,

Interesting anomaly!

In 64bit mode, The variadic sprintf looks for the number in register rdx even though it is a double, normally passed in the simd register xmmm2.

The solution (hack) is to cast the number as a quad integer so it goes into the rdi register, where it will be picked up by sprintf.

sprintf (buff, "%.2f", (quad) num)
#7
OxygenBasic / sprintf / sprintf_s in 64-bit ...
Last post by Roland Stowasser - Yesterday at 09:33:41 AM
Hi Charles,

I tried this little program:
$filename "test_sprintf.exe"

'uses rtl32
uses rtl64

uses corewin
uses console

SetConsoleTitle "sprintf / sprintf_s Examples"
double num
char buff[64]

num = 333 * 1.5
sprintf (buff, "%.2f", num)
printl "333*1.5 = " buff

num = 100 / 13
sprintf_s (buff,64, "%.4f" , num)
printl "100/13 = "buff

printl
printl

sprintf (buff, "Value of pi = %.2f", pi)
printl buff

int arg1 = 27, arg2 = 9, result
result = arg1 * arg2
sprintf(buff, "When %d is multiplied with %d the result is: %d", arg1, arg2, result)
printl buff

int age = 30
double height = 1.75   'float / single does not work
string name = "John"
sprintf(buff, "%s is %d years old and %.2f meters tall.", name, age, height)
'Result: "John is 30 years old and 1.75 meters tall."
printl buff

printl
printl "Enter ..."
waitkey

If I use msvcrt.inc as is, then the app only works correctly in 32-bit..
Therefore, I changed in msvcrt.inc:

...
//! sprintf
int  sprintf(char *buffer, const char *format, ...)
//! sprintf_s
int  sprintf_s(char *buffer, int size, const char *format, ...)
...

now the app does also work in 64-bit mode.

I know that many functions of msvcrt.dll work if applied unprototyped with Oxygen, but it seems to me that functions with variable arguments need prototyping. Is there another solution?
#8
General Discussion / 100 Year-Old Nutrition Profess...
Last post by Charles Pegge - June 23, 2024, 09:22:28 PM
100 Year-Old Nutrition Professor: 7 Keys to Longevity | Dr. John Scharffenberg

Plant Chompers
13 jun 2024

#9
General Discussion / The US Ban Kaspersky
Last post by Zlatko Vid - June 22, 2024, 06:50:55 PM
what you think ...from my experience one of the best AV tools
for MS windows

#10
General Discussion / Did AI Just End Music?
Last post by Charles Pegge - June 22, 2024, 02:17:55 PM
Did AI Just End Music? Ft. Rick Beato

ColdFusion
30 apr 2024



I Told You This Was Going To Happen

Rick Beato
11 June 2024