Autore Topic: Analizzatore personalizzato di espressioni  (Letto 315 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.725
  • Ne mors quidem nos iunget
    • Mostra profilo
Analizzatore personalizzato di espressioni
« il: 04 Gennaio 2016, 11:20:01 »
Riporto questo messaggio di Minisini:

" Hi,

In revision #7545, it is now possible to inherit the Expression class to
customize the expression evaluator.

It works that way:

Codice: [Seleziona]
' Gambas class file'

Inherits Expression

Static Public Sub IsIdentifier(Name As String) As Boolean

   ' Return if 'Name' is an allowed identifier.'

End

Static Public Sub IsSubr(Name As String) As Boolean

   ' Return if a the 'Name' Gambas subroutine is allowed.'

End

Public Sub GetValue(Name As String) As Variant

   Return the value of the 'Name' identifier.

End

Public Sub MySubr(iVal As Integer) As Integer

  ' Example of a custom subroutine. The "MySubr" identifier'
  ' must be allowed by the IsIdentifier() method.'

End
It's mainly a present for Fabien so that he can write a simpler
evaluator for the gb.report2 component, but it may be helpful for other
people that need a custom evaluator.

It's not possible to disable Gambas operators or reimplement their
behaviour, and I don't think I would allow that.

But if you have other customization needs, you can tell!

Note : you can now evaluate an expression or call Eval() recursively,
and it should work. But it is not well tested and may crash.

Regards,

--
Benoît Minisini
"
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »