Posts

Showing posts from November, 2011

OpenJDK Java8 Lambda Syntax

Image
This document provides some working examples of the future OpenJDK 8 lambda syntax.   There was a lot of discussion whether the language changes would get included in the Java7 or Java8 so it looks like we will see the changes in Java8 slated for release in 2013. The lambda conversion uses a target SAM type or single abstract method. You can see the conversion in this example:     interface F {         void f();     }         final F func = () -> System.out.println("Test");         System.out.println("Function Object : " + func);         func.f(); ... The variable type on the left is an interface of type 'F' with a single method 'f'. It seems that the Java lambda implementation provides a slightly more expressive syntax for code blocks that you would normally see in an anonymous inner class.  These sections of  code are synonymous.         for (int i = 0; i < 10; i++) {             final int ii = i;             final int re

Implementing a Parser and Simple Compiler for the Java Virtual Machine

Image
1. Overview   This document covers the implementation of a simple recursive-descent parser for an infix adder language with a lexer, parser, and compiler.  The language is implemented with Java and compiles to Java Virtual Machine (JVM) bytecode.  The first implementation of the compiler is different from other implementations because it is fully implemented in one class without third party parser generator libraries.  The implementation of the language only uses the Java standard libraries.  The code for the parser does not use a parser generator so it only contains pure Java standard libraries and no references to third-party libraries. I wanted to discuss this particular example it helps for you to understand the nature of programming languages and their implementation.  Don't be scared about the parsing input token routines in them.  They help as a tool to the developer.  This a basic implementation but at least I provided a JVM compiler.  Actually code generator from the