Solved

How to parsing simple scripts

Posted on 2004-10-30
160 Views
Last Modified: 2010-05-02
I need to build a "simple" script parser: an app receive strings from a RS232 connection.
In a text file i have some "expressions" to execute, the app reads these expressions and return via RS232 the correct answer.
I put here a starting idea of what i think about these "expressions":

1)
IF "the input string must match exactly this string, no care of capitalization"
THEN "This string wil be sent via RS232"
ELSE "This is another string that wil be sent via RS232"
END

2)
IF CAPS "This String MUST Match Capitalization"
THEN ""This string wil be sent via RS232"
END

2)
IF CONTAINS CAPS "This string Is CONTAINED somewhere in the input string, Capitalization match also"
THEN
    IF "a test depending on the previous IF test"
    OR "another string"
    THEN "ok"
    ELSE "No"
    END
ELSE "Another result"
END

Well, i hope you can uderstand what i mean.
I'm searching for a sample, a link, something that make me able to build the "expression" parser, converting the lines readed from the text file in a functon that works.
Thnkx
0
Question by:fab1970
    7 Comments
     
    LVL 6

    Expert Comment

    by:Marv-in
    here is a link with examples of the various string functions in VB
    http://www.officecomputertraining.com/vbtutorial/tutpages/page19.asp

    if you would like more specific info let me know
    0
     

    Author Comment

    by:fab1970
    Marv,
    i know the strings functions in vb, what i need is a way to read the examples i've wrote in the question from a text file in a function that, given an input string, do the comparisons.
    In other words i need a custom-script interpreter...
    Ii's hard to explain in a foreign language, i'm sorry.
    0
     
    LVL 27

    Expert Comment

    by:Ark
    Hi
    If you're speaking about 'script', did you thought about 'tags'? You can put smth like 'tags' in the beginning of your strings in a file, like:
    [1] First type of string 'optionally end of tag mark [/1], or just [br] or vbCrLf
    [2] Second type of string 'optionally end of tag mark [/1], or just [br] or vbCrLf
    ...etc
    Now you can just read a tag and perform action according this tag
    0
     
    LVL 6

    Expert Comment

    by:Marv-in
    I think I understand - you want to parse a file that is actually formatted like what you posted. If that is the case this could take some work.

    if you want an advanced example of a parsing engine - this is it
    http://www.devincook.com/goldparser/engine/index.htm#Engine-DLL

    this example includes grammer definitions and lots of other good stuff - plus its free =]
    0
     

    Author Comment

    by:fab1970
    Marv,
    you've right understood me.
    I've got a look at the link you tell me. The Gold Engine i'ts a huge stuff for the "little" thing i need... i need some time to understand the Gold Engine.
    Anyway, it's a step in the right direction. If you have some simpler example, or some tips for me, you're welcome.

    ;)
    0
     
    LVL 6

    Accepted Solution

    by:
    it will be lots of if statements =]

    Here is some puseduo code  that should help

    while not EOF
     
      readln
     
      if line is IF then
        ParseIF textstream, line
      endif

    wend

    sub ParseIF (t as textstream, l as string)
      if CAPS IF then
        eval as boolean
      else if IF
        eval as boolean
      endif

      if true then
        readln
        its its another IF
          ParseIF t,l
        else
          write value to output
        endif
      else
        readln till you find ELSE
        its its another IF
          ParseIF t,l
        else
          write value to output
        endif
      endif  

    end sub

    im sorry i dont have a ton of free time but i would like to help as much as i can
    0
     

    Author Comment

    by:fab1970
    Well, it's a starting point. I now have an idea of what to do. Thanks, Marv.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    The Complete Ruby on Rails Developer Course

    Ruby on Rails is one of the most popular web development frameworks, and a useful tool used by both startups and more established companies to build strong graphic user interfaces, and responsive websites and apps.

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    857 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now