GithubHelp home page GithubHelp logo

calculator's Introduction

Calculator

学习编译原理写出的一个简单计算器。结果取两位小数。

要求

计算器接受四则运算表达式为输入。如果表达式语法正确,则输出计算结果,否则报错,指出错误位置及原因。

  1. 每个语句需要以“;”结束;
  2. 涉及的操作符只要求加减乘除;支持括号;
  3. 操作数为整数或浮点数;
  4. 变量不需要先声明,可直接赋值,它的类型由右边表达式的类型决定;每个变量在使用之前必须要已经有赋值;
  5. 变量名可以是由数字和字母组成,但首字符必须是字母;
  6. 输出语句使用print()函数,输出并换行;
  7. print()函数不仅可以输出变量,还可以直接输出表达式的值,例如print(1+2)
  8. 接受一个源文件路径为命令行参数。

使用方法

java -jar calculator.jar [sourceFile]

测试用例

test开头的为测试成功的文件。

error开头的为会报错的文件。

缺陷

除数为 0 时不能确定错误发生行中的具体位置。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.