This is a somewhat informal summary of the syntax for NewLang. The intended audience for this document are developers.
NewLang's syntax is intended to be simple, verbose and unambiguous. This is intended to aid people with physical and cognitive disabilities that have trouble with symbols and keeping track of large amounts of contextual information.
This section lists the conscious design decisions behind the syntax.
Often programming languages will use symbols to represent tokens. These are often borrowed mathematical and logical symbols.
These suffer from numerous accessibility issues:
To avoid these issues, NewLang uses text for all tokens. Some additional conventions apply:
Most developers use spaces and tabs to visually structure code. This convention helps in reading and understanding code.
Unfortunately screen readers skip over whitespace. This makes it difficult to understand code structure, and even more difficult to write.
NewLang treats whitespace as a separator between tokens. No whitespace is otherwise required.
Whitespace may still be used to structure code, but this is discouraged.
Programming languages often contain ways to specify context about when or why code will execute.
Some examples of these are:
These are often necessary to make a structured programming language and facilitate organization of code.
However, most programming languages will allow nesting these directives.
For example:
Excessive nesting can create a large amount of cognitive overhead, so NewLang strictly limits nesting to tolerable levels.
The following is a complete listing of all syntax in NewLang.
This is not specified using formal grammar or language. Any ambiguity is accidental.
Syntax in NewLang is formed using alphanumeric tokens separated by whitespace.
Whitespace can be the following characters:
For example, the following code snippet:
Hi There EveryOne How are you
Breaks down in to the following tokens:
NewLang supports storing code in files.
Files must be UTF-8 encoded and use Unix new lines.
Unix and Unix-like systems allow turning text files in to regular executables. This is done by placing a shebang at the start of a file.
A shebang consists of a line containing:
Here's an example of a file with a shebang:
#! /bin/bash --verbose echo Hi there!
NewLang will detect shebangs and skip them, instead leaving them for the operating system to handle.
The NewLang directive specifies the version of NewLang used to write the code.
The NewLang directive consists of two tokens:
Here's an example of specifying version 0:
NewLang 0
This directive is used by NewLang to preserve backwards compatibility with code written for older versions of itself.
Notes allow you to write text intended for other humans to read.
These are often referred to as comments in other programming languages.
Notes consist of:
'StartNote' is not allowed in the note's text. This helps catch cases of accidental nesting.
The text is otherwise ignored by NewLang.
Notes may be used anywhere where code can appear.
Here's an example of specifying a note among other code:
NewLang 0 StartNote Read the user's name EndNote Set Name To System Read EndSet System Print Name Done
The note here is ignored by NewLang but read by humans.
Values represent a piece of data used by the running program.
Values may be of these types:
See the sections for each of these value types on how to use them.
Text values contain human-readable text.
Creating a text value consists of these tokens:
'StartText' is not allowed in text values. This helps catch cases of accidental nesting.
Whitespace after 'StartText' and before 'EndText' are automatically removed.
The arbitrary text will be used as Text data.
Here's an example:
NewLang 0 System Print StartText Hello, world! EndText Done
This will print the text 'Hello, world!'
Booleans are values that can be one of two possibilities:
Booleans can be created by specifying True or False as a token. The value (True or False) will be used as Boolean data.
These don't literally mean true or false, those are just the names of each possibility.
Anything that has two options can be represented using a boolean. Instead of true or false you could think of these as:
Here's an example on using a boolean with an If directive:
NewLang 0 If True Then System Print StartText Hi EndText Else System Print StartText Bye EndText EndIf
This will print 'Hi' to the screen as the If directive interprets the boolean as whether to run the first command or second command.
Variables reference values using a name.
Specifying variables is done by writing the name as a token.
Variables are created using the Set directive.
Here's an example:
NewLang 0 Set Time To StartText Twelve O'Clock EndText EndSet System Print Time Done
This will create a variable named Time that references the text value 'Twelve O'Clock'.
When it's time to pass a value to System Print, the variable is used as a reference instead of the actual value.
As a result, this will print 'Twelve O'Clock' to the screen.
Actions instruct NewLang to create a new value.
An action consists of these tokens:
An action performs a verb on a subject with provided arguments.
The result of the action is a new value. This value is used by other language directives.
The number of arguments required is determined when running the verb.
If no verb is provided, the subject is recycled as the result.
Here's an example using a set directive:
NewLang 0 Set UserName To System ReadLine EndSet
In this case the action is 'System ReadLine'. This action refers to the subject 'System' and the verb 'ReadLine'.
The result is used by the Set directive to create a variable.
This variable would contain the value read from a command prompt.
Directives instruct NewLang to perform some action or logic.
The following directives are available:
These are placed in a file in sequence.
Here's an example of multiple directives in a single file:
NewLang 0 Set UserName To System ReadLine EndSet If UserName Equals StartText Jookia EndText Then System Print StartText Hi Jookia EndText Else System Print StartText Howdy Stranger EndText EndIf System Exit 0 Done
See the sections for each of these value directives on how to use them.
Command directives perform an action and discards the result.
The directive consists of these tokens:
Here's an example of using command directives:
NewLang 0 System Print StartText Hit enter to continue EndText Done System ReadLine Done
This will prompt the user to press enter, then read and discard a line.
In this case the result of Print and ReadLine don't matter, only the fact that the user had to hit enter to write a line does.
Set directives create a variable containing the result of an action.
The directive consists of these tokens:
The variable name must be unique.
Here's an example of using the set directive:
NewLang 0 Set Message To StartText Hi there! EndText System Print Message Done
This creates a variable named 'Message' and prints it to the screen.
If directives runs a test action then either a success or failure action depending on the test action's result.
The result of the success or failure action is discarded.
The directive consists of these tokens:
NewLang 0 If True Then System Print StartText Success EndText Else System Print StartText Failure EndText EndIf
This will print 'Success' to the screen.