473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 3182
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
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
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
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
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
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
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
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
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
by: Antoninus Twink | last post by:
On 19 Jun 2008 at 21:27, vaib wrote: Check out yacc (aka bison).
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.