ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hey thank you very much graemef). Everything solved.
Actually i am designing a compiler supporting set operations using Lex and Yacc. Here, the user will give input in the form of set like: {1,2,3,4}. So i need to convert it to an array as I am using Standard Template Library(STL), which contains set functions like intersection, union, set difference and set symmetric difference.
And in these functions, the arguments are in the form of an array. For that purpose, i need to pass the set as an array. And therefore, i need to convert the input, which is in the form of braces(set) to array form.
This is what i did.
Quote:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char *c="{1,2,3,4}",a[10];
int i,j;
Most of this you may want to do in a separate validation function, the duplicate case you can easily do by changing the way you hold the set. First set each element to zero, then if it exists set the value to one, which would be a[c[j]] = 1;. You display routine would then be a case of seeing if it is one or not.
If space is an issue you can then change this to a bit pattern.
Yes, you are right. But Flex has a very good option regarding ill-formed input. I just need to match the pattern like { //input } , i.e. starting parenthesis , elements separated by comma, closing parenthesis. so any other input is considered as ill-formed input and it wont' be converted to token. So all the inputs(sets) will be scanned but not passed to the parser.
Quote:
Most of this you may want to do in a separate validation function, the duplicate case you can easily do by changing the way you hold the set.
Thanks for the help,but I have used STL functions, which automatically detect this duplication. So i need not device another logic for that purpose.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.