Tom's JavaScript Machine

[ Machine | Instructions | Examples | JavaScript Basics | Challenge | Hints | About ]

The Operating Instructions

We assume you know (a bit) about JavaScript. Some JavaScript examples and a summary of JavaScript basics are separately available.

This page explains how to operate Tom's JavaScript Machine, including some extensions that are not standard in JavaScript.

Program Facilities
  • Edit your JavaScript program in the text area in the middle of Tom's JavaScript Machine, under Program.
    Warning: Your program is lost when reloading the machine page. Save it in a local text file via copy/paste, or via the Clone button (see below).
  • Run the program by clicking the Run button. This first clears the output area.
    [Advanced] Button 'Run & Append Output' will run the program without clearing the output area.
Output Facilities
  • The program can write output, which then appears in the text area on the right, using the predefined functions
    • write(): writes each of its multiple arguments to output
    • writeln(): like write(), and appends a newline
    • writequ(): writes a single quote
    Such output is also appended to the predefined variable output.

    (The functions write() and writeln() are comparable to the standard JavaScript functions document.write() and document.writeln(), that 'inject' the argument strings into the HTML document. Such 'injection' is not useful in Tom's JavaScript Machine.)

  • [Advanced] To clear the output text area, click its Clear button.
  • [Advanced] To copy the output to the program area, click button 'Copy to Program' above the output area. This is useful when a program produces as output a program that you then want to run. See the Examples for such programs.
Input Facilities
  • The program can process input from the text area on the left.
    When you click Run, the text on the left is made available in the predefined variable input.
    The input is also separated into an array of strings according to the separator defined in the input field above the input text area (the default separator is a space).
    The separated values can be accessed one by one using the predefined functions
    • readStr()
    • readNum()
    Whether further separated input values are available is reported by the predefined function moreInputs().
    Warning: Input that is entered after the program has been started, will not be processed in this way.
    Notes (for advanced use):
    • The separator is available in the predefined variable separator. This might be useful in output.
    • The arrray of separated input strings is available in the predefined variable inputs.
    • The index of the next input value is available in the predefined variable nextInputIndex. You typically do not need this variable and should not mess with it.
  • [Advanced] To clear the input text area, click its Clear button.
  • [Advanced] To copy the program to the input area, click button 'Copy to Input', above the program area.
  • [Advanced] To copy the output to the input area, click button 'Copy to Input', above the output area.
Miscellaneous Predefined Functions and Constants
  • Some predefined functions are available to recognize characters (not needed for the Challenge):
    • isQuote(c): determines whether c is a single quote (')
    • isNewline(c): determines whether c is a newline
  • Some special symbols are available through predefined constants (use these sparingly; not needed for the Challenge):
    • QU for a single quote (')
    • NL for a newline: on output, moves the writing head to next line (like writeln()); can also be used for comparison to characters on input

Valid HTML 4.01 Transitional

©2009-2010, Tom Verhoeff (TU/e)
Feedback about this page is welcome