Results 1 to 4 of 4

Thread: Lexical? Simple Compiler for my Project

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    2

    Lexical? Simple Compiler for my Project

    can anyone help me with my School project..since

    My Teacher told me to make a simple basic compiler that has lexical analysis features


    so it means onc you type an expression on a textbox..and verify that line

    it will separate Identifier,operator,assignment operator and number


    so lets say you type sum=a+b

    then on the ListBox it will show

    sum is an identifier
    = is an Assignment Operator
    a is an identifier
    + is an Operator
    b is an identifier


    just like that and if i inputted sum = 1 + 2 then it will show

    sum is an identifier
    = is an Assignment Operator
    1 is a number
    + is an Operator
    2 is a number

    after that on the second listbox it will show

    Sum = 3 (since 1+2 is inputted on the textbox)



    I hope someone could help me and provide the easiest code as possible

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Lexical? Simple Compiler for my Project

    You won't get code for an entire school project, that's frowned upon here since you're supposed to be learning, not copy-pasting.

    For your purposes, I suggest you look at regular expressions. You should be able to write a regular expression that is able to identify that 'sum' is an identifier, 1 is a number, '+' is an operator, and so on in your given statement.

  3. #3
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: Lexical? Simple Compiler for my Project

    Some suggestions to help you get started with your project.

    1) Mark the topics/keywords that was discussed in your class. This probably means tokens, words, language, input string, etc. (Sorry I forgot my Compiler class, should be in your book or whatever references you have).

    2) Make a state diagram (automata) for your language and for each state create a function or object if you like. I'm assuming this is function you can make several functions and have a main switch for it.

    3) Tie them up together (The transitions should be right, make your automata your guide on the flow of your program). Focus first on the logic, try to divide tasks as much as you can. In fact if you have the tasks listed you can get suggestions on what to do next, but it's better if you already have the logic for the program already.

    4) If you encounter problems with the actual c0ding then buzz us. Make sure you have the c0d in hand though, because if you don't have the c0d then there is nothing for us to help you fix with.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Lexical? Simple Compiler for my Project

    What language are you using, and what have you got so far?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width