in this article we build a simple compiler that augments java with tasks (independent blocks of code that execute in parallel), thus creating a new language called aj that well supports the programming of systems with concurrent activities. this is not to imply that java does not support multithreading, but to create a syntax that enables the clear expression of concurrency requirements. (aj programs do, in fact, compile into java programs that use java.lang.thread objects to support tasks.) you will see how to use a completely visual, user-friendly parser generator, visuallanglab, to quite easily build a compiler for aj.
visuallanglab is a freely downloadable (gpl) java.net project. to install it, just unzip the distribution file (visuallanglab.zip) into a directory. the visual parser generator (see figure 1) is started by clicking on visuallanglab.jar. the only other thing to keep in mind is that visuallanglab.jar must be on the classpath when compiling or executing the generated parser. 【程序编程相关:了解 JAVA classloader】
start here: a readymade grammar for java 【推荐阅读:Java学习推荐书籍】the heart of any compiler project is the grammar--a typically cryptic piece of text that serves as a specification for the language. since we wish to augment the capabilities of an existing language (java), it is simpler to start with an existing grammar for the base language. the starting point for this exercise will therefore be a java 1.4 grammar included in the visuallanglab distribution (the file java14c.lkv). well-written grammars, like well-written programs, are divided into smaller units called rules. a few sample rules from the java 1.4 grammar (as displayed by the visuallanglab gui) are shown in figure 2 (ifstatement), figure 3 (switchstatement) and figure 4 (unaryexpression). 【扩展信息:hibernate的hello word】
figure 1. the visuallanglab gui
... 下一页