Writing a Java 1.5 Parser with Coco/R - Tutorial

<- Back to Introduction

Next Chapter Java 1.5 Parser - Scanner and Lexer - part 1

Java is one of the most successful computer languages and have been so for more than two decades. It is not surprising, loved by so many developers. However, it is surprising that there are so few, relatively speaking, tools for analyzing java code. One reason may be the quite hard effort it takes to write a java parser. Even with the help of parser generator tools.

In this tutorial, JFlex will be used as scanner.

Java Syntax Specification

Sun Microstation and Oracle have both been very generous with publishing the Java language specifications, both in book form and online. Today (2013) only two specifications are published online The Java™ Language Specification - Java SE 7 Edition and The Java Language Specification, Third Edition (Java 1.5/1.6). Both are found at Java Language and Virtual Machine Specifications @ Oracle.

The Java Language Specification, Third Edition

A closer look at the specification yields that the specification is parted in two parts: The Language Specification (chapter 1 to 17) and Java Syntax Specification (chapter 18). Both specifications are similar in many ways but the latter Java Syntax Specification is much lesser in size and not so detailed and more relaxed. Why should any one want to use that kind of specification? In fact, that is just the kind of specification that will be used in this tutorial.

The language specification (chapter 1 to 17) must be used to produce a parser to a java compiler, or editor that must understand java code. But for most tools that will be used to analyze java code the assumption could be made that the java code is correct. So, a much more relaxed specification could be used to build the java parser. It will also be faster.

Java 1.5 Parser - Scanner and Lexer - part 1

<- Back to Introduction

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License