un interpréteur de script , voici quelques fonctions très utiles pour le parsing d'un fichier source :
Code : Tout sélectionner
; ------------------------------------------------------------------
; FORMAT 0x??...
; ------------------------------------------------------------------
Procedure.a IsHexaDecimal(word$)
For i = 3 To Len(word$)
EXPREG$ + "[0-9 A-F a-f]"
Next
RE = CreateRegularExpression(#PB_Any, "^0x"+EXPREG$)
If RE
Result.a = MatchRegularExpression(RE, word$)
EndIf
FreeRegularExpression(RE)
ProcedureReturn Result
EndProcedure
; ------------------------------------------------------------------
; FORMAT $xx...
; ------------------------------------------------------------------
Procedure.a IsHexaDecimal2(word$)
For i = 2 To Len(word$)
EXPREG$ + "[0-9 A-F a-f]"
Next
RE = CreateRegularExpression(#PB_Any, "^$"+EXPREG$)
If RE
Result.a = MatchRegularExpression(RE, word$)
EndIf
FreeRegularExpression(RE)
ProcedureReturn Result
EndProcedure
; ------------------------------------------------------------------
; FORMAT [0 to 9]...
; ------------------------------------------------------------------
Procedure.a IsDigit(word$)
For i = 1 To Len(word$)
EXPREG$ + "[0-9]"
Next
RE = CreateRegularExpression(#PB_Any,EXPREG$)
If RE
Result.a = MatchRegularExpression(RE, word$)
EndIf
FreeRegularExpression(RE)
ProcedureReturn Result
EndProcedure
; ------------------------------------------------------------------
; FORMAT : MyVar / MyVar0 / MyVar_0 ...
; ------------------------------------------------------------------
Procedure.a IsVariable(word$)
For i = 2 To Len(word$)
EXPREG$ + "[A-Z a-z 0-9 _]"
Next
RE = CreateRegularExpression(#PB_Any,"^[A-Z a-z]"+EXPREG$)
If RE
Result.a = MatchRegularExpression(RE, word$)
EndIf
FreeRegularExpression(RE)
ProcedureReturn Result
EndProcedure
; ------------------------------------------------------------------
; Format : #MyConst / #MyConst0 / #MyConst_0
; ------------------------------------------------------------------
Procedure.a IsConstant(word$)
For i = 2 To Len(word$)
EXPREG$ + "[A-Z a-z 0-9 _]"
Next
RE = CreateRegularExpression(#PB_Any,"^[#]"+EXPREG$)
If RE
Result.a = MatchRegularExpression(RE, word$)
EndIf
FreeRegularExpression(RE)
ProcedureReturn Result
EndProcedure
l'utilisation est simple , admettons que vous voulez analyser ce texte :
le Debbuger vous dit , si il sagit d'une variable , d'une constante , d'un nombre hexa , etc...MyVariable = #PI
MyVariable = 589
MyVariable = 0xFF
Code : Tout sélectionner
Text$ = "MyVariable = #PI"+Chr(32)
Text$ + "MyVariable = 589"+Chr(32)
Text$ + "MyVariable = 0xFF"
For i = 1 To CountString(Text$,Chr(32))+1
Word$ = StringField(Text$,i,Chr(32))
If IsHexaDecimal(Word$) = #True
Debug "HEXA = "+Word$
EndIf
If IsDigit(Word$) = #True
Debug "DIGIT = "+Word$
EndIf
If IsVariable(Word$) = #True
Debug "VARIABLE = "+Word$
EndIf
If IsConstant(Word$) = #True
Debug "CONSTANT = "+Word$
EndIf
Next
VARIABLE = MyVariable
CONSTANT = #PI
VARIABLE = MyVariable
DIGIT = 589
VARIABLE = MyVariable
HEXA = 0xFF