Compiler Construction: Design A Scanner

A Member? Please Login  
type your username and password to login
Date: November 19, 2008, 09:30 AM
262552 members and 159904 Topics
Latest Member: oxiang
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming (Moderator: Dual Core)  |  Compiler Construction: Design A Scanner
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Compiler Construction: Design A Scanner  (Read 245 views)
chatykrew (m)
Compiler Construction: Design A Scanner
« on: March 10, 2007, 08:00 PM »

Hi guys, its great that there is a site like nairaland. More grease to the owners.
Well i don't know whether this is the right place to ask this question with regards to compiler. but i hope someone can help or direct me to a site that might help.

Design a scanner for the following instruction
A=:B+10*(C-D)

write a program to simulate the action of the above state diagram

Thanks
wavemasta (m)
Re: Compiler Construction: Design A Scanner
« #1 on: March 22, 2007, 08:33 AM »

Compiler construction isn't beans. I'm doing it here, and even the foreign students are moaning in agony.
Didnt mean to scare you. I think you'd need a good book, or search for tutorials on the net.

As to your question, I'm assuming you already have rudimentary knowledge of compilers.

A scanner is a lexical analyser, and its responsible for breaking your input string into tokens.

So A+B fed as input to your scanner should produce tokens "A", "B"  and "+"
 
So you need to :

First change the expression to reverse polish (or postfix notation) if i'm not mistaken.

So if you have an expression like A+B, it becomes AB+. You can google up some code snippets to do that i suppose.


So your program should be able to

1. Read the input as a string i.e A+B

2. Break it down into tokens AB+ (changing it to reverse polish notation)

3. If i were you, a quick programming jutsu (yes I like naruto  Grin ) would be to store the reverse polish stuff in a char array, then
   copy them into another array, with a whitespace in between them.

But Id advise you to read it up and not tjust blindly take my word for it.

cheers
gurmen (m)
Re: Compiler Construction: Design A Scanner
« #2 on: March 23, 2007, 08:41 PM »

Hello, i'm a new member. I need materials on Compiler contruction.
DJNiyi (m)
Re: Compiler Construction: Design A Scanner
« #3 on: March 24, 2007, 02:37 PM »

Wavemasta is pretty much on point there.

chatykrew, lexical analysis is the first part but then you have to do syntax analysis, semantic analysis and object code generation and optimization. Are you required to do this as well?

This topic creates a lot of nostalgia so if you can you give us an idea of the whole project, I'm sure some of us will be able to help/guide you.

For example, does your uni or college list the details of the assignments on a project page? If so, send us the link.

Regards
 Looking To Outsource Web Application Development To Nigeria  Error Running Asp.net Application  Freelance Php Coder Wanted  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Job Talk Jobs/Vacancies (2) Career Talk Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.