[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

lex

please explain me shortly how to use lex.
I'm writing a calculator so what I have in my strings are operators and digits and functions with alphanumeric name.

10x alot.
0
wabby26
Asked:
wabby26
  • 2
  • 2
1 Solution
 
jhanceCommented:
Entire books (or at least large portions of book) have been written on lex.  Let me suggest the O'Reilly "lex and yacc" book to help you with your homework problem.

http://www.oreilly.com/catalog/lex/
0
 
wabby26Author Commented:
I asked this question just because I don't want to read the whole book inorder to do one simple thing.
0
 
jhanceCommented:
Yes, it would be awful if you actually had to learn something in order to do the work.  Maybe some other expert will take pity on you and post a complete tutorial on using lex for 50 pts. but I doubt it.

0
 
wabby26Author Commented:
Many questions like the one I asked have short and clear answers and do not require reading the whole book.
If you save a programmer time by answering his question he can use this time to learn the things that he really needs to know thoroughly.
Do you want to help or to argue?
0
 
ahoffmannCommented:
%{
int i=0;char o='';
%}
%%
DIGIT [0-9]
%%
{DIGIT}+      { n[i++]=atoi( yytext );}
"+"|"-"|"*"|"/"      { o=yytext[0];}
\n      { if(o=='+')printf("%d\n",n[0]+n[1]);
        if(o=='-')printf("%d\n",n[0]-n[1]);
        if(o=='/')printf("%d\n",n[0]/n[1]);
        if(o=='*')printf("%d\n",n[0]*n[1]);
        i=0;o='';
      }
..      { printf("error\n"); }

%%
void main (int a,char*v[]){yylex();}
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.

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