The Language Javalette

BNF-converter

April 19, 2011

This document was automatically generated by the BNF-Converter. It was generated together with the lexer, the parser, and the abstract syntax module, which guarantees that the document matches with the implementation of the language (provided no hand-hacking has taken place).

The lexical structure of Javalette

Identifiers

Identifiers ⟨Ident ⟩ are unquoted strings beginning with a letter, followed by any combination of letters, digits, and the characters ', reserved words excluded.

Literals

Integer literals ⟨Int ⟩ are nonempty sequences of digits. Double-precision float literals ⟨Double ⟩ have the structure indicated by the regular expression ⟨digit ⟩ + ‘.’⟨digit ⟩ + (‘e’‘-’?⟨digit ⟩+)? i.e. two sequences of digits separated by a decimal point, optionally followed by an unsigned or negative exponent. String literals ⟨String ⟩ have the form "x", where x is any sequence of any characters except " unless preceded by \.

Reserved words and symbols

The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions. The reserved words used in Javalette are the following:

boolean  double  else
false    if      int
return   true    void

while

The symbols used in Javalette are the following:

(    )    ,

{  }  ;
= ++ −−

− !    &&

||  < >

+ *    /

%  <= >=
== !=

Comments

Single-line comments begin with #, //. Multiple-line comments are enclosed with /* and */.

The syntactic structure of Javalette

Non-terminals are enclosed between ⟨ and ⟩. The symbols ::= (production), | (union) and ϵ (empty rule) belong to the BNF notation. All other symbols are terminals.

⟨Program ⟩ ::= ⟨ListTopDef ⟩
⟨TopDef ⟩ ::= ⟨Type ⟩ ⟨Ident ⟩ ( ⟨ListArg ⟩ ) ⟨Block ⟩
⟨ListTopDef ⟩ ::= ⟨TopDef ⟩
|  ⟨TopDef ⟩ ⟨ListTopDef ⟩
⟨Arg ⟩ ::= ⟨Type ⟩ ⟨Ident ⟩
⟨ListArg ⟩ ::= ϵ
|  ⟨Arg ⟩
|  ⟨Arg ⟩ , ⟨ListArg ⟩
⟨Block ⟩ ::= { ⟨ListStmt ⟩ }

⟨ListStmt ⟩ ::= ϵ
|  ⟨Stmt ⟩ ⟨ListStmt ⟩
⟨Stmt ⟩ ::= ;
|  ⟨Block ⟩
|  ⟨Type ⟩ ⟨ListItem ⟩ ;
|  ⟨Ident ⟩ = ⟨Expr ⟩ ;
|  ⟨Ident ⟩ ++ ;
|  ⟨Ident ⟩ −− ;

|  return ⟨Expr ⟩ ;
|  return ;

|  if ( ⟨Expr ⟩ ) ⟨Stmt ⟩
|  if ( ⟨Expr ⟩ ) ⟨Stmt ⟩ else ⟨Stmt ⟩
|  while ( ⟨Expr ⟩ ) ⟨Stmt ⟩
|  ⟨Expr ⟩ ;
⟨Item ⟩ ::= ⟨Ident ⟩
|  ⟨Ident ⟩ = ⟨Expr ⟩
⟨ListItem ⟩ ::= ⟨Item ⟩
|  ⟨Item ⟩ , ⟨ListItem ⟩
⟨Type ⟩ ::= int

|  double
|  boolean
|  void

⟨ListType ⟩ ::= ϵ
|  ⟨Type ⟩
|  ⟨Type ⟩ , ⟨ListType ⟩
⟨Expr6 ⟩ ::= ⟨Ident ⟩
|  ⟨Integer ⟩
|  ⟨Double ⟩

 |  true
 |  false

|  ⟨Ident ⟩ ( ⟨ListExpr ⟩ )
|  ⟨String ⟩
|  ( ⟨Expr ⟩ )
⟨Expr5 ⟩ ::= − ⟨Expr6 ⟩
|  ! ⟨Expr6 ⟩
|  ⟨Expr6 ⟩
⟨Expr4 ⟩ ::= ⟨Expr4 ⟩ ⟨MulOp ⟩ ⟨Expr5 ⟩
|  ⟨Expr5 ⟩

⟨Expr3 ⟩ ::= ⟨Expr3 ⟩ ⟨AddOp ⟩ ⟨Expr4 ⟩
|  ⟨Expr4 ⟩
⟨Expr2 ⟩ ::= ⟨Expr2 ⟩ ⟨RelOp ⟩ ⟨Expr3 ⟩
|  ⟨Expr3 ⟩
⟨Expr1 ⟩ ::= ⟨Expr2 ⟩ && ⟨Expr1 ⟩
|  ⟨Expr2 ⟩
⟨Expr ⟩ ::= ⟨Expr1 ⟩ || ⟨Expr ⟩
|  ⟨Expr1 ⟩
⟨ListExpr ⟩ ::= ϵ
|  ⟨Expr ⟩
|  ⟨Expr ⟩ , ⟨ListExpr ⟩

\begin{aligned}⟨AddOp ⟩ & ::= & + \\ & | & − \end{aligned}

⟨MulOp ⟩ ::= *

          |  /
          |  %

⟨RelOp ⟩ ::= <
|  <=
|  >
|  >=
|  ==
|  !=