📄 modmajorparsing.vb
字号:
Module modMajorParsing
Public Function GetE() As Object
On Error GoTo ErrorHandler
'**********************************
'* PARSING ROUTINE (Expression E) *
'* E ::= T + T | T - T | T *
'**********************************
'Get the lower value (T)
Value = GetT()
'Exit function if error or help call returned
'User set a value to a variable
If SetVariable Then
GetE = Value
Exit Function
End If
'Allow for multiple operators of the same precedence
'level occuring immediately after each other
While OutputString = "+" Or OutputString = "-"
Select Case OutputString
'Addition operator
Case "+"
ExtractToken()
Value = Value + GetT()
'Subraction operator
Case "-"
ExtractToken()
Value = Value - GetT()
End Select
End While
'Return value for E
GetE = Value
'Exit function before error handler
Exit Function
ErrorHandler:
'Trap errors
TrapErrors(Err.Number)
End Function
Public Function GetT() As Object
On Error GoTo ErrorHandler
Dim Exponent As Double
'****************************
'* PARSING ROUTINE (Term T) *
'* T ::= F * F | F / F | F *
'****************************
'Get the lower value (F)
Value = GetF()
'Exit function if error or help call returned
'User set a value to a variable
If SetVariable Then
GetT = Value
Exit Function
End If
'Allow for multiple operators of the same precedence
'level occuring immediately after each other
While OutputString = "*" Or OutputString = "/"
Select Case OutputString
'Multiplication operator
Case "*"
ExtractToken()
Value = Value * GetF()
'Division operator
Case "/"
ExtractToken()
Value = Value / GetF()
End Select
End While
'Return value for T
GetT = Value
'Exit function before error handler
Exit Function
ErrorHandler:
'Trap errors
TrapErrors(Err.Number)
End Function
Public Function GetF() As Object
On Error GoTo ErrorHandler
Dim ArrayIndex As Integer
Dim ArrayItemExists As Boolean
Dim ArrayString As String
Dim ArrayValue As Double
Dim Base As Double
Dim Constant As Double
Dim ConstantExists As Boolean
Dim FileNumber As Integer
'Dim LogBase As String
Dim LogIndex As Integer
Dim i As Integer
Dim Temp As String
Dim Temp2 As String
'******************************
'* PARSING ROUTINE (Factor F) *
'* F ::= Number | ( E ) *
'******************************
'Handle the low level calculations
Select Case OutputString
'***************
'Basic Functions
'***************
'Number
Case "Number"
Value = OutputValue
ExtractToken()
GetF = PostToken()
'Negative
Case "-"
ExtractToken()
GetF = -(GetF())
'Random number
Case "rnd"
Randomize()
Value = Rnd()
ExtractToken()
GetF = PostToken()
'Parenthesis
Case "("
ExtractToken()
Value = GetE()
If OutputString <> ")" And OutputString <> "EOS" Then
TrapErrors(0)
Exit Function
End If
If OutputString = "EOS" Then
GetF = Value
Else
ExtractToken()
GetF = PostToken()
End If
'Previous answer
Case "ans"
Value = PrevAnswer
ExtractToken()
GetF = PostToken()
'*************
'Miscellaneous
'*************
'Absolute value
Case "abs"
ExtractToken()
Value = GetF()
If InError Then
Exit Function
Else
GetF = System.Math.Abs(Value)
End If
'Help
Case "sr"
ExtractToken()
Value = GetF()
If InError Then
Exit Function
Else
GetF = System.Math.Sqrt(Value)
End If
'**********
'Logarithms
'**********
'Logarithm (to a base)
Case "log"
'Get logarithm base
Base = Val(logbase)
'Get number
ExtractToken()
GetF = System.Math.Log(GetF()) / System.Math.Log(Base)
'Natural logarithm
Case "ln"
ExtractToken()
Value = GetF()
If InError Then
Exit Function
Else
GetF = System.Math.Log(Value)
End If
'***********************
'Trigonometric Functions
'***********************
'Cosine
Case "cos"
ExtractToken()
Value = GetF()
ConvertToRadians()
If InError Then
Exit Function
Else
GetF = System.Math.Cos(Value)
End If
'Cotangent
Case "cot"
ExtractToken()
ConvertToRadians()
If InError Then
Exit Function
Else
GetF = 1 / System.Math.Tan(Value)
End If
'Cosecant
Case "csc"
ExtractToken()
Value = GetF()
ConvertToRadians()
If InError Then
Exit Function
Else
GetF = 1 / System.Math.Sin(Value)
End If
'Hyperbolic cosecant
Case "hcsc"
ExtractToken()
Value = GetF()
ConvertToRadians()
If InError Then
Exit Function
Else
GetF = 2 / (System.Math.Exp(Value) - System.Math.Exp(-Value))
End If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -