Results 1 to 7 of 7

Thread: Creating very small scripting language: conditional statements?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Question Creating very small scripting language: conditional statements?

    I'm extending my application with plugins and a small scripting language. It will only have 1 or 2 objects available.

    I can probably do variables but I'm kind of at a loss for how to do conditional statements. I've never tried anything like this before and I'm actually kind of confused on where to start also.

    But the main concern is conditional statements. It will only contain If/Then statements. Can someone give me some pseudo-code or logic or an example or something?

    I found a few examples on Planet Source Code, but a lot were way too complex/sloppy-coded to be of much use and pick out the important parts.

  2. #2
    Lively Member Garrcomm's Avatar
    Join Date
    Jul 2009
    Location
    the Netherlands
    Posts
    87

    Re: Creating very small scripting language: conditional statements?

    You could try the Microsoft Script Control reference, see also:
    http://support.microsoft.com/kb/184740
    If a thread is solved, please click on Thread Tools / Mark Thread Resolved .
    If someone helped you very good, consider rating his post by clicking the icon under his name.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Re: Creating very small scripting language: conditional statements?

    Thanks, but doesn't really help much since I'll be writing my own scripting language which won't really be much like Visual Basic or run Visual Basic code.

    Thanks, though.

  4. #4
    Lively Member Garrcomm's Avatar
    Join Date
    Jul 2009
    Location
    the Netherlands
    Posts
    87

    Re: Creating very small scripting language: conditional statements?

    Have you defined your syntax already? Will it be procedure based or object orientated? And if I may know, what is the purpose?
    It sounds like a very intense and interesting project!
    Last edited by Garrcomm; Jul 13th, 2009 at 02:40 AM.
    If a thread is solved, please click on Thread Tools / Mark Thread Resolved .
    If someone helped you very good, consider rating his post by clicking the icon under his name.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Re: Creating very small scripting language: conditional statements?

    It will use more-or-less the BASIC syntax. Its purpose is just to extend my application.

    Users can write scripts to modify the GUI of the program, do things with data, etc. It will be a very basic/stripped-down language with only a couple objects, variables, conditional statements, and maybe if I can, for loops.

    Edit: I've used the Microsoft Script Control that you linked to before, to run VB code, but unfortunately it won't work for this situation, and I'd really rather write it from scratch.

  6. #6
    Addicted Member
    Join Date
    Jul 2006
    Location
    Adelaide, Australia
    Posts
    204

    Re: Creating very small scripting language: conditional statements?

    you could possibly write a couple of functions like this
    Visual Basic Code:
    1. Public function GreaterThan(byval Arg1 as string, byval Arg2 as string, optional EqualTo as boolean) as boolean
    2. If EqualTo then
    3. 'GreaterThan or equal to (>=)
    4.     if arg1 >= arg 2 then GreaterThan = true
    5. else
    6. 'Only GreaterThan (>)
    7.     if arg1 > arg 2 then GreaterThan = true
    8. end If
    9. end function
    10.  
    11. Public function LessThan(byval Arg1 as string, byval Arg2 as string, optional EqualTo as boolean) as boolean
    12. If EqualTo then
    13. 'LessThan or equal to (<=)
    14.     if arg1 <= arg 2 then LessThan = true
    15. else
    16. 'Only GreaterThan (<)
    17.     if arg1 < arg 2 then LessThan = true
    18. end If
    19. End Function

    Of course you will need to change the Arg input types based on what you are comparing, but you can get the general idea.

    Next, you will need to parse the text in the script, and then call the appropriate function eg
    Script: If "abc" =< "bcd" Then ...
    Your app will need to pull out the strings "abc" and "bcd" and then call LessThan like so: If LessThan("abc", "bcd", True)
    Last edited by Macka007; Jul 13th, 2009 at 03:27 AM.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Creating very small scripting language: conditional statements?

    I would recommend something similar to what Macka007 suggested, but a bit simplified.

    Assuming that you have separated the items into variables arg1, arg2, and strOperator, you could use a Select Case like this:
    Code:
    Dim booResult as Boolean
      Select Case strOperator
      Case "="
         booResult = (arg1=arg2)
      Case ">"
         booResult = (arg1>arg2)
      Case ">="
         booResult = (arg1>=arg2)
    ...
      Case Else
         MsgBox "Unknown operator!", vbExclamation
         Exit Sub
      End Select
    ..or re-arranged slightly:
    Code:
    Dim booResult as Boolean
      Select Case strOperator
      Case "=":     booResult = (arg1=arg2)
      Case ">":     booResult = (arg1>arg2)
      Case ">=":    booResult = (arg1>=arg2)
    ...
      Case Else
         MsgBox "Unknown operator!", vbExclamation
         Exit Sub
      End Select
    The booResult variable would then tell you the outcome of their If statement.


    Note that you need to be careful with the data type of arg1 and arg2, or you may get unexpected results (if both were strings, 2 would be greater than 11).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width