Star Script

Simplify Web Application Development

Programming Language that Accepts Arbitrary Input Program

Most programming languages are very selective on the input programs. They have strict grammars and semantic rules. Violation of the rules will result in compilation errors. There is a reason for that – enforcing strict rules are believed to help reducing programming errors.

Enforcing strict rule does not come without its drawbacks. First, it creates a barrier for beginners by enforcing certain amount of learning before they can write their first program. Let’s take a popular programming language Java as an example. The first program a student usually learns is the HelloWorld program:

class HelloWorld {
    public static void main(String[] args) {
    System.out.println("Hello World!");

In order to understand and write the above program, a student has to understand quite a few concepts: class, identifier, method, method visibility, class method vs. instance method, string type, string literal, array, statement, method invocation, main method, ‘System’ object, ‘out’ field, println method. Some of the concepts are quite heavy such as the concept of class. Any mistake by the student will lead to compilation errors and therefore frustrations.

Being strict on the input program also puts a burden on the experienced programmers. They will have to constantly carry all those rules in their mind to avoid violating any of them. The penalty for violating the rule is harsh, your program won’t run.

Even after you carefully crafted your program, fixed all the compilation errors, there is still no guarantee that your program is bug free. In fact, no existing technology can detect all the bugs. Now, the question is, is rejecting the user input the only method or best method for reducing bugs. Is there a way that is more friendly to user input without sacrificing the ability to help user reduce bugs. Is it possible to design a programming language that is easy on the beginners yet powerful enough for the experienced? The history of HTML shed some light on this question.

HTML is believed to be one of the easiest to learn computer language in the world. HTML has a very user friendly language specification. It defines many elements as optional, including the <html> element and the <body> element, and asks the browser to automatically compensate for the missing elements. Most browsers go even beyond the specification and handle invalid HTML gracefully. The spirit is, treating HTML authors nicely like treating customers. When they get a little lazy or make a small mistake, don’t penalize them by refusing to render the document, instead, trying the best to recover from errors and render the document as good as it possibly can. This behavior relieved the HTML authors from having to always write perfect HTML. Even if they missed something, their document still gets rendered. The end result is a user agent that can process nearly arbitrary input text. It makes creating web pages easy for the beginners. Anybody can start creating one with minimal learning. In HTML, the Hello World program is simply:

Hello World!

It is the simplest possible form of all the hello world programs!

Unfortunately, HTML is not a programming language, it is not Turing complete. To make it more powerful, there is a desire to supplement HTML with programming language constructs. Several attempts have been made, ranging from server side ASP/JSP/PHP, to the client side JavaScript. All those approaches use some kind of switch that turns the compiler from text processing mode into programming language mode and vice versa. When the compiler is in the text processing mode, it is very dumb. It simply copies the source to the output. When the compiler is in the programing language mode, it is very strict, or as strict as any other programming language would be. Those extensions enhanced the HTML ecosystem. However, they do not bring the same level of ease of use as that of HTML to the programming language world. In turn, only real programmers dare to cross the line to build dynamic web applications.

Star Script is a programming language that tries to bring HTML level of ease of use into the programming language world. The idea is being tolerant to the language user can reduce the barrier of entry and making it easier for beginners.

Star Script compiler will process program with mixed text and programming language fragments. Instead of asking the language users to manually insert markers between text sections and programming language sections, Star Script will automatically detect valid programming fragments from the input text. The un-recognized fragments will be treated as text. Therefore, the hello world program in Star Script is exact the same as that of HTML:

Hello World!

Programming language fragment can be mixed directly with text. For example, the Star Script program that prints out “Hello World!” three times, is

For I = 1 To 3 Hello World! Next

You may wonder that what if you want to print out the source instead of executing it. In Star Script, you can always put a piece of text between double quotes to make sure that it is treated as text, for example:

“For I = 1 To 3 Hello World! Next”

will output the source as oppose to print out ‘Hello World!’ three times.

Being tolerant to the input programs, does not mean being loose in checking the code. Star Script compiler not only detects programming language fragments from the source program, it also checks the grammar and semantic rules. Only when a fragment passes all the checks, it will be generated into executable code. So the generated executable code is as reliable as the one generated by many other programming languages.

What makes Star Script different is when grammar or semantic rules are violated, instead of throwing a compilation error at the language user, the Star Script compiler will try to recover from the violation by converting the invalid fragment into a valid one. Several error recovery strategies are applied at various stage of the compilation process.

  • Defaulting: for example, when a variable is not assigned an initial value, default one will be used.
  • Automatically insert missing statement: for example, when you forget to add return statement to a function declaration, the Star Script compiler will automatically insert a return statement with the default value depending on the function return type
  • Type inference: for example, when a user forgets to assign a type to a newly declared variable, the Star Script compiler will try to infer types from its usage.
  • Type casting: for example, when a user uses incompatible types in an expression, some automatic type casting may be applied.
  • Automatic fix structural issue: for example, when an element is not close, the Star Script compiler will automatically close it.
  • Convert into text output: most other error cases are being converted into text output, such as un-declared name reference, duplicate name declaration etc.

After automatically fixing the grammar and semantic rule violations and before the code generation is performed, the Star Script compiler generates a completely valid abstract syntax tree internally which conforms to all the Star Script language grammar and semantic rules. From that point onward, Star Script compiler is dealing with a valid program as if it was originally written by its user.

To help user identify programming issues, Star Script compiler can output the abstract syntax tree or modified source, so the language user can inspect or compare whether the Star Script compiler understands their program correctly. Potentially, these infomation can be displayed in the IDE as instant feedback to help user while they are writing the code.

As an example, if the user forget to add the ‘Next’ keywords when trying to print out ‘Hello World!’ three times like the below program:

For I = 1 to 3 Hello World!

Star Script will simply print out the source.

Star Script is very tolerant to the input program. One of the design goals for Star Script is being able to process arbitrary input text. The Star Script compiler is very close to this goal. If you are interested, please try out the Star Script at MyEzApp online service, or download the standalone version from the Star Script official langauge site.

Star Script has many other features. I will discuss them in details in later posts. Please feel free to share your thoughts. Thanks!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: