Solved

tokenize sourcecode, compiler design

Posted on 2004-04-26
9
410 Views
Last Modified: 2010-04-15
in which tokens would a C compiler tokenize this little func?

int max(int i, int j)
/* this is a comment */
{
  return i > j ? i : j;
}
0
Comment
Question by:jakl
  • 4
  • 3
9 Comments
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
homework ?
0
 

Author Comment

by:jakl
Comment Utility
should have known...
answer or dont, if i told you it was not homework you wouldnt believe it anyway.
0
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
jakl,

Please realize that experts are here to provide solutions and they do not derive pleasure out of declining to answer questions.
Your profile says that you are a student. The question is simple and homework like and unfortunately your reply is not very convincing.

Study and reasearch is an integral part of learning. I am afraid you will have to do your homework yourself. However, if you get stuck on something specific, ask here.

sunnycoder
0
 
LVL 2

Expert Comment

by:anupvijay
Comment Utility
Hey Jakl,
Don't be disappointed....
Just tell us what you have understood of the question and what answer you have come out with....
All of us here will really help you if you are really stuck.
Cheers.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jakl
Comment Utility
heh, disappointed? i think not. after all, this is just a question in some forum.

just for the sake of it..  the question is from an ebook in pdf format(one file per chapter). after every chapter there is a summary in form of some exercises. unfortunately the answer-appendices are missing.

well, these are the tokens i came up with and just wanted to get checked:

identifiers: max i j
operators: ( ) = > ? :
punctuators: { } , ;
keywords: int return
constants: -
string constants: -

nevermind if they are correct or not. i really dont know why im explaining myself here...
0
 

Author Comment

by:jakl
Comment Utility
well then, lets discuss.
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 125 total points
Comment Utility
int max(int i, int j)
/* this is a comment */
{
  return i > j ? i : j;
}

identifiers: max i j        ........ right
operators: ( ) = > ? :    .... there was no =
punctuators: { } , ;        ..... right
keywords: int return       .... right
constants: -
string constants: -

lexer gets to see the comments too .. though it does not form tokens out of them for further processing ....

you were pretty good

cheers
0
 

Author Comment

by:jakl
Comment Utility
thanks.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now