PseudoChartPseudoChart

Learn PSC 1.0

PSC is the pseudocode language PseudoChart reads. You write the steps of an algorithm in plain, structured English, and the app turns them into a flowchart. PSC only describes an algorithm, so nothing you write here is actually run.

Your first file

Every file needs exactly two things: the signature on line 1, and a named BEGIN … END block. That is already a valid program.

// PSC:1.0 Greeting

BEGIN Greeting
  INPUT "What is your name? " name
  OUTPUT "Hello, " name
END
  • Line 1 is the signature. The name after it titles the file.
  • The name after BEGIN titles the main page of the flowchart. The two can differ.
  • Indentation is two spaces. It is there to help you read; the parser ignores it.

Four things that catch everyone

  • Not this
    if x > 0
    This
    IF x > 0

    Keywords are UPPERCASE. A lowercase `if` is just an identifier, so the parser will not read it as a branch.

  • Not this
    x = 10
    This
    LET x = 10

    LET is the only way to assign. A bare `=` outside LET is an equality check.

  • Not this
    BEGIN
    This
    BEGIN Main

    BEGIN must be followed by a name. That name becomes the title of the main page of your flowchart (E015).

  • Not this
    BEGIN Main
      FUNCTION f(a)
      END FUNCTION
    END
    This
    FUNCTION f(a)
    END FUNCTION
    
    BEGIN Main
    END

    FUNCTION and PROCEDURE live at the top level, never inside a block (E012).

Every construct

File structure

File signature

Every .psc file must start with this exact line. It names the file and the flowchart title.

Shape
// PSC:1.0 <AlgorithmName>
Example
// PSC:1.0 BubbleSort
// Description: Sorts a list of n numbers

Get this wrong and you'll see E001.

BEGIN … END

Terminal (oval)

The main body of the algorithm. BEGIN must be followed by a name, which becomes the title of the main flowchart page.

Shape
BEGIN <Name>
  <statements>
END
Example
BEGIN BubbleSort
  OUTPUT "Starting"
END

Get this wrong and you'll see E015.

Comment

Single line only. A comment starts at // and runs to the end of the line. There are no block comments.

Shape
// <text>
Example
// Full-line comment
LET x = 10  // Inline comment

Control flow

IF / ELSE IF / ELSE

Decision (diamond)

Branch on a condition. ELSE IF and ELSE are optional; only one ELSE, and it must be last.

Shape
IF <condition>
  <statements>
ELSE IF <condition>
  <statements>
ELSE
  <statements>
END IF
Example
IF score >= 80
  OUTPUT "Pass"
ELSE
  OUTPUT "Fail"
END IF

Get this wrong and you'll see E004 or E014.

WHILE

Decision (diamond)

Checks the condition before each pass. If it is FALSE the first time, the body never runs.

Shape
WHILE <condition>
  <statements>
END WHILE
Example
WHILE swapped = TRUE
  LET swapped = FALSE
END WHILE

Get this wrong and you'll see E004.

FOR … FROM … TO

Decision (diamond) + process boxes

Numeric range loop. Inclusive on both ends, increments by 1.

Shape
FOR <variable> FROM <start> TO <end>
  <statements>
END FOR
Example
FOR i FROM 1 TO 5
  OUTPUT i
END FOR

Get this wrong and you'll see E007.

FOR EACH … IN

Decision (diamond)

Loops over a collection, assigning each item to the loop variable in turn.

Shape
FOR EACH <variable> IN <collection>
  <statements>
END FOR
Example
FOR EACH student IN classList
  OUTPUT student
END FOR

REPEAT / UNTIL

Decision (diamond)

Checks the condition after each pass, so the body always runs at least once. The loop stops when the condition is TRUE.

Shape
REPEAT
  <statements>
UNTIL <condition>
Example
REPEAT
  INPUT guess
UNTIL guess = secretNumber

Get this wrong and you'll see E006.

SWITCH / CASE / DEFAULT

Decision (diamond) per CASE

Each CASE fits on one line: the keyword, a value, a colon and a single statement. There is no fall-through, and CASE needs no END.

Shape
SWITCH <expression>
  CASE <value>: <single statement>
  DEFAULT: <single statement>
END SWITCH
Example
SWITCH grade
  CASE "A": OUTPUT "Excellent"
  CASE "B": OUTPUT "Good"
  DEFAULT:  OUTPUT "Below average"
END SWITCH

Input & output

INPUT

Input/Output (parallelogram)

Reads a value into a variable. An optional prompt string comes before the variable name.

Shape
INPUT <variable>
INPUT "<prompt>" <variable>
Example
INPUT age
INPUT "Enter your name: " username

OUTPUT

Input/Output (parallelogram)

Displays values. Several values separated by spaces are concatenated.

Shape
OUTPUT <value>
OUTPUT "<string>" <variable>
Example
OUTPUT "Hello, world"
OUTPUT "Result: " total

Data

LET

Process (rectangle)

The only way to assign a value. Outside LET, = means equality: LET x = 10 assigns, while IF x = 10 compares.

Shape
LET <variable> = <expression>
LET <collection>[<index>] = <expression>
Example
LET total = 0
LET total = total + price
LET list[i] = list[j]

Get this wrong and you'll see E005.

Collection indexing

Read or write one element with [ ], 0-indexed. There is no collection literal syntax.

Shape
<collection>[<index>]
LET <collection>[<index>] = <expression>
Example
LET first = list[0]
LET list[i] = list[j]

TRUE / FALSE

Boolean literals, uppercase only. Lowercase true and false are ordinary identifiers.

Shape
TRUE | FALSE
Example
LET swapped = TRUE
WHILE swapped = TRUE

Functions & procedures

PROCEDURE

Subprocess (double-barred rectangle)

A named block with no return value. It must sit at the top level, never inside BEGIN…END.

Shape
PROCEDURE <name>(<params>)
  <statements>
END PROCEDURE
Example
PROCEDURE printLine(message)
  OUTPUT ">> " message
END PROCEDURE

Get this wrong and you'll see E012.

FUNCTION / RETURN

Subprocess (double-barred rectangle)

A named block that returns a value, so it needs at least one RETURN. Like PROCEDURE, it belongs at the top level.

Shape
FUNCTION <name>(<params>)
  <statements>
  RETURN <expression>
END FUNCTION
Example
FUNCTION maximum(a, b)
  IF a > b
    RETURN a
  ELSE
    RETURN b
  END IF
END FUNCTION

Get this wrong and you'll see E008 or E012.

CALL

Subprocess (double-barred rectangle)

Runs a PROCEDURE on its own; capture a FUNCTION result with LET x = CALL name(...). Recursion is allowed.

Shape
CALL <name>(<arguments>)
LET <variable> = CALL <name>(<arguments>)
Example
CALL printLine("Starting")
LET biggest = CALL maximum(x, y)

Get this wrong and you'll see E009 or E010.

Operators

AND / OR / NOT

Logical operators. NOT is applied first, then AND, then OR. Add ( ) when in doubt.

Shape
<condition> AND <condition> | <condition> OR <condition> | NOT <condition>
Example
IF age >= 18 AND hasTicket = TRUE
  OUTPUT "Allowed"
END IF

Comparison operators

= is equality, not assignment. Use != for "not equal".

Shape
=  !=  <  >  <=  >=
Example
IF count != 0
  LET average = total / count
END IF

Putting it together

A bubble sort that uses a procedure, a while loop, a for range, a condition and a for each. Paste it into a new file to see the full flowchart it produces.

// PSC:1.0 BubbleSort
// Description: Sorts a list of n numbers using bubble sort

PROCEDURE swap(list, i, j)
  LET temp = list[i]
  LET list[i] = list[j]
  LET list[j] = temp
END PROCEDURE

BEGIN BubbleSort
  INPUT "How many numbers? " n
  LET swapped = TRUE

  WHILE swapped = TRUE
    LET swapped = FALSE
    FOR i FROM 1 TO n - 1
      IF list[i] > list[i + 1]
        CALL swap(list, i, i + 1)
        LET swapped = TRUE
      END IF
    END FOR
  END WHILE

  OUTPUT "Sorted list:"
  FOR EACH item IN list
    OUTPUT item
  END FOR
END

What the errors mean

The editor marks problems in the gutter as you type. Here is every code it can show and how to fix it.

CodeTriggerFix
E001Missing // PSC:1.0 headerMake line 1 exactly `// PSC:1.0 <AlgorithmName>`.
E002Unknown keywordCheck the spelling, and make sure it is UPPERCASE.
E003Unmatched ENDAn END IF / END WHILE with no opener above it. Remove it, or add the opener.
E004Unclosed blockAn IF / WHILE / FOR was opened but never closed. Add its END line.
E005Invalid LET assignmentUse `LET <variable> = <expression>`. LET is the only way to assign.
E006Missing UNTIL after REPEATEvery REPEAT needs a matching `UNTIL <condition>`.
E007Invalid FOR rangeUse `FOR <var> FROM <start> TO <end>` or `FOR EACH <var> IN <collection>`.
E008RETURN outside FUNCTIONRETURN only belongs in a FUNCTION. A PROCEDURE returns nothing.
E009CALL target undefinedDefine the FUNCTION or PROCEDURE, or fix the name. Names are case-sensitive.
E010Circular subprocess linkTwo files link to each other. Break the loop.
E011File too largeMax 500 lines or 50 KB. Split the algorithm across linked files.
E012FUNCTION or PROCEDURE nested inside a blockMove the definition to the top level, before BEGIN or after END.
E013Empty block bodyA block needs at least one statement between its opener and END.
E014ELSE without IFELSE and ELSE IF only follow an IF that is still open.
E015Missing or unnamed main blockAdd `BEGIN <Name>` … `END`. A bare BEGIN with no name is not enough.
E016Unterminated string literalClose the quote on the same line. Strings cannot span lines.
E017Illegal characterOnly letters, digits, _, ", operators and brackets are allowed.
E018Identifier exceeds 64 charactersShorten the name.
E019Malformed numberWrite 0.5 and 5.0, not .5 or 5. A number like 3.14.15 is never valid.
E020Expression nesting deeper than 50Split the expression across several LET statements.