如何验证输入的功能 [英] how do to validate a inputted function

查看:89
本文介绍了如何验证输入的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以有一个简单的示例程序,让用户输入一个函数,然后评估函数,然后给出输出值。

变量的值是预先定义的。



假设我有这个代码接受来自用户的int值



can i have a simple sample program that lets the user input a function then evaluates the function then gives the output value.
the values of the variables are pre-defined.

lets say i have this code that accepts int values from the user

#include<stdio.h>
main
{
int A,B,X,VAL;
printf("enter a number:");
scanf("%d",&A);

printf("enter a number:");
scanf("%d",&B);

printf("enter a number:");
scanf("%d",&X);

Val= (A * X) + B;

printf("the value of the function is %d",Val);
}





现在我需要一个非常简单的代码,用户这次将是输入该功能的用户。我对C的了解很广泛。我从来没有看到一个程序要求用户输入一个函数而不是一个值,所以这是我第一次遇到这种问题。



我只是打算使用示例代码来理解这样的程序是如何完成的,这样我就可以继续解决我们老师要求我们做的机器问题。





谢谢:))))



now I need a really simple code in which the user this time will be the one to input the function. my knowledge on C is that wide. I've never saw a program that asks the user to input a function instead a value so this the first time I've encountered this sort of problem.

Im just going to use the sample code on understanding how a program like that is done so I can proceed with the machine problem our teacher tasked us to do.


thank you :)))

推荐答案

这不是一项简单的任务,因为C不是解释性语言。虽然此操作在脚本和解释语言(如Bash,Java等)中是可行的,但C要求在执行之前编译和链接程序。



所以, 这不可能。可以手动使用一些C语法分析器和代码来解释,但是考虑到编写一个简单的编译器(仍然比普通程序员高一级)这个任务很难。



希望有所帮助,

Denis
That is not a trivial task because C is not an interpreted language. While this operation is feasible in scripting and interpreted languages (like Bash, Java and so on), C requires that the program is compiled and linked before executing it.

So, it is not possible. It is possible to use some C parser and code manually the interprete, but consider that it is a task as difficult as writing a simple compiler (still a level higher than the averageprogrammer).

Hope to be of help,
Denis


欢迎来到数学表达式解析器的世界。您可以使用 Shunting-yard算法 [ ^ ]。
Welcome in the world of mathematics expression parser. You may use the Shunting-yard algorithm[^].


给所有回答我问题的人,谢谢。

基本上我们负责的机器问题是关于触发器设计



我遇到了用户需要的第5个输入问题提供哪个是功能。基本上是一个数学表达式(抱歉:) :)

遗憾的是,我还没有学习Java Classes和C ++。我只知道C,这就是为什么很难找到实现这种评估的方法。





我还有另一个问题。同样的问题,但这次我将使用的IDE是Visual Basic 6.可能还是Java是用于此问题的最佳编程语言?
to all the people who answered my questions, thank you.
basically the machine problem we were tasked to make was about the "flip flop design"

im having problems with the 5th input that the users need to provide which is the function. well basically a mathematical expression (sorry about that :) )
unfortunately, im not yet taking Java Classes and C++. i only know C so thats why its hard to find a way to implement that kind of evaluation.


I have another question though. same problem but this time the IDE that I will use is Visual Basic 6. is that possible or Java is the best programming language to use for this problem?


这篇关于如何验证输入的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆