Solved

tokenize sourcecode, compiler design

Posted on 2004-04-26
9
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-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.

738 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