Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

displaying the language of the program in an input file

Posted on 1999-07-24
16
Medium Priority
?
206 Views
Last Modified: 2010-08-05
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.

0
Comment
Question by:k_f_v
[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
  • 4
  • 4
  • +4
16 Comments
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1263856
Homework ?
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 1263857
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.
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 1263858
How many languages do you need to check for?
0
Independent Software Vendors: 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 84

Expert Comment

by:ozo
ID: 1263859
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");
}
0
 
LVL 1

Expert Comment

by:MatthiasLange
ID: 1263860
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.");
}

0
 
LVL 1

Accepted Solution

by:
mrbrocoli earned 300 total points
ID: 1263861
The hard and "correct" way is to implement a compiler
(the lexical/syntactic analizer part only of course)
for C, perhaps using a tool such as lex/yacc. The quick and
dirty (but works) way, is to get a C compiler, run the
compiler on the input file and if the compiler returns
no error, say that the program is a "C Program".
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 1263862
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!
0
 
LVL 1

Expert Comment

by:mrbrocoli
ID: 1263863
shlomoy: read the 2nd part of the answer
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 1263864
I did.
so?
0
 
LVL 1

Expert Comment

by:mrbrocoli
ID: 1263865
read again
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 1263866
read it again, so?
0
 

Author Comment

by:k_f_v
ID: 1263867
to mrbrocoli,

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

thankx
0
 
LVL 1

Expert Comment

by:mrbrocoli
ID: 1263868
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");
}
0
 

Author Comment

by:k_f_v
ID: 1263869
thankx
0
 

Author Comment

by:k_f_v
ID: 2018431
to mrbrocoli ,
can u pls give me an example of an input file. i am a little confused.

0
 

Author Comment

by:k_f_v
ID: 2018442
i am a little confused . can u pls tell me what will be in the input file
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

704 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