#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0

    Lexical Analyser using Lex/Flex


    hello everyone :)

    i need help from you

    i want a Program to create Lexical Analyser for C Programming Language using Lex/Flex

    thanks to you all ;)
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    Code:
    flex -P _my_prefix_ my_lex_file.l
    What you put in my_lex_file.l depends on your requirements, which you haven't specified in your post.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0
    i mean write a program using lex language that analyse a c programm and test every character and show its type if it is a digit or alpha or keyword like if or while or .... or special character i hope you understand what i meann... thanks for replying
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0
    thanks,it's not what i really mean but it helps me a lot .thanks again :)
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,996
    Rep Power
    481

    beginnings of a php parser.


    Attached is an (incomplete) php parser I just wrote (36 hours, including sleep.) It builds a parse tree and evaluates it. Handles integer variables, expressions, echo, if, string concatenation and some common operators. Not completely tested. Leaks memory. I'm not a php expert (not even a novice, I should say). (I DO know more about php than I knew last week.) The code sufficiently meets the rules of the task I was assigned.
    Code:
      109   253  1814 z.y            (I used z.y to work out syntax tree execution.)
       19    77   543 00README.txt
       22    30   313 a.php
       61   174  1542 dictionary.c
        6     6    45 ex1.html
        6     6    45 ex1.php
        9    10    66 ex2.html
        9    13    83 ex2.php
        9    10    62 ex3.html
        9    13    79 ex3.php
        9    10    76 ex4.html
       11    13    93 ex4.php
       12    13    92 ex5.php
       16    18   173 example1.php
       21    24   266 example2.php
       73   206  1510 php2html.lex
      381  1252  9159 php2html.y
       27    70   374 test.sh
       21    42   353 tree.h
      830  2240 16688 total
    Attached Files
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0

    Post


    i found this one ...and this is what i mean thanks to everyone


    letter [a-zA-Z]
    digit[0-9]
    %%
    {digit}+("E"("+"|"-")?{digit}+)? printf("\n%s\tis real number",yytext);
    {digit}+"."{digit}+("E"("+"|"-")?{digit}+)? printf("\n%s\t is floating pt no ",yytext);
    "if"|"else"|"int"|"char"|"scanf"|"printf"|"switch"|"return"|"struct"|"do"|"while"|"void"|"for"|"floa t" printf("\n%s\t is keywords",yytext);
    "\a"|"\\n"|"\\b"|"\t"|"\\t"|"\b"|"\\a" printf("\n%s\tis Escape sequences",yytext);
    {letter}({letter}|{digit})* printf("\n%s\tis identifier",yytext);
    "&&"|"<"|">"|"<="|">="|"="|"+"|"-"|"?"|"*"|"/"|"%"|"&"|"||" printf("\n%s\toperator ",yytext);
    "{"|"}"|"["|"]"|"("|")"|"#"|"'"|"."|"\""|"\\"|";"|"," printf("\n%s\t is a special character",yytext);
    "%d"|"%s"|"%c"|"%f"|"%e" printf("\n%s\tis a format specifier",yytext);
    %%
    int yywrap()
    {
    return 1;
    }
    int main(int argc,char *argv[])
    {
    yyin=fopen(argv[1],"r");
    yylex();
    fclose(yyin);
    return 0;
    }

IMN logo majestic logo threadwatch logo seochat tools logo