Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gigimushroom/system_programming
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.5.0
Choose a base ref
...
head repository: gigimushroom/system_programming
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 14 commits
  • 343 files changed
  • 1 contributor

Commits on Aug 18, 2020

  1. Update Assembler.dat

    gigimushroom committed Aug 18, 2020
    Copy the full SHA
    6c3b81b View commit details

Commits on Aug 19, 2020

  1. some test code

    gigimushroom committed Aug 19, 2020
    Copy the full SHA
    7212ff1 View commit details

Commits on Aug 22, 2020

  1. project 8

    gigimushroom committed Aug 22, 2020
    Copy the full SHA
    123810d View commit details

Commits on Aug 27, 2020

  1. nand2teris proj 8 done

    gigimushroom committed Aug 27, 2020
    Copy the full SHA
    30d7bdc View commit details

Commits on Aug 28, 2020

  1. game of life

    gigimushroom committed Aug 28, 2020
    Copy the full SHA
    0ef7848 View commit details

Commits on Sep 1, 2020

  1. p9 done

    gigimushroom committed Sep 1, 2020
    Copy the full SHA
    0da0864 View commit details
  2. p9

    gigimushroom committed Sep 1, 2020
    Copy the full SHA
    79daa66 View commit details

Commits on Sep 4, 2020

  1. More explore on parser

    gigimushroom committed Sep 4, 2020
    Copy the full SHA
    038664f View commit details

Commits on Sep 5, 2020

  1. project 10

    gigimushroom committed Sep 5, 2020
    Copy the full SHA
    a1eae0a View commit details

Commits on Sep 10, 2020

  1. project 10 done

    gigimushroom committed Sep 10, 2020
    Copy the full SHA
    730975e View commit details

Commits on Sep 22, 2020

  1. Project 11 is done

    gigimushroom committed Sep 22, 2020
    Copy the full SHA
    5ec756d View commit details

Commits on Sep 23, 2020

  1. readme for project 11

    gigimushroom committed Sep 23, 2020
    Copy the full SHA
    dadb396 View commit details

Commits on Oct 1, 2020

  1. Project 12 80%

    gigimushroom committed Oct 1, 2020
    Copy the full SHA
    1ec6a17 View commit details

Commits on Oct 2, 2020

  1. Copy the full SHA
    1854292 View commit details
Showing 343 changed files with 108,919 additions and 35 deletions.
134 changes: 134 additions & 0 deletions advance/python/Calculator Implementation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Support cases\n",
"\n",
"`((2+3)*5)`\n",
"\n",
"`(3+(10/2))`"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10\n",
"18\n",
"4\n"
]
}
],
"source": [
"symbols = ['+', '-', '*', '/']\n",
"\n",
"\n",
"def tokenizer(str):\n",
" tokens = []\n",
" rhs = ''\n",
" for i in range(len(str)):\n",
" if str[i] == '(' or str[i] == ')' or str[i] in symbols:\n",
" # We got left hand side, save it.\n",
" if rhs:\n",
" tokens.append(rhs)\n",
" rhs = ''\n",
" tokens.append(str[i])\n",
" \n",
" else:\n",
" rhs += str[i]\n",
" \n",
" return tokens\n",
"\n",
"def calc(tokens):\n",
" lhs = tokens[0]\n",
" sym = tokens[1]\n",
" rhs = tokens[2]\n",
" if sym == '+':\n",
" return int(lhs) + int(rhs)\n",
" elif sym == '-':\n",
" return int(lhs) - int(rhs)\n",
" elif sym == '*':\n",
" return int(lhs) * int(rhs)\n",
" elif sym == '/':\n",
" return int(lhs) / int(rhs)\n",
" \n",
" return None\n",
"\n",
"def eval(tokens):\n",
" if len(tokens) == 1:\n",
" return tokens[0]\n",
" \n",
" return parser(tokens)\n",
"\n",
"def parser(tokens):\n",
" # Trim ().\n",
" tokens = tokens[1:-1]\n",
" \n",
" paren_start = False\n",
" for i, t in enumerate(tokens):\n",
" if t == '(':\n",
" paren_start = True\n",
" \n",
" elif t == ')':\n",
" paren_start = False\n",
" # We got LHS in (xxx), next symbol is +/-/*//, add these as tokens\n",
" symbol = tokens[i+1]\n",
" lhs = eval(tokens[:i+1])\n",
" rhs = eval(tokens[i+2:])\n",
" #print(lhs, symbol, rhs)\n",
" tks = [lhs, symbol, rhs]\n",
" return calc(tks)\n",
" \n",
" elif t in symbols and not paren_start:\n",
" symbol = t\n",
" lhs = eval(tokens[:i])\n",
" rhs = eval(tokens[i+1:])\n",
" tks = [lhs, symbol, rhs]\n",
" return calc(tks)\n",
" \n",
" return None\n",
" \n",
"print(parser(tokenizer('((2+3)+5)')))\n",
"print(parser(tokenizer('(3*(2+4))')))\n",
"\n",
"print(parser(tokenizer('((88-86)*(4/2))')))\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading