Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to parsing simple scripts

Posted on 2004-10-30
7
Medium Priority
?
175 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
Comment
Question by:fab1970
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 6

Expert Comment

by:Marv-in
ID: 12451976
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
ID: 12454173
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 28

Expert Comment

by:Ark
ID: 12454484
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Expert Comment

by:Marv-in
ID: 12456478
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
ID: 12457274
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:
Marv-in earned 2000 total points
ID: 12458980
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
ID: 12460006
Well, it's a starting point. I now have an idea of what to do. Thanks, Marv.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

609 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