C Programming Assignment:

J

janconway

Hey, kinda bit lost with the lab assignment in college. any tips would be really appreciated.
basically we were given a flex file and we've to modify it to see if a string is a keyword or identifier within C itself. Just a bit lost as to where to start.
do i initialise a linked list to compare the two arrays or what?
 
C

CBFalconer

janconway said:
Hey, kinda bit lost with the lab assignment in college. any tips
would be really appreciated. basically we were given a flex file
and we've to modify it to see if a string is a keyword or
identifier within C itself. Just a bit lost as to where to start.
do i initialise a linked list to compare the two arrays or what?

Or what.
 
G

Grumble

janconway said:
Hey, kinda bit lost with the lab assignment in college. any tips
would be really appreciated. basically we were given a flex file
and we've to modify it to see if a string is a keyword or
identifier within C itself. Just a bit lost as to where to start.
do i initialise a linked list to compare the two arrays or what?

The comp.compilers newsgroup seems more appropriate.

The following document might help:
http://www.tldp.org/HOWTO/Lex-YACC-HOWTO.html
 
G

GVK

janconway said:
Hey, kinda bit lost with the lab assignment in college. any tips would be really appreciated.
basically we were given a flex file and we've to modify it to see if a string is a keyword or identifier within C itself. Just a bit lost as to where to start.
do i initialise a linked list to compare the two arrays or what?
If it is just a C programming assignment(no knowlegdge of compilers,
parsers etc. is assumed), you can take a two dimensional array
containing all the keywords,identifiers etc

key[][] = { "int","float",etc etc}

and compare with strcmp(input,key) for all i. This was how I did MY
assignment :)

regards,
GVK
 
M

Malcolm

janconway said:
basically we were given a flex file and we've to modify it to see if a
string is a keyword or identifier within C itself. Just a bit lost as to
where to start.
Start by writing this function

char *getidentifier(char *line, char *id)

Return NULL if you run to the end of the line without reading an identifier,
else return the position immediately past the id you just read. To make it
robust, set a max length for id.
do i initialise a linked list to compare the two arrays or what?
You could use a linked list, but a simple array of all the keywords would be
easier. What is the output format?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top