LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 03-06-2010, 09:51 AM   #1
raheeel
LQ Newbie
 
Registered: Mar 2010
Posts: 1

Rep: Reputation: 0
have question in Compiler Construction


hi all
I happy to be brat of
Actually I have HW and I need your helps to solve it please


Implement a table-driven scanner for our simple language called SL. Our SL language has the following four subsets:

Keywords
program, int, perform, get, put.

Simple operators
+ - * / =
Token Delimiters
comma, semicolon

Block Delimiters
comma, semicolon

String Delimiters
Double quote

Identifiers
User defined variables starts with a letter and followed by only two digits (e.g. a99, x00, etc.)

Line Comments
Start with the escape sequence “// “ (e.g. // this is a comment line )

Input/Output
Consider the following simple program in our SL language as the input to your lexical analyzer:

// this program evaluates arithmetic expression

program P01
{
int a99, b99; // declare a99 and b99 as integer variables

get b99; // read b99 from keyboard
perform a99 = 10+20; // do or perform arithmetic calculation
put “sum=”, a99; // display the result
}

The task of the scanner is to identify tokens and extract the lexemes. The program should output the results of lexical analysis either on the screen or to a separate file called “lextokens” in terms of the following classification:

Token type Token ID Lexeme/ Value
Keyword 1 1: program
2: int
3: perform
4: get
5: put
Identifier 2 n: Symbol table entry address
Integer Constants 3 n: Symbol table entry address
String Constants 4 n: Symbol table entry address
Operator 5 1: +
2: -
3: *
4: /
5: =
Delimiter 6 1: semicolon
2: comma
Block 7 1: {
2:: }




Finally, your program should produce token pairs (i.e. token and its value) and the symbol table as follows:
(1,1), (2,0), (7,1), . . . . . . .

Entry Symbol pseudoID symbol type symbol’s initial value
address or
internal ID

0 P01 id0 name -
1 a99 id1 int 0
2 b99 id2 int 0
3 “10” ic1 int 10
4 “20” ic2 int 20
5 “sum=” sc2 string “sum=”
 
Old 03-06-2010, 10:01 AM   #2
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,053

Rep: Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881
Quote:
Originally Posted by raheeel View Post
hi all
I happy to be brat of
Actually I have HW and I need your helps to solve it please
....

Implement a table-driven scanner...
I don't want to do a Venn diagram of this post, but the two obvious divisions seem to be the bits that smell of homework and the bits that I don't understand. I don't think you'll get anyone doing your homework for you here.
 
Old 03-06-2010, 10:01 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.

Please feel free to start a new thread that meets these guidelines.
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
understanding 1,p$ construction in ed phenomenix Linux - Newbie 5 02-12-2010 12:01 AM
Message Construction ranjeet_badhe Linux - Software 1 05-30-2006 02:59 PM
compiler question xviddivxoggmp3 Programming 2 03-15-2004 01:50 PM
compiler question... toadbark Linux - Newbie 8 05-31-2003 07:36 PM
Compiler question [EMOBA] Linux - Software 4 05-28-2002 05:42 AM


All times are GMT -5. The time now is 08:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration