Hi
I got one assignment to submit within 2 days.I am suppose to build scanner(lexicle analyser) in c,which will take input from standard input stream and print its class.
for example if I input + it will displya "plus",- "minus"
I have to run this program in unix environment.
program will have main function which will accept character from input stream
and call scanner function to get its type.
I have to use getchar(),putcar() and ungetc() functions for this.
I dont know how to use unggetc function withh stdin(standard input).
there will be buffer which will be difeined globally and can be accessed by all the functions.I also want to know how to compile the and run the file in unix enviornment.
I have lost thhe touch with 'c'.Didntdo it from last 2 years.
code will be somewhat like this
main()
{
char msg [][]={"plus","minus"};....(dont know howto use this,gives error char const too long)int code;
char next;
next=getchar();
putchar(next);
ungetc(next);
code=scanner();
while(code!=EOF)
{
print msg;
print buffer;
code=scanner();
}
int scanner()
{
int code;
char next;
if(next=='+')
{
code=get_plus();
}elseif(next=='-')
{code=get_minus();}
return code;
}