to implement hand written lexer and parser

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kathyayini
    New Member
    • Mar 2010
    • 3

    to implement hand written lexer and parser

    i am trying to implement the algorithm given in the dragon book but i am facing a lot of difficulties please help...... especially the regular expression to DFA using C
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    What is this 'dragon book' ? Could you please explain your problem further, including your relevant code so far? Have you broken down the problem into concrete steps?

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      Originally posted by kathyayini
      'Dragon book' is the 'Compiler Techniques and Tools' by Aho, Ravi Setti and others.
      Yes i hav planned to do the coding in two steps namely to
      1. construct the transition table which is the output of the lexer and input to the parser
      2. construction of the parsing table using which my own language is parsed whose output should be the parsing table and with its parse tree.
      Alright, it looks like you're working on a good foundation.
      May I ask, (to give us background on the task)
      1. What type of input are you taking in? What are the rules of the language that you are parsing?
      2. Or are the language rules part of the input?
      3. Are you required to tokenize anything, or is this a character by character process?

      Comment

      • kathyayini
        New Member
        • Mar 2010
        • 3

        #4
        Mainly we are asked to create a new language eg:delimeters which are ';' is being replaced by '.' in my language. And I am asked to write a lexer and parser in C which takes my own language as the input and processes it to produce the corresponding parse tree using 'dotty'.

        The transition table should contain states as its column and in rows should contain the input symbol. And thier respective transitions filled in the table.
        I dont know how to enter the regular expression [a-zA-Z] or [0-9] which is input on some state n should go to some state m. If you can help me on this I will be thankfull.

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          Period ('.') has legitimate uses in C (decimal point in floating point numbers; delimit structure field names). Are you going to replace period in these contexts with something else or does your parser need to distinguish between these uses of period plus your new use of it as a delimiter?

          Comment

          • kathyayini
            New Member
            • Mar 2010
            • 3

            #6
            Yes it should distinguish between the delimeter and the period('.') according to the context.

            can you please help me to construct the transition table for the same. If you can help me out with alteast the basic functions used would be very helpful.

            Comment

            • jkmyoung
              Recognized Expert Top Contributor
              • Mar 2006
              • 2057

              #7
              Please give us the language construction rules. Eg simple syntax of a simple programming language could be like:
              Code:
              code:= <stmt>
                         <code>
              code:= </>
              
              <stmt>:=  If <bool> then
                         <code>
                         endif
              
              <stmt> := <variable> = <value>
              
              <bool> := <variable> ?= <value>
              
              <variable> := [a-zA-Z][a-zA-Z0-9]*
              
              <value> := [0-9]+

              Comment

              • donbock
                Recognized Expert Top Contributor
                • Mar 2008
                • 2427

                #8
                Are you allowed to use tools like lex and yacc?

                The C language doesn't lend itself well to simple parsing. For instance, each time a typedef is encountered it changes the parsing rules for the downstream source code. Are you allowed to simplify the problem by forbidding features such as this?

                Comment

                Working...