Skip to content

Instantly share code, notes, and snippets.

def rpn(str: String): Int = rpnPrime(str.split(' ').toList, Nil)
def rpnPrime(str: List[String], stack: List[Int]): Int = (str, stack) match {
case ("+"::t, y::x::zs) => rpnPrime(t, (x + y) :: zs)
case ("-"::t, y::x::zs) => rpnPrime(t, (x - y) :: zs)
case ("*"::t, y::x::zs) => rpnPrime(t, (x * y) :: zs)
case ("/"::t, y::x::zs) => rpnPrime(t, (x / y) :: zs)
case ("%"::t, y::x::zs) => rpnPrime(t, (x % y) :: zs)
case ( n::t, zs) => rpnPrime(t, (n.toInt) :: zs)
case _ => stack.head
@7shi
7shi / gist:4121619
Created November 20, 2012 22:15 — forked from bencz/gist:4115521
Basic compiler, generate PE EXE
/*
INPUT SAMPLE:
VAR NUMBER = 25
VAR STRING = "ALEX"
VAR ERRO = "THAT's NOT CAUSE AN ERROR :)"
PRINT ERRO
PRINT "ALEXANDRE"
PRINT NUMBER
@7shi
7shi / main.cpp
Last active December 14, 2015 04:09 — forked from bencz/main.cpp
#include <cstdio>
#include <vector>
#include <windows.h>
using namespace std;
class Buffer: public vector<unsigned char>
{
public:
void push_dword(DWORD dw)