473,395 Members | 1,471 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,395 software developers and data experts.

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
Mar 22 '10 #1
7 5193
jkmyoung
2,057 Expert 2GB
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?
Mar 22 '10 #2
jkmyoung
2,057 Expert 2GB
'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?
Mar 23 '10 #3
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.
Mar 24 '10 #4
donbock
2,426 Expert 2GB
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?
Mar 24 '10 #5
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.
Mar 24 '10 #6
jkmyoung
2,057 Expert 2GB
Please give us the language construction rules. Eg simple syntax of a simple programming language could be like:
Expand|Select|Wrap|Line Numbers
  1. code:= <stmt>
  2.            <code>
  3. code:= </>
  4.  
  5. <stmt>:=  If <bool> then
  6.            <code>
  7.            endif
  8.  
  9. <stmt> := <variable> = <value>
  10.  
  11. <bool> := <variable> ?= <value>
  12.  
  13. <variable> := [a-zA-Z][a-zA-Z0-9]*
  14.  
  15. <value> := [0-9]+
  16.  
Mar 24 '10 #7
donbock
2,426 Expert 2GB
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?
Mar 24 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Simon Foster | last post by:
Anyone have any experience or pointers to how to go about creating a parser lexer for assemble in Python. I was thinking of using PLY but wonder whether it's too heavyweight for what I want. ...
19
by: petantik | last post by:
Where can I find a good resource, on the web, that will give me a good comprehensive idea of how to write a compiler in C for C or maybe another language. http://petantik.blogsome.com - A...
2
by: Billy Porter | last post by:
Greetings, I got a class that wraps the System.Data.SqlClient.SqlConnection class (no COM interaction). I'm not sure if I'm supposed to implement the IDisposable pattern for this wrapper or not....
17
by: M.Siler | last post by:
I'm trying to get my head around a conversation I had with a developer the other day. We were talking about Codesmith vs. Hand coding. He's position is Codesmith is for junior to mid level...
3
by: stephen.nil | last post by:
http://code.google.com/p/spxml/ http://spxml.googlecode.com/files/spxml-0.1.src.tar.gz Simple Plain Xml Parser (spxml) is a simple and plain stream-oriented XML parser that supports pull-model and...
30
by: lovecreatesbea... | last post by:
K&R says the following in the preface to the first edition, "... the C compiler, and ... are written in C." I'm wondering, does it say even the first / original C compiler was written in C?
4
by: =?Utf-8?B?QmFqaS4=?= | last post by:
Hi, Can somebody suggest me, how can I implement a vc++ interface in C#.net. This interface has method CallMe( ) which is used as a CallBack from my main application. Thanks, Baji.
0
by: mmayur | last post by:
I'm using ANTLR parser for a txt file of around 5 MB. My main grammer module contains displaying contents between START_TAG(<) and END_TAG(>). fragment ELEMENT : ( (ELEMENT ...
8
by: John | last post by:
Hi, gurus, How can I implement the following feature in C#: Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ", group") For Each objMember In objGroup.Members...
14
by: Thomas Mlynarczyk | last post by:
Hello, I started to write a lexer in Python -- my first attempt to do something useful with Python (rather than trying out snippets from tutorials). It is not complete yet, but I would like some...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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...

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.