Solved

tokenize sourcecode, compiler design

Posted on 2004-04-26
9
411 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
ID: 10918676
homework ?
0
 

Author Comment

by:jakl
ID: 10918690
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
ID: 10918863
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
ID: 10919563
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:jakl
ID: 10926438
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
ID: 10938655
well then, lets discuss.
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 125 total points
ID: 10967146
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
ID: 10968887
thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

910 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

24 Experts available now in Live!

Get 1:1 Help Now