Re: newbee help : parser in C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bartc

    Re: newbee help : parser in C


    "vaib" <vaibhavpanghal @gmail.comwrote in message
    news:26a44cc5-0f08-41fe-859b-0d27daf3ca1d@f2 4g2000prh.googl egroups.com...
    hi all . i am trying to build a parser in ANSI C . I made a lexical
    analyser in the same language a while ago . It was a very simple lexer
    that tokenised a simple C source code text file - basically a very
    simple lexer . I had made use of hash tables for the data structure .
    Now i want to know how to build a parser . I'll let you know what i
    know about parser building - i'll need a grammar written in the form
    of regular expressions , i would need to implement something called a
    parse tree in a data structure of my choice and so on.
    I don't know the formal approach to these things but I haven't come across
    an RE grammar before, not for an entire language anyway.

    The usual approach if you're not using external tools is to program using
    'recursive descent' or top-down, whatever the term is. In this case the
    grammar is built-in to the code. You will need a tokeniser too, which it
    seems you already have.

    Then you have all you need and top-down is really easy! But you have to
    decide what the output will be, and typically this will be some tree
    representation of the syntax.

    I don't have any /simple/ examples however (and they're not in C). But if
    you post a simple grammar example (which I can understand as I don't know
    RE), then maybe I can give a bit more help.


    --
    Bartc


  • vaib

    #2
    Re: newbee help : parser in C

    On Jun 20, 3:41 pm, "Bartc" <b...@freeuk.co mwrote:
    "vaib" <vaibhavpang... @gmail.comwrote in message
    >
    news:26a44cc5-0f08-41fe-859b-0d27daf3ca1d@f2 4g2000prh.googl egroups.com...
    >
    hi all . i am trying to build a parser in ANSI C . I made a lexical
    analyser in the same language a while ago . It was a very simple lexer
    that tokenised a simple C source code text file - basically a very
    simple lexer . I had made use of hash tables for the data structure .
    Now i want to know how to build a parser . I'll let you know what i
    know about parser building - i'll need a grammar written in the form
    of regular expressions , i would need to implement something called a
    parse tree in a data structure of my choice and so on.
    >
    I don't know the formal approach to these things but I haven't come across
    an RE grammar before, not for an entire language anyway.
    >
    The usual approach if you're not using external tools is to program using
    'recursive descent' or top-down, whatever the term is. In this case the
    grammar is built-in to the code. You will need a tokeniser too, which it
    seems you already have.
    >
    Then you have all you need and top-down is really easy! But you have to
    decide what the output will be, and typically this will be some tree
    representation of the syntax.
    >
    I don't have any /simple/ examples however (and they're not in C). But if
    you post a simple grammar example (which I can understand as I don't know
    RE), then maybe I can give a bit more help.
    >
    --
    Bartc
    all right . thank you so much . i really find people here who help me
    all the time .

    Comment

    • CBFalconer

      #3
      Re: newbee help : parser in C

      vaib wrote:
      "Bartc" <b...@freeuk.co mwrote:
      >"vaib" <vaibhavpang... @gmail.comwrote in message
      >>
      >>hi all . i am trying to build a parser in ANSI C . I made a
      >>lexical analyser in the same language a while ago . It was a
      >>very simple lexer that tokenised a simple C source code text
      >>file - basically a very simple lexer . I had made use of hash
      >>tables for the data structure .
      >>>
      >>Now i want to know how to build a parser . I'll let you know
      >>what i know about parser building - i'll need a grammar written
      >>in the form of regular expressions , i would need to implement
      >>something called a parse tree in a data structure of my choice
      >>and so on.
      >>
      >I don't know the formal approach to these things but I haven't
      >come across an RE grammar before, not for an entire language
      >anyway.
      >
      .... snip ...
      >
      all right . thank you so much . i really find people here who
      help me all the time .
      I suggest you look at the source for the portable Pascal compiler,
      available on the ISO Pascal pages. You can find out about that on
      comp.lang.pasca l.ansi-iso newsgroup. It uses recursive descent.

      Similar techniques will teach you much more than just using lex and
      yacc. The first step is a useful lexer, that separates out
      reserved words, identifiers, numerics, char symbols, etc. There is
      no need for hash tables here. When you get to things that develop
      symbol tables etc. that is another matter, and I recommend looking
      at my hashlib, available at:

      <http://cbfalconer.home .att.net/download/hashlib.zip>

      --
      [mail]: Chuck F (cbfalconer at maineline dot net)
      [page]: <http://cbfalconer.home .att.net>
      Try the download section.


      ** Posted from http://www.teranews.com **

      Comment

      • vaib

        #4
        Re: newbee help : parser in C

        On Jun 26, 2:47 am, CBFalconer <cbfalco...@yah oo.comwrote:
        vaib wrote:
        "Bartc" <b...@freeuk.co mwrote:
        "vaib" <vaibhavpang... @gmail.comwrote in message
        >
        >hi all . i am trying to build a parser in ANSI C . I made a
        >lexical analyser in the same language a while ago . It was a
        >very simple lexer that tokenised a simple C source code text
        >file - basically a very simple lexer . I had made use of hash
        >tables for the data structure .
        >
        >Now i want to know how to build a parser . I'll let you know
        >what i know about parser building - i'll need a grammar written
        >in the form of regular expressions , i would need to implement
        >something called a parse tree in a data structure of my choice
        >and so on.
        >
        I don't know the formal approach to these things but I haven't
        come across an RE grammar before, not for an entire language
        anyway.
        >
        ... snip ...
        >
        all right . thank you so much . i really find people here who
        help me all the time .
        >
        I suggest you look at the source for the portable Pascal compiler,
        available on the ISO Pascal pages.  You can find out about that on
        comp.lang.pasca l.ansi-iso newsgroup.  It uses recursive descent.
        >
        Similar techniques will teach you much more than just using lex and
        yacc.  The first step is a useful lexer, that separates out
        reserved words, identifiers, numerics, char symbols, etc.  There is
        no need for hash tables here.  When you get to things that develop
        symbol tables etc. that is another matter, and I recommend looking
        at my hashlib, available at:
        >
           <http://cbfalconer.home .att.net/download/hashlib.zip>
        >
        --
         [mail]: Chuck F (cbfalconer at maineline dot net)
         [page]: <http://cbfalconer.home .att.net>
                    Try the download section.
        >
        ** Posted fromhttp://www.teranews.co m**
        thank you for replying . right now i am reading 'lex and yacc' . i
        plan to use yacc for generating a parser and then read its code ( ie ,
        the generated parser's code ) and then continue my parser construction
        study from the 'dragon book' . then i hope to have a clear picture in
        my mind as to what 'exactly' has to be done in parser coding . am i
        right in my approach ?? i generally avoid reading the code of the
        already stable compilers sice it takes a lot of time for me to do that
        and to figure out the complete code (...even of the front-end ) . do
        you think my approach is right or is there a speedier way to it ?
        thank you again for replying .

        Comment

        • CBFalconer

          #5
          Re: newbee help : parser in C

          vaib wrote:
          CBFalconer <cbfalco...@yah oo.comwrote:
          >
          .... snip ...
          >
          >I suggest you look at the source for the portable Pascal compiler,
          >available on the ISO Pascal pages. You can find out about that on
          >comp.lang.pasc al.ansi-iso newsgroup. It uses recursive descent.
          >>
          >Similar techniques will teach you much more than just using lex and
          >yacc. The first step is a useful lexer, that separates out
          >reserved words, identifiers, numerics, char symbols, etc. There is
          >no need for hash tables here. When you get to things that develop
          >symbol tables etc. that is another matter, and I recommend looking
          >at my hashlib, available at:
          >>
          > <http://cbfalconer.home .att.net/download/hashlib.zip>
          >
          thank you for replying . right now i am reading 'lex and yacc'. i
          plan to use yacc for generating a parser and then read its code (ie,
          the generated parser's code) and then continue my parser construction
          study from the 'dragon book'. then i hope to have a clear picture in
          my mind as to what 'exactly' has to be done in parser coding. am i
          right in my approach ?? i generally avoid reading the code of the
          already stable compilers sice it takes a lot of time for me to do
          that and to figure out the complete code (...even of the front-end).
          do you think my approach is right or is there a speedier way to it?
          I am darned if I know. I went through this process about 30 to 40
          years ago, so my memory of it is dim.

          --
          [mail]: Chuck F (cbfalconer at maineline dot net)
          [page]: <http://cbfalconer.home .att.net>
          Try the download section.


          ** Posted from http://www.teranews.com **

          Comment

          Working...