Giter Club home page Giter Club logo

python_interpreter's Introduction

Python_Interpreter

Object

The project is built based on UIUC CS-421 MP2 (https://github-dev.cs.illinois.edu/cs421-su21/release.git)

Running Code

Install Haskell: https://www.haskell.org/platform/

To run the interpolator, start GHCi with stack ghci. From here, run REPL by calling main.

Type Python commands under Python REPL:

Python>

Use exit() or cmd + c to quit the interpolator.

To test the interpolator use the embedded test, use the following command:

$ stack test

To check all the unit and property test been implemented, it is recommended to use the following command:

$ stack test interpreter\:test\:friendly-test

The friendly test spec can be found in test/friendly/FriendlySpec.hs.

Interpolator Functions

Constants

Recognizable constants include

  • integer (both positive and negative)
  • double (both positive and negative)
  • string (the combination of letters, numbers, marks, punctuation, symbols and spaces, excluding double quote ")

Variables

Assign a constant to a variable The variable name should start with a letter or a underscore. The latter part of the variable name can be letter, number, or underscore.

Python> a = 3

Python> print(a)
3

Basic Operations

Arithmetic Opeartions

Arithmetic operations (+, -, * and /) for integer and double values.

Bool Operations

Bool operations (and, or and not) for bool values (True and False)

Comparison Opeartions

Comparison operations (<, >, <=, >=, /=, ==) for integer and double values.

Python Built-in Functions

abs(x)

Return the aboslute value of a number.

Python> abs(-4)
4
Python> abs(-4.1-9.0)
13.1

bool(x)

Return a Boolean value. x is converted using the standard truth testing procedure.

Python> bool(3.2)
True
Python> bool(-1)
True
Python> bool(0)
False
Python> bool(0.0)
False
Python> bool("ab")
True
Python> bool(True)
True
Python> bool(False or True)
True
Python> bool(not False)
True

chr(i)

Return the string representing a character whose Unicode code point is the integer i.

Python> chr(97)
'a'
Python> chr(45)
'-'

eval(expression)

Evaluate the value of the expression.

Python> eval(1+1)
2
Python> a=4

Python> eval(a+2)
6

print()

Print string or value of an expression given in the argument.

Python> a="Test"

Python> print(a)
"Test"

round(number, ndigits)

Return number rounded to ndigits precision after the decimal point.

Python> round(-8.021,2)
-8.02

To-do

Expression statement

When input an expression, such as a variable expression, display its value. Now it cannot be realized, because an expression statement could be interpolated as a set statement.

Integer and double operations

Currently, the arithmetic and comparison operations require the two operators to be of the same type (int or doulbe). Need to extend to accept mixed data types.

python_interpreter's People

Contributors

jasonzjc avatar

Watchers

James Cloos avatar  avatar

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.