Link to home
Start Free TrialLog in
Avatar of k_f_v
k_f_v

asked on

displaying the language of the program in an input file

HOW DO I WRITE A PROGRAM IN C WHOSE INPUT IS A FILE CONTAINING A PROGRAM IN C LANGUAGE.THE PROGRAM SHOULD OUTPUT THE LANGUAGE OF THE PROGRAM IN THE INPUT FILE.

HOW DO I WRITE A PROGRAM IN C WHOSE INPUT IS A FILE CONTAINING A PROGRAM IN C LANGUAGE.THE PROGRAM SHOULD OUTPUT THE LANGUAGE OF THE PROGRAM IN THE INPUT FILE.

HOW DO I WRITE A PROGRAM IN C WHOSE INPUT IS A FILE CONTAINING A PROGRAM IN C LANGUAGE.THE PROGRAM SHOULD OUTPUT THE LANGUAGE OF THE PROGRAM IN THE INPUT FILE.

Avatar of AlexVirochovsky
AlexVirochovsky

Homework ?
You would need to have your program recognise the syntax and grammar of all the languages you would want to recognize.

looks like a difficult question.

if the input programs are guaranteed to be correct (in the language they are wriiten in, at least syntaticall, grammatically correct) then you can just call for every input file a compiler of that language.
if the compiler returns an error you switch to the next compiler, until you either get a positive response, or you run out of compilers.

I can sketch you a pseudo-code if you want.

please tell me more which tools are available to you and which languages you want to recognise.
How many languages do you need to check for?
Avatar of ozo
If the input is a file containing a program in c language,
then this program in c will output the language of the program in the input file:

#include <stdio.h>
int main(void){
    puts("c language");
}
ozo, I think U didn't read the question properly. This should be the right one:

#include <stdio.h>
int main(void)
{
   puts("THE LANGUAGE OF THE PROGRAM IN THE INPUT FILE.");
}

ASKER CERTIFIED SOLUTION
Avatar of mrbrocoli
mrbrocoli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you didn't actually say anything new to what I've already mentioned before...  mrbrocoli.

Pretty rude of you to post it as an answer!
shlomoy: read the 2nd part of the answer
I did.
so?
read again
read it again, so?
Avatar of k_f_v

ASKER

to mrbrocoli,

could u please give me a clue on how to go about it.

thankx
Something like this:

sprintf(cmdline, "compiler_name_and_flags %s", input_file);
res = system(cmdline);
if (res == EXIT_SUCCESS) {
    puts("input file is a valid C program");
} else {
   puts("dont know whats in the input file");
}
Avatar of k_f_v

ASKER

thankx
Avatar of k_f_v

ASKER

to mrbrocoli ,
can u pls give me an example of an input file. i am a little confused.

Avatar of k_f_v

ASKER

i am a little confused . can u pls tell me what will be in the input file