BSc 2nd year mini-project
one partial circle and three smaller circles in various shades of blue one blue circle

Language details

Java-- isn't meant to be a new language or anything clever, its just a subset of the Java language with a few changes to make it easier. The syntax is the same as Java (with the exception of the string concatenation operator) and I've tried to keep the semantics as close as possible.

The only supported primitives are integers (int) and booleans (boolean). The integer operators are: +, -, * and / (addition, subtraction, multiplication and integer division, respectively), integers can also be negated using the - operator. Booleans can be operated on using && and || (logical and, logical or), note that these do not implement short circuit semantics (I should have really used & and |). The ! operator performs boolean negation.

Object and String classes are built in and may be extended, they support a very limited subset of the Java methods (Object: Object(), String toString(). String: String(), String(String), int length() String charAt(int) String toString()). The string concatenation operator, ++, combines Strings with any other objects or primitives as in Java.

Objects, ints and booleans can be compared (but not with each other) using the == and != operators.

For and if statements are similar to Java, except for the fact that there is no support for the else part of an if statement.

I've added the print() and exit() statements since there is no support for the runtime libraries. Print() takes a single parameter (of any type) and prints it (using System.out.print()). exit() takes no parameters and is equivilant to System.exit(0)

Assignment and declaration are as in Java except that you must supply a value in a declaration (eg 'int x;' is illegal), this goes for fields too.

Class declarations are as in Java, except that all access modifiers (public, protected or private) must be supplied (there is no package scope), all constructors must be supplied (no default constructors will be created) and all super calls must be explicit. eg:

class SomeClass extends AnotherClass {
    public SomeClass(String s)
    {
        super(s);
    }


    private void someMethod()
    {
    }

}

All classes must be supplied in one file and there is no implementation of packages, imports etc.

The entry point to the program is the main method of the class called Main. This class and method must be supplied and the Main class must have a public constructor that takes no parameters. On program startup this class is instantiated and the resulting object's main method is run.

Some Java features nor supported: Exceptions, static methods/fields, final bits, while/do loops, nested classes, packages, imports, threads, <, > and other comparison operators, arrays, many primitives, switch statements, abstract classes, interfaces, casting, the instanceof operator.

Grammar

 program ::= (classDef)+
 classDef ::= 'class' name ('extends' name)? '{' (classPart)* '}'
 classPart ::= fieldDecl | methodDecl
 fieldDecl ::= modifier type name = expression ';'
 methodDecl ::= modifier type name '(' argList ')' compoundStatement
             | modifier name '(' argList ')' compoundStatement //constructor
 modifier ::= 'public' | 'protected' | 'private'
 type ::= 'int' | 'String' | 'boolean' | 'Object' | name
 argList ::= type name (',' type name)*
 paramList ::= expression (',' expression)*
 statement ::= stExpression ';'
         | compoundStatement
         | 'if' '(' expression ')' statement
         | 'for' '('(expression | decl)? ';' expression ';' (expression)? ')' statement
         | 'return' expression ';'
         | 'exit()' ';'
         | decl ';'
         | 'super' '(' paramList ')' ';' 
 compoundStatement ::= '{' (statement)* '}'
 expression ::= stExpression
         | expression '.' name //field access
         | '(' expression ')'
         | expression '+' expression
         | expression '++' expression
         | expression '-' expression
         | expression '*' expression
         | expression '/' expression 
         | expression '||' expression
         | expression '&&' expression 
         | expression '==' expression
         | expression '!=' expression 
         | '-' expression
         | '!' expression 
         | name //local variable or field
         | 'this' //no extra syntax, since it is private local variable
         | '"' string '"'
         | number
         | 'true' | 'false' | 'null'
 stExpression ::= assignment
         | expression '.' name '(' paramList ')' //method invocation
         | name '(' paramList ')' //local method
         | 'new' name '(' paramList ')' //constructor
 decl ::= type name '=' expression
         assignment ::= (expression '.')? name '=' expression 

      
 String escape sequences:
     '\n', other escape sequences would be easy to add but are not supported by Jasmin


 Keywords:
if, for, this, class, public, private, protected, extends, true, false, super, exit(),
null, void, return, new, print
 Built in classes:
     String {String(), String(Int), String toString(), String charAt(int), int length()}
     Object {Object(), String toString()}
 Built in Types:
     int, boolean


 Operators:
     + - * / ++ == != || && ! .
one blue circle