Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Script Parsing

Posted on 1998-10-15
10
Medium Priority
?
238 Views
Last Modified: 2010-04-15
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).
0
Comment
Question by:ealva
[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
  • 2
  • +2
10 Comments
 
LVL 3

Expert Comment

by:braveheart
ID: 1253588
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
 

Author Comment

by:ealva
ID: 1253589
No. This is not a full-fledged language. I do not need yacc and lex.
0
 
LVL 3

Expert Comment

by:elfie
ID: 1253590
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 3

Expert Comment

by:braveheart
ID: 1253591
You could use "strtok".
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1253592
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
 
LVL 84

Expert Comment

by:ozo
ID: 1253593
Rather than bother with converting and then stacking, I would just do a recursive descent.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1253594
>>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
 

Author Comment

by:ealva
ID: 1253595
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
 
LVL 5

Accepted Solution

by:
scrapdog earned 800 total points
ID: 1253596
>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
 

Author Comment

by:ealva
ID: 1253597
Thanks, scrapdog.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

670 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