cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

  <div class="container">

  <textarea id="language_input" type="text"/>
3 22 +</textarea>
  <div class="results" id="language_output">5</div>

  <div id="stack_output"></div>

  <h4>A Simple Stack Based Language</h4>
  <p>Simple Stack based language in postfix notation.</p>

  <p>Ehem,  I'll say that again in English</p>

  <h4>A Backwards Calculator</h4>
  <p> a really simple calculator with a twist.</p>

  <p>Postfix means instead of writing "2 + 3" you write "3 2 +". Make sure there is space between every number and every operator. Parentheses will not help you here.</p>


3 22 +        ->        25


              .container {
  float: left;
  margin: 0 60px 0 60px;

.details {

var selInput = d3.select('#language_input')
  .on('keyup', _.debounce(executeFromInput, 500))
var selOutput = d3.select('#language_output')

// Drive first one

function executeFromInput() {
  var input = selInput.node().value;
  var tokens = parse(input)
  var output = execute(tokens);

function execute(tokens) {
  var stack = [];
  _.each(tokens, function (t, i) {
    if (stack.length > 10000) return userError('Stack overflow. That means something went horribly wrong on my end. Sorry boo.');
    switch (t.type) {
    // For values, just throw'm on to the stack.
    case "number":
    // Operators
    case "operator":
     if (stack.length < 2) return userError('Stack underflow. That means you used an operator with not enough values on the stack.');

     // Take operatands off of stack.
     var a = stack.pop();
     var b = stack.pop();

     // Operator implementations
     switch(t.value) {
     case '+':
       log(a, b, t)
       a.value = a.value + b.value;
     case '-':
       a.value = a.value - b.value;
     case '*':
       a.value = a.value * b.value;
     case '/':
       a.value = a.value / b.value;

     // Finally push new value back on stack;
  return stack.map(function (t, i) { return t.value }).join(' ')

function parse(input) {
  var tokens = [];
  // Tokens are any-whitespace delimited
  // TODO: Can reduce this by using regex that matches any group of whitespace for split, instead of string
  _.each(input.split(' '), function (word, i) {
    // First match group is operators, second match group is values. Reserving a lot more than I'm implementing. See execute()
    var reTokens= /(\+|\-|\/|\*|\x|\^)|(\d+(.\d*)?(e\d*)?)/i;
    var matchTokens = word.match(reTokens);
    // Do nothing with words we don't understand
    if ( ! matchTokens ) return;
    var token = {
      type: 'BLANK_TOKEN_TYPE',
      value: 'BLANK_TOKEN_VALUE',
    var op = matchTokens[1];
    var number = matchTokens[2];
    if (op) {
      token.type = 'operator';
      token.value = op
    } else if (number) {
      token.type = 'number';
      token.value = parseFloat(number, 10)
  return tokens;
function userError(message) {
    throw new Error(message)

function log(mess,ag,es) { console.log.apply(console, arguments) }
Loading ..................