I have written a scanner program for oberon language compiler but its incomplete,in the botton i need to write certain code to make this program work properly,so can anyone help me to make this program work properly.

FILE *input;
int row, col;
token t;
char buff[bufflen];
int tabwidth;

int KWidx[] = { 29,  0,  6, 32,  2,  0,  9,  0, 25,  0,
                 4,  0, 21, 12,  0,  0,  0,  0,  0,  0,
                19,  0,  7,  8, 14, 13, 28,  0,  0,  0,
                15, 31, 11, 17,  0, 16, 30, 18,  1,  0,
                10,  3,  0,  5, 22, 26, 23, 24,  0,  0,
                27, 20,  0
               };

char *KWstr[] = { "", "ARRAY", "BEGIN", "BOOLEAN", "BY",
                  "CHAR", "CONST", "DIV", "DO", "ELSE",
                  "ELSIF", "END", "EXIT", "FALSE", "FOR",
                  "IF", "INTEGER", "LOOP", "MOD", "MODULE",
                  "OF", "OR", "PROCEDURE", "REAL", "REPEAT",
                  "RETURN", "STRING", "THEN", "TO", "TRUE",
                  "UNTIL", "VAR", "WHILE"
                };

tokenType KWtok[] = { tokIDENT, kwARRAY, kwBEGIN,
                      kwBOOLEAN, kwBY, kwCHAR, kwCONST,
                      kwDIV, kwDO, kwELSE, kwELSIF, kwEND, kwEXIT, kwFALSE,
                      kwFOR, kwIF, kwINTEGER, kwLOOP, kwMOD,
                      kwMODULE, kwOF, kwOR, kwPROCEDURE, kwREAL,
                      kwREPEAT, kwRETURN, kwSTRING, kwTHEN, kwTO,
                      kwTRUE, kwUNTIL, kwVAR, kwWHILE
                    };

int KWhash(char *s) {
    return (strlen(s) + 83*(s[0]+s[1]) + 139*s[strlen(s)-1]) % 53;
}

tokenType KWsearch(char *s) {
    int h = KWhash(s);
    message(debug, "hash: keyword hash value = %i", h);
    message(debug, "hash: keyword index value = %i", KWidx[h]);
    message(debug, "hash: matching to keyword \"%s\"", KWstr[KWidx[h]]);
    if (strcmp(KWstr[KWidx[h]], s) == 0)
        return KWtok[KWidx[h]];
    else
        return KWtok[0];
}

void strnapp(char *s, char c, int n) {
    int len = strlen(s);
    if (len < n-1) {
        s[len] = c;
        s[len+1] = '\0';
    }
}

int peekCh() {
	int c;
	if (feof(input))
		c = -1;
	else {
		c = getc(input);
		ungetc(c, input);
	}
	return c;
}

int nextCh() {
    int c;
    if (feof(input))
        c = -1;
    else {
        c = getc(input);
        strnapp(buff, (char)c, bufflen);
        if (c == '\r' || c == '\n') { // Mac or Unix EOL
            if (c == '\r' && peekCh() == '\n') // DOS style EOL
                c = getc(input);
            ++row;
            col = 0;
        } else if (c == '\t')
            col = col/tabwidth * tabwidth + tabwidth;  // calculate the tab column
        else
            ++col;
    }
    return c;
}

void scannerInit(FILE *fin) {
    input = fin;
    row = 1; col = 0;  // index of current character
    buff[0] = '\0';
    tabwidth = DEFtabwidth;

    message(debug, "scanner: initialized");
}

int setTabWidth(int t) {
    return tabwidth = t<1?DEFtabwidth:t;
}

int getTabWidth() {
    return tabwidth;
}

token scannerRead() {
    int c; int count;

    c = nextCh();

	/* PLACE YOUR CODE HERE */

    message(debug, "scanner: found %s", tokenString(t));
    return t;
}

Edited 6 Years Ago by __avd: Added [code] tags.

Comments
This is a student of mine trying to get his assignment done for free. You better hope I don't find out who you are.
Stop creating new threads to ask the same question.

where is the problem? Does it compile? Errors?

In addition,

  1. You only need one thread.
  2. What's a scanner?
  3. What's oberon?
  4. Who wrote this code?
  5. Use code tags.

scanner
is a part of compiler
we have to make compiler for oberon language
every compiler is written in some language
this compiler should be written in C language
we have the whole code
of compiler
except scanner.Below u will find a incomplete code,try 2 complete the code.

FILE *input;
int row, col;
token t;
char buff[bufflen];
int tabwidth;

int KWidx[] = { 29,  0,  6, 32,  2,  0,  9,  0, 25,  0,
                 4,  0, 21, 12,  0,  0,  0,  0,  0,  0,
                19,  0,  7,  8, 14, 13, 28,  0,  0,  0,
                15, 31, 11, 17,  0, 16, 30, 18,  1,  0,
                10,  3,  0,  5, 22, 26, 23, 24,  0,  0,
                27, 20,  0
               };

char *KWstr[] = { "", "ARRAY", "BEGIN", "BOOLEAN", "BY",
                  "CHAR", "CONST", "DIV", "DO", "ELSE",
                  "ELSIF", "END", "EXIT", "FALSE", "FOR",
                  "IF", "INTEGER", "LOOP", "MOD", "MODULE",
                  "OF", "OR", "PROCEDURE", "REAL", "REPEAT",
                  "RETURN", "STRING", "THEN", "TO", "TRUE",
                  "UNTIL", "VAR", "WHILE"
                };

tokenType KWtok[] = { tokIDENT, kwARRAY, kwBEGIN,
                      kwBOOLEAN, kwBY, kwCHAR, kwCONST,
                      kwDIV, kwDO, kwELSE, kwELSIF, kwEND, kwEXIT, kwFALSE,
                      kwFOR, kwIF, kwINTEGER, kwLOOP, kwMOD,
                      kwMODULE, kwOF, kwOR, kwPROCEDURE, kwREAL,
                      kwREPEAT, kwRETURN, kwSTRING, kwTHEN, kwTO,
                      kwTRUE, kwUNTIL, kwVAR, kwWHILE
                    };

int KWhash(char *s) {
    return (strlen(s) + 83*(s[0]+s[1]) + 139*s[strlen(s)-1]) % 53;
}

tokenType KWsearch(char *s) {
    int h = KWhash(s);
    message(debug, "hash: keyword hash value = %i", h);
    message(debug, "hash: keyword index value = %i", KWidx[h]);
    message(debug, "hash: matching to keyword \"%s\"", KWstr[KWidx[h]]);
    if (strcmp(KWstr[KWidx[h]], s) == 0)
        return KWtok[KWidx[h]];
    else
        return KWtok[0];
}

void strnapp(char *s, char c, int n) {
    int len = strlen(s);
    if (len < n-1) {
        s[len] = c;
        s[len+1] = '\0';
    }
}

int peekCh() {
	int c;
	if (feof(input))
		c = -1;
	else {
		c = getc(input);
		ungetc(c, input);
	}
	return c;
}

int nextCh() {
    int c;
    if (feof(input))
        c = -1;
    else {
        c = getc(input);
        strnapp(buff, (char)c, bufflen);
        if (c == '\r' || c == '\n') { // Mac or Unix EOL
            if (c == '\r' && peekCh() == '\n') // DOS style EOL
                c = getc(input);
            ++row;
            col = 0;
        } else if (c == '\t')
            col = col/tabwidth * tabwidth + tabwidth;  // calculate the tab column
        else
            ++col;
    }
    return c;
}

void scannerInit(FILE *fin) {
    input = fin;
    row = 1; col = 0;  // index of current character
    buff[0] = '\0';
    tabwidth = DEFtabwidth;

    message(debug, "scanner: initialized");
}

int setTabWidth(int t) {
    return tabwidth = t<1?DEFtabwidth:t;
}

int getTabWidth() {
    return tabwidth;
}

token scannerRead() {
    int c; int count;

    c = nextCh();

	/* PLACE YOUR CODE HERE */

    message(debug, "scanner: found %s", tokenString(t));
    return t;
}

Edited 6 Years Ago by __avd: Added [code] tags.

add a code in it so it work properly

yeah? and how far have you gotten?

i mean besides cutting and pasting your assignment here, as if we're your own personal homework-completion service.

.

Edited 6 Years Ago by jephthah: n/a

i didnt copy and paste my assignment,i wrote the code by my self but in the end iam having problem

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Comments
it just gets more and more pathetic.

i didnt copy and paste my assignment,i wrote the code by my self but in the end iam having problem

No, you copied and pasted what the prof. gave you and are so lazy and arrogant that you didn't bother to change the "Place your code here" part that the teacher put in there.

Or you had so much chutzpah that YOU put it in there.

Or maybe both. Either way you deserve no help.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Comments
I agree.
Amen

i didnt copy and paste my assignment,i wrote the code by my self but in the end iam having problem

yeah right. is that like when you posted:

below u will find a incomplete code,try 2 complete the code.

...

/* PLACE YOUR CODE HERE */

LOL. your incomplete code, hmm?

how 'bout u try 2 lie a little better.

we're not as dumb as you look.

.

Edited 6 Years Ago by jephthah: n/a

Comments
"we're not as dumb as you look" Nice :)

Hurricane123 is a cheater. I recognize this code, it's our department chair's code and he/she knows it.

This is what is going on. Our project consists of writing various parts of an Oberon0 compiler. A good chunk of the compiler has already been written by the department chair, who is teaching the class. He wants us to fill in the missing spots, hence the "/* PLACE YOUR CODE HERE */".

Hurricane123 is trying to cheat their way out of doing the assignment the RIGHT way, by getting the daniweb community to write it. Don't give them a single line of code. If I have to do this project legit, you do to. I have half the mind to turn you in to the department chair for both cheating and plagiarism. I'm sure he wouldn't like it if he knew you were trying to pass his hard work off as your own to cheat in his class.

Don't forget, the code is due Monday at midnight >:-(

Hurricane123 is a cheater. I recognize this code, it's our department chair's code and he/she knows it.

Hurricane123 is trying to cheat their way out of doing the assignment the RIGHT way, by getting the daniweb community to write it.

Thanks for the heads up. But if you read the help we've given, we caught him with his first post. We've been down this road many times over the past few years with people that want a free ride, so we catch on really fast.

Hmm...this looks like my code! Seems one of my students is attempting to cheat and not do the work. I am not sure you can even complete this without the rest of the code (laughing). If I catch the student, I will give you an 'F'.

Dr. Jeff Jenness
Arkansas State University

This article has been dead for over six months. Start a new discussion instead.