You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


FbCadCam - Macro
06-11-2017, 04:44 PM
Post: #11
 (Print Post)
RE: FbCadCam - Macro
FbCadCam -Macro Expression Evaluator : see attachment

I have commented out small sections of the 1200 or so LOC that are used to get the values of variables used in an expression such as would be the case in the following expresson:
a+b*c
atan2((r2h/2),Sqr((r1h/2)^2 + (r2x2-r1cx)^2 - (r2h/2)^2)) / rad

So no variables are interpreted or can be used in this example. Instead it will only handle expressions with numerics, i.e.:
1+2*3
atan2((100/2),Sqr((100/2)^2 + (300-1)^2 - (50/2)^2)) / .017444


Attached File(s)
.bas  evaluate_expression.bas (Size: 34.82 KB / Downloads: 11)
Find all posts by this user
Like Post
The following 1 user Likes owen's post:
figosdev
06-11-2017, 05:26 PM
Post: #12
 (Print Post)
RE: FbCadCam - Macro
The expression evaluater function is called in the case of:

Dim x as Integer

x=1
Print x

x=1+2
Print x

where x=1 and x=1+2

My previous post was presented to show the internals of evaluating an expression (without using variables in the equation)

In the source code you'll see:

    Dim As BOOLEAN _
        is_numeric_only, _
        is_variable_only, _
        has_numerics, _
        has_variables, _
        has_arithmetic_op, _
        has_bitwise_op, _
        has_math_op

The boolean variables has_arithmetic_op, has_bit_wise_op, has_math_op are set to TRUE if and when the string containing the expression uses these operations.

The order of operation in a mathematical expression is determined and held in an array based on priority. In other words in the case or 1+2*3 the math_ops array would contain 2 operations where the multiplication operation would have priority over the addition operation.

My expression evaluater also takes into account the order of operations in the event of parentheses
Find all posts by this user
Like Post
06-16-2017, 09:54 AM
Post: #13
 (Print Post)
RE: FbCadCam - Macro
full_evaluate_expression is called it the line uses arrays. For example:


Dim As Integer A, B, C, X(3)

X(0)=21
X(1)=32
X(2)=43
X(3)=54

A=1
B=2
C=X(A+B) + x(0)
In order to set C equal to the value held in the array X at index 3
The full_evaluate_expression function calls evaluate_expression to resolve A+B so that the index value will be known. I.e.:
C=X(3)
Once the index value is know full_evaluate_expression pulls the value held in array X index 3 and returns:
C=54+21
Which is then passed to evaluate_expression to return:
C=73
Find all posts by this user
Like Post
06-16-2017, 11:41 AM
Post: #14
 (Print Post)
RE: FbCadCam - Macro
hi owen
i don't know that your fbcadcam have expression evaluator
so i will check source
if i uderstand it correctly u use array as stack?

basicPro forum:
http://basicpro.mipropia.com/smf/index.php
EU Radioboard forum:
http://euradioboard.createmybb3.com/index.php
AurelSoft main site:
http://aurelsoft.ucoz.com
Find all posts by this user
Like Post
06-17-2017, 12:11 AM
Post: #15
 (Print Post)
RE: FbCadCam - Macro
Good q will use integer_array_1d_1()stion.
Variables and Arrays:

Variable name, type and index information is stored in a 2d string array.
The values of variables are stored in respective 1d arrays. I.e. integers are in an array called variable_value_integer().

Now arrays are unique and the number of arrays that my program will accept is 9.
9 - 1d integer
9 - 2d integer
9 - 3d integer
and the same for all other numeric data types such as double, long, ubyte, etc...
as well as boolean.

so let's say your source code uses two 1d integer arrays:
Dim As Integer A(11), B(22)
then A will use integer_array_1d_1()
anf B will use integer_array_1d_2()

I know that is crazy.
I know i could have put the arrays in one big array.
oops sorry, got to go back to work. my truck load is ready.
Find all posts by this user
Like Post
06-19-2017, 06:46 PM
Post: #16
 (Print Post)
RE: FbCadCam - Macro
evaluating expressions with functions in the expression

Code Snippet: [Select]
declare function add_int(a as integer,b as integer) as integer
dim as integer i,n(3)

do while n(3)<100
    for i = 0 to 2
        n(i)=i+1
    next
    n(3)+=add_int(n(0)*2,n(1)*2)*n(2)
    print n(3)
loop


function add_int(a as integer,b as integer) as integer
    dim as integer i
    i=a+b
    return i
end function
Find all posts by this user
Like Post
06-20-2017, 05:43 AM
Post: #17
 (Print Post)
RE: FbCadCam - Macro
In the example above, the expression to be evaluated for n(3) was

n(3)+=add_int(n(0)*2,n(1)*2)*n(2)

in this expression the function add_int is first detected in

Function keyword_commands_block()
For i= 1 To macro_function_c
temp=Left(temp,fxstart-1)+func_value(functext)+Mid(temp,fxend+1)

func_value returns a string and
n(3)+=add_int(n(0)*2,n(1)*2)*n(2) is changed to n(3)+=function_result*n(2)
Function func_value(func_text As String) As String


Code Snippet: [Select]
Function func_value(func_text As String) As String
    Dim As Integer i,j,k,x,c,a,b,ai1,ai2,ai3
    Dim As BOOLEAN keyword_command_found
    Dim As String temp,temps(),temp2,array_index,temptemp
    Dim As Integer temps_c
    Dim As Integer stringpartc

    temp=func_text
    For i= 1 To macro_function_c
        If temp=macro_function_name(i) Then
            clear_sub_function_variables(macro_function_name(i))
            For j=1 To macro_function_data_c
                If macro_function_data(j)=macro_function_name(i) Then
                    c=1
                    For k=1 To CInt(macro_function_data(j+c))
                        c+=1
                        'Print "*************** function data ****** iterate k=";k;" data=";macro_function_data(j+c)
                    Next
                    c+=1
                    'Print "*************** function data ****** one more time=";macro_function_data(j+c)
                    temps_c=0
                    ReDim temps(temps_c)
                    For k=1 To CInt(macro_function_data(j+c))
                        c+=1
                        'Print "*************** function data ****** 2nd k=";macro_function_data(j+c)
                        temps_c+=1
                        ReDim Preserve temps(temps_c)
                        temps(temps_c)=macro_function_data(j+c)
                    Next
                    For k=1 To temps_c
                        temp=temps(k)
                        k=keyword_commands_block(k,temps_c,temp,temps())
                    Next
                    Exit For
                EndIf
            Next
            Exit For
        Else 'function routine is called and parms are parsed ie. A=f(x)
            clear_sub_function_variables(macro_function_name(i))
            'note: this does not address A=B+f(x) or A=f(x)+B
            If LTrim(RTrim(Mid(temp,1,InStr(temp,"(")-1)))=macro_function_name(i) Then
                temp=LTrim(Mid(temp,InStr(temp,"(")+1)) 'test(x(),1) = x(),1)
                temp=RTrim(Left(temp,Len(temp)-1)) 'x(),1) = x(),1
                getparts(temp)
                For j=1 To macro_function_data_c
                    If macro_function_data(j)=macro_function_name(i) Then
                        macro_function_recursion_c+=1
                        ReDim Preserve macro_function_return(macro_function_recursion_c)
                        ReDim Preserve macro_function_exit(macro_function_recursion_c)
                        macro_function_return(macro_function_recursion_c)=macro_function_name(i)+"_return"
                        macro_function_exit(macro_function_recursion_c)=FALSE
                        stringpartc=0
                        c=1
                        For k=1 To CInt(macro_function_data(j+c))
                            c+=1
                            stringpartc+=1
                            If InStr(string_parts(stringpartc),"()") Then 'copy array x() to test_n()
                                temp=LTrim(RTrim(Mid(string_parts(stringpartc),1,InStr(string_parts(stringpartc),"(")-1)))
                                For a=1 To macro_variables_info_c
                                    If temp=macro_variables_info(a,1) Then
                                        temp="redim "+macro_function_data(j+c)+macro_variables_info(a,4)
                                        'Print temp
                                        keyword_redim(temp)
                                        For b=1 To macro_variables_info_c
                                            If macro_function_data(j+c)=macro_variables_info(b,1) Then
                                                array_index=macro_variables_info(b,3)
                                                Exit For
                                            EndIf
                                        Next
                                        copy_array(a,array_index)
                                        Exit For
                                    EndIf
                                Next
                            Else
                                temp=macro_function_data(j+c)+"="+string_parts(stringpartc)
                                keyword_let(temp)
                            EndIf
                        Next
                        c+=1
                        temps_c=0
                        ReDim temps(temps_c)
                        For k=1 To CInt(macro_function_data(j+c))
                            c+=1
                            temps_c+=1
                            ReDim Preserve temps(temps_c)
                            temps(temps_c)=macro_function_data(j+c)
                        Next
                        For k=1 To temps_c
                            temp=temps(k)
                            k=keyword_commands_block(k,temps_c,temp,temps())
                            If macro_function_exit(macro_function_recursion_c)=TRUE Then Exit For
                        Next
                        temp=macro_function_return(macro_function_recursion_c)
                        macro_function_recursion_c-=1
                        Exit For
                    EndIf
                Next
                Exit For
            EndIf
        EndIf
    Next
    For i=1 To macro_variables_info_c
        If temp=macro_variables_info(i,1) Then
            Select Case macro_variables_info(i,2)
                Case "BOOLEAN"
                    Return Str(macro_variables_boolean_value(CInt(macro_variables_info(i,3))))
                Case "BYTE"
                    Return Str(macro_variables_byte_value(CInt(macro_variables_info(i,3))))
                Case "UBYTE"
                    Return Str(macro_variables_ubyte_value(CInt(macro_variables_info(i,3))))
                Case "SHORT"
                    Return Str(macro_variables_short_value(CInt(macro_variables_info(i,3))))
                Case "USHORT"
                    Return Str(macro_variables_ushort_value(CInt(macro_variables_info(i,3))))
                Case "LONG"
                    Return Str(macro_variables_long_value(CInt(macro_variables_info(i,3))))
                Case "ULONG"
                    Return Str(macro_variables_ulong_value(CInt(macro_variables_info(i,3))))
                Case "INTEGER"
                    Return Str(macro_variables_integer_value(CInt(macro_variables_info(i,3))))
                Case "UINTEGER"
                    Return Str(macro_variables_uinteger_value(CInt(macro_variables_info(i,3))))
                Case "LONGINT"
                    Return Str(macro_variables_longint_value(CInt(macro_variables_info(i,3))))
                Case "ULONGINT"
                    Return Str(macro_variables_ulongint_value(CInt(macro_variables_info(i,3))))
                Case "SINGLE"
                    Return Str(macro_variables_single_value(CInt(macro_variables_info(i,3))))
                Case "DOUBLE"
                    Return Str(macro_variables_double_value(CInt(macro_variables_info(i,3))))
            End Select
            Exit For
        EndIf
    Next
End Function
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - 9 Board
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Blokus
QB64 Member Project - Basic Dithering
QB64 Member Project - Rotating Background
QB64 Member Project - Martin Fractals version two
QB64 Member Project - Score 4
QB64 Member Project - Color Rotating Text
QB64 Member Project - Kings Valley verion one
QB64 Member Project - Othello
QB64 Member Project - Overboard
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - Touche
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - Exit
QB64 Member Project - Color Triangles
QB64 Member Project - Algeria Weather
QB64 Member Project - Kings Court
QB64 Member Project - Spiro Roses
QB64 Member Project - Line Thickness
QB64 Member Project - Isolation
QB64 Member Project - OpenGL Triangles
QB64 Member Project - Dreamy Clock
QB64 Member Project - ARB Checkers
QB64 Member Project - Rubix's Magic
QB64 Member Project - Amazon
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Qubic
QB64 Member Project - Splatter
QB64 Member Project - Pivet version one
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Kings Vallery version two
QB64 Member Project - Inside Moves
QB64 Member Project - Foursight
QB64 Member Project - Dakapo
QB64 Member Project - Input
QB64 Member Project - Swirl
QB64 Member Project - Quarto
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Connect Four
QB64 Member Project - Sabotage
QB64 Member Project - Martin Fractals version one
QB64 Member Project - Domain
QB64 Member Project - Bowditch curve
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Pivot version two
QB64 Member Project - Point Blank
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Full Color LED Sign