• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

How to parsing simple scripts

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
fab1970
Asked:
fab1970
  • 3
  • 3
1 Solution
 
Marv-inCommented:
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
 
fab1970Author Commented:
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
 
ArkCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Marv-inCommented:
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
 
fab1970Author Commented:
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
 
Marv-inCommented:
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
 
fab1970Author Commented:
Well, it's a starting point. I now have an idea of what to do. Thanks, Marv.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now