473,479 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: newbee help : parser in C


"vaib" <va************@gmail.comwrote in message
news:26**********************************@f24g2000 prh.googlegroups.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
Jun 27 '08 #1
4 3189
On Jun 20, 3:41*pm, "Bartc" <b...@freeuk.comwrote:
"vaib" <vaibhavpang...@gmail.comwrote in message

news:26**********************************@f24g2000 prh.googlegroups.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 .
Jun 27 '08 #2
vaib wrote:
"Bartc" <b...@freeuk.comwrote:
>"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.pascal.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 **
Jun 27 '08 #3
On Jun 26, 2:47*am, CBFalconer <cbfalco...@yahoo.comwrote:
vaib wrote:
"Bartc" <b...@freeuk.comwrote:
"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.pascal.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.com**
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 .
Jun 27 '08 #4
vaib wrote:
CBFalconer <cbfalco...@yahoo.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.pascal.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 **
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1912
by: Newbee | last post by:
Hi ! Let's say that this is the folder on the server: /web/firstDir/secondDir/images/image.gif where i have stored my pictures. I have tryed with apsolute and relative paths but i can't display...
1
5265
by: Karalius, Joseph | last post by:
Can anyone explain what is happening here? I haven't found any useful info on Google yet. Thanks in advance. mmagnet:/home/jkaralius/src/zopeplone/Python-2.3.5 # make gcc -pthread -c...
3
3099
by: Himanshu Garg | last post by:
Hello, I am trying to pinpoint an apparent bug in HTML::Parser. The encoding of the text seems to change incorrectly if the locale isn't set properly. However Parser.pm in the directory...
2
1619
by: Newbee Adam | last post by:
some said that .NET app can run on any program where rutime exists. What is "runtime" in this sense? will I have to install runtime or .net framework or .NET support on an xp machine for a...
4
1767
by: PerryC | last post by:
All, 1. Do the following codes seem ok? 2. If so, then how do I pull the value of YOE1 and YOE2 into my report? (to do some further calculations) ...
2
1851
by: Martin Hvidberg | last post by:
Dear list I have found a declaration like this: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <math.h> #include "ectemp.h"
5
1295
by: consternation | last post by:
I can't find neither in tutorial nor with google It's all about isinstance, or __class__. How to test that an object is an instance of my X class?? Do I have this problems because I stre my...
0
2207
by: UncleRic | last post by:
Environment: Mac OS X (10.4.10) on MacBook Pro I'm a Perl Neophyte. I've downloaded the XML::Parser module and am attempting to install it in my working directory (referenced via PERL5LIB env): ...
5
247
by: Antoninus Twink | last post by:
On 19 Jun 2008 at 21:27, vaib wrote: Check out yacc (aka bison).
0
7027
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7019
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
6847
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5312
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4463
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2970
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
555
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.