This test is designed to test your skills, and style in the Java programming language. The test 
should be done in Java 5. There are only two requirements for you solution to this test: 1. it must 
work as described 2. we must be able to compile it. Since this test is designed to test you skills and 
knowledge in the Java programming language, make sure that you apply good coding pratices and 
object oriented design to your solution. The solution must be sent to [email protected]. The 
result file must contain the source code of your solution, as well as a readme file explaining how to 
run it. Include the detailed steps required to compile your solution in the readme file (this includes 
the javac command, the libraries to import etc...).
Good Luck!
Problem : Calculator application
Write a command line application that takes a mathematical expression as input and prints 
the result to the console.
The mathematical expression should be read from a file. The expression can use integer 
numbers only (but the result can be a floating number), and the only supported operators are +, -, *, 
/. The expression can use parentesis "(" and ")" to group operations. The * and / operators have the 
priority on the + and – operators.
Sample input file:
2 + 3 * (4+5) – 4/5
Sample console output:
2 + 3 * (4+5) – 4/5 = 28.2
Typical application usage:
java -jar calc.jar input.txt
The exact EBNF grammar for the acceptable input expressions is the following
Expression EBNF grammar:
expression = term (operator expression)?
term = number | '(' expression ')'
number = (('-')? non_zero_number (non_zero_number | '0')*) | '0'
non_zero_number = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
operator = '*' | '/' | '+' | '-'
Feel free to transform this grammar to an equivalent one if you feel the need to. If you do, 
please include the modified grammar in your classes' documentation.

解决方案 »

  1.   

    就是喊你按他要求用EBNF语法 写个计算器撒
      

  2.   

    大概翻译了一下,本人译的不好,请楼下的朋友纠正:本测试是为了测试您的编程技巧和风格,本测试应该在JAVA5下完成,您只须解决两个问题:
    1。它必须能按要求运行
    2。我们必须能编译它因为本测试是为了测试您在JAVA语言领域的技巧和知识,请务必在答案中使用好的代码practices(不知道这个词如何意译,实践?请楼下补充)和面向对象设计。请将答案发送到 [email protected]  ,请附上您的程序源代码,以及一个readme文件,里面说明如何使用您的程序和编译程序的详细步骤(包括JAVAC命令,编译需要导入的包等等)。祝好运!题目: 计算应用。
    输入一条数学表达式的命令,程序可以输出结果。该表达式可以从一个文件中读取,并且只能使用整数(但是结果可以使用浮点数),并且只支持下面几个运算符:+ - * /  可以使用小括号"(",")"来确定优先关系,*, /运算优先于+ ,- 运算。输入示例:
    2 + 3 * (4+5) – 4/5
    输出的结果示例:
    2 + 3 * (4+5) – 4/5 = 28.2典型的用法:
    java -jar calc.jar input.txt输入文件中表达式的精确的EBNF文法是:(译注:扩展的巴科斯-诺尔范式 Extended Backus-Naur Form,EBNF )
    expression = term (operator expression)?
    term = number | '(' expression ')'
    number = (('-')? non_zero_number (non_zero_number | '0')*) | '0'
    non_zero_number = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
    operator = '*' | '/' | '+' | '-'需要的话您完全可以把上面的语法转换成等价的表达式,如果您做了转换,那么请在您的程序中附加转换后的语法。
      

  3.   

    译注:扩展的巴科斯-诺尔范式 Extended Backus-Naur Form,EBNF ---------------------------------------------
    不理解这个,还以为是个正则表达式呢。
      

  4.   

    按照我的理解,只要能根据一个输入的字符串,按照合适的方法解析,然后输出运算结果就可以了。建议楼主使用 StringTokenizer。很容易了。上面E文原文中,废话多,而且还有若干语法错误。貌似里面的人对JAVA的理解也只是停留在C/S的时代。什么公司啊,没事不建议楼主去了。考这么无聊的题
      

  5.   

    大家也不用考虑那个EBNF了。
    都是废话来的。出考题的人为了卖弄自己的知识罢了。楼主按照小学的数学知识来弄就可以了。
      

  6.   

    我看着也觉得不太难,西电出的那本java基础教程上有个很类似的例题,不过要求中要用到编译原理中的好多知识,哎,忘记的差不多了,祝楼主好运!
      

  7.   

    应该不是了。不过确实有点bt,需要去读取txt文件的,对于多数借助工具的,到这里就over了。
    大家注意看这个:
    java -jar calc.jar input.txt
      

  8.   

    理解是理解了,ebnf是什么飞机!?
      

  9.   

    那些EBNF找本编译原理看看就会了
    其实就是读入数据做计算,用逆波兰表达式,这个赵数据结构
    怎么感觉这个题是对应届毕业生的呢?
      

  10.   

    确实是考逆波兰表达式和txt文件操作
    几年前考程序员的时候学过了
    忘了