• C

Script Parsing

I have a test script syntax of the form:
1. READ TRACK_1 & (TRACK_2 | TRACK_3)
2. WRITE TRACK_1 | TRACK_2

The first implies that tracks 1 is required AND either if tracks 2 or 3. The second implies that either track 1 or 2 is OK.  These are left associative. READ, WRITE, TRACK_1, TRACK_2, TRACK_3 are the only keywords.

I have to find a general (but efficient) algorithm to do these.  I also want to be able to store the order of evaluation to a structure that I can pass to any routine (that way, I don't have to parse again).  I already have a tokenizing routine so that's one out.

Any ideas?  (This is usually directed to anyone with an experience in compilers and translators).
ealvaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
braveheartCommented:
To write this from scratch in C would be fairly pointless when there are so many useful tools such as lex, yacc and bison about which can do the job for you quite efficiently.
0
 
ealvaAuthor Commented:
No. This is not a full-fledged language. I do not need yacc and lex.
0
 
elfieCommented:
If you already have a tokenizing routine, why not give each token a  number (like LEX) and then call a routine with variable number of parameters. That way you can pass a list of number, representing the parsed sentence
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
braveheartCommented:
You could use "strtok".
0
 
scrapdogCommented:
Elfie:  isn't that what the definition of tokenization is?

Tokenizing is the easy part, the hard part is determining the order of evaluation.

I would go about it by first converting the infix espression to postfix, and then using a stack to evaluate the postfix expression.
0
 
ozoCommented:
Rather than bother with converting and then stacking, I would just do a recursive descent.
0
 
scrapdogCommented:
>>I also want to be able to store the order of evaluation

If you want to STORE the order of evaluation, a postfix expression is most efficient.
0
 
ealvaAuthor Commented:
scrapdog is right. I do have to first convert to postfix in order to determine the order of evaluation. How do I award the answer?

0
 
scrapdogCommented:
>scrapdog is right. I do have to first convert to postfix in
>order to determine the order of evaluation. How do I award the
>answer?

If it was my answer you were talking about, grade it :)
.if not, reject it.

Btw, if you need infix to postfix algorithms, I can show you some (in Pascal though...).  These are (almost) generic;  you would have to change them to accommodate your needs.
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
ealvaAuthor Commented:
Thanks, scrapdog.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.