Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,820 members, 7,817,394 topics. Date: Saturday, 04 May 2024 at 11:27 AM

Compiler Construction: Design A Scanner - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Compiler Construction: Design A Scanner (2829 Views)

Java online compiler for swing programs / Pls Help, Website For C/c++ Compiler Free Download Windows 7 / Facebook Releases A Php Just-in-time Compiler (2) (3) (4)

(1) (Reply) (Go Down)

Compiler Construction: Design A Scanner by chatykrew(m): 8:00pm On Mar 10, 2007
Hi guys, its great that there is a site like nairaland. More grease to the owners.
Well i dont 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
Re: Compiler Construction: Design A Scanner by Nobody: 8:33am On Mar 22, 2007
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, Im 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
Re: Compiler Construction: Design A Scanner by gurmen(m): 8:41pm On Mar 23, 2007
Hello, i'm a new member. I need materials on Compiler contruction.
Re: Compiler Construction: Design A Scanner by DJNiyi(m): 2:37pm On Mar 24, 2007
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

(1) (Reply)

Hints Needed / So Hard To Female Software Programmers / Which Php Framework Do You Use?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.