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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

  <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 ='#language_input')
  .on('keyup', _.debounce(executeFromInput, 500))
var selOutput ='#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 (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) }
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.