Results 1 to 6 of 6
  1. #1

    Default lexical analyzer in C..


    Hi guys! sa ako ni PL nga class sa laboratory. just want to ask some ideas. we are asked man to make a mini compiler. my analyzer.hÂ* contains all the functions.Â* naa naman ko five functions nga nahimo on isDigit,isAlpha,isIdentifier,isInterger,isOperator . My problem are the functions: isExpression, isDeclaration, and isCType.Â*

    Valid tokens for isExpression: identifier= identifier operator identifier semicolon
    Â* Â* Â* Â* Â* Â* Â*example: sum= a+b;Â*

    int isExpression (char *ch)
    {
    Â* int flag=0,i;

    for(i=0;ch[i]!= '\0';i++){
    Â* if(isIdentifier(ch[i])){

    /*dri ko nga part naglibog kung unsa sunod*/

    }

    int isCType(char *ch)
    {

    char *str1= "int";
    char *str2= "float";
    char *str3= "double";
    char *str4= "long int";
    char *str5= "long float";
    char *str6= "long double";

    if(strcmp(str1,ch))
    Â* return 1;

    else if(strcmp(str2,ch))
    Â* return 1;

    else if(strcmp(str3,ch))
    Â* return 1;
    .......
    .......
    ......so on and so forth...

    }Â* Â* Â*/*unsa pasabot ani error nga: isCtype in MAINANALYZER.c is duplicated in ANALYZER.H?mao man ako makuha nga error sa ani nga function inig tawag nako sa main*/Â*


    ari lang sa ko kutob post..kay maghimo pa pud ko program..hehe..pa-eta ani oy..dok2x jud ko ani maau kay C man gud..

    hope anyone could share some ideas...thanks!

  2. #2

    Default Re: lexical analyzer in C..

    1. test if the expression is well terminated.
    2. test the validity - to test the validity you need to use a STACK. Loop each character until the ";" character - here's the technique. if you find a value PUSH it to the STACK else if its an operator POP it out, but before you POP test if the STACK is EMPTY, if it is raise an ERROR flag and break from the loop else continue..
    3. lastly, test the STACK if it is EMPTY - an empty stack means you have a well-formed expression

    Comments:
    int isCType() - can you use array and looping


    heheheeheh anah jud na part dokdok. Good Luck

  3. #3

    Default Re: lexical analyzer in C..

    naa mai same problem ani sa atong usa ka datastructure & algo nga libro.. katong morag dako nga wave made out of pixels and yeah Stack gamit.. poydi multiple stack imong gamiton

    use your imagination hehehe, kong malingaw gali kag programming ma solve rana nimo..
    i usually take a break/ or ma-tog kon naai problem di nako masolve the next day maka huna huna naka og solution..

  4. #4

    Default Re: lexical analyzer in C..

    Quote Originally Posted by metz143
    /*unsa pasabot ani error nga: isCtype in MAINANALYZER.c is duplicated in ANALYZER.H?mao man ako makuha nga error sa ani nga function inig tawag nako sa main*/Â*
    naa ba handler sa C kung magduplicate ang function sa 2 ka included files sa imong program? If that's that case, then maybe naa ka isCtype function on both MAINANALYZER.c ug sa ANALYZER.h and then dili man pwede mag-override ug same two functions dili parehas sa pascal.

  5. #5

    Default Re: lexical analyzer in C..

    I have a complete finished project regarding sa imo problem involving lexical, syntactic and semantic kaso delphi ako gamit.
    ingna lang ko if nahan ka.

  6. #6

    Default Re: lexical analyzer in C..

    /*unsa pasabot ani error nga: isCtype in MAINANALYZER.c is duplicated in ANALYZER.H?mao man ako makuha nga error sa ani nga function inig tawag nako sa main*/
    It's possible that isCtype() has been defined in ANALYZER.H. Usually, function prototypes ra ang ibutang diha nga file.

    [ simon.cpu ]

  7.    Advertisement

Similar Threads

 
  1. Replies: 2671
    Last Post: 10-29-2018, 11:39 PM
  2. GREAT DIVING SPOTS IN CEBU
    By Gypsy in forum Destinations
    Replies: 37
    Last Post: 10-22-2018, 10:29 AM
  3. For Sale: Condominiums in Mabolo! Compare, Analyze and Invest!
    By GOSPELofROCH in forum Real Estate
    Replies: 40
    Last Post: 08-21-2012, 07:02 PM
  4. Do you believe in God? If so/if no, WHY?
    By n`gel in forum Spirituality & Occult - OLDER
    Replies: 1585
    Last Post: 07-31-2009, 04:33 PM
  5. SPELLCHECKER, GRAMMAR ANALYZER, TRANSLATOR in C++
    By dicpimp in forum Programming
    Replies: 5
    Last Post: 07-15-2007, 01:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top