previous next contents
Users who have already experience with Java software may skip the reminder of this section.
If you are unsure whether or not a Java Runtime Environment has been already installed at your computer, try to start
or to find an application named 'java'.
The command 'java -version' lets you know its actual version. If there is none, you can obtain your copy for free
from http://java.com. There you will also find installation hints and sources
for further support. Even if
your type of platform is not directly supported by Sun, there is hope for finding a Java runtime in the web.
(MacOS X is already shipped with its own implementation.)
Java has its own places where to search for resources, defined by the classpath. There are two ways
to define the classpath. First, setting the CLASSPATH variable which is similar to any other path variable.
Second, define the classpath in the command line, e.g.,
>java -classpath C:\j2sdk1.4.1\jre\lib\ext\tools.jar;C:\work\classes;. example.main
which has the advantage that it declines the risk of unintended interaction with other Java applications.
At least, the classpath should contain all the jar archives from the directory ...\jre\lib\
and the application's archive and/or directory.
C:\work\Dp4B19.jar;C:\jdk\jre\lib\rt.jar;C:\jdk\jre\lib\i18n.jar
The different modes of use:
tools.jar
archive from the JDK to the classpath. (see above)*** java.lang.NoClassDefFoundError: sun/tools/javac/Main
indicates that the default Java compiler could not be found.
Hint: To circumvent these restrictions, one can use the root production Ml4jT
to
generate the Java code from a Ml4
rule only. Save the generated code to a file and compile it elsewhere.
Swing based graphical user interface: ide
Java version: from 1.4.x
package name: Dp4.ide
main class: Dp4.ide.Main
(extends java.applet.Applet
)
Depot4.cfg
file.
Given the package name as in Java's package statement, e.g. "my.nice.pack
" a
rule "ThisRule
" will be searched for as
ThisRule
This.ThisRule
my.nice.pack.ThisRule
Dp4.ThisRule
Thisrule
, THISrule
, etc.
point 2 is skipped.)
To start the IDE enter the command line (check the classpath)
java -classpath .;C:\work\Dp4B19.jar;...\tools.jar Dp4.ide.Main
Remark: The current directory '.' is the default place to start for (search and save) of generated translator
rules.
The "Help" menu contains an item "Getting started" with further explanations.
Hint: A message There is no configuration file: Depot4.cfg
is only an information
indicating that the defaults are in use and not substituted.
example.np
and expect the result to be written into file example.c
one can issue the command
java -classpath .;C:\work\Dp4B19.jar....jre\lib\i18n.jar Dp4Run program example.np example.c
Any messages will be sent to the standard output stream. "nanoPascal2C" is the name of the translator's root
production rule.main
method of the Dp4Run class (with the command line example):
Dp4Run.main(new String[]{"nanoPascal2C", "example.np", "example.c"});
Another solution is to copy the appropriate code (the name "MyTranslator" has no specific meaning and
will be used for logging purposes only):
// Create a Translator
Dp4.Translator translator= new Dp4.Translator("MyTranslator"); // may be static
// call translator:
Dp4.trgts tt= Dp4.Tools.translate(translator, Dp4.Files.IFile("example.np"), "nanoPascal2C");
if (Dp4.Tools.isOk(translator)) {
// if successful write target on file
Dp4.StreamTrg.Tar2Strm(tt.trg1, new Dp4.FileTrg("example.c"));
}
RemarksTranslator
object needed for all translations if they do not happen
in concurrent threads.stringVariable
instead of a text file substitute
Dp4.Files.IFile("example.np");
by
Dp4.StringStream.IString(stringVariable);
stringVariable
instead of a text file substitute
"Dp4.StreamTrg.Tar2Strm(tt.trg1, new Dp4.FileTrg("example.c"));"
by
Dp4.StrBuf strbuf= new Dp4.StrBuf(); // make StringBuffer stream
Dp4.StreamTrg.Tar2Strm(tt.trg1, strbuf); // write target on stream
stringVariable= strbuf.toString(); // copy to string
(*!package=xx.yy.zz ...*)
anywhere in
the Ml4
code you can define a package name for the rule/module.(*!nopackage ...*)
disables the default package placement, i.e., the generated class
is placed in the unnamed package (see Java Language Specification, 7.4.2).
Imported (foreign) modules are the main reason for Java compiling errors. As the metalanguage
translator has no information it cannot do any checks and relies on their proper use. To make
the back tracing of errors which are caused by improper method invocations simple, the generated
Java code contains at each such call a comment with the associated Ml4
location.
!BOOLEAN(Dp4Base.LogLevel.get(9))
in file C:\Ml4\Ml4jTrans.Ml4
is translated into
y_Prs.A=(Dp4.Base.LogLevel.get(9)/*$"C:\Ml4\Ml4jTrans.Ml4" pos 434 */);
An accidental type mismatch lets the Java compiler issue a log message like this, from which it is easy to locate the
error at position 10 of the current input text area:
javac -d . -classpath .;C:\j...\classes tmp\src\a.java
tmp\src\a.java:29: appStr(Dp4.tNode,java.lang.String) in Dp4.Chars cannot be applied to (Dp4.tNode,int)
y_0tg.trg1= Dp4.Chars.appStr(y_0tg.trg1, N/*$"" pos 10 */);
Window>Add ...card
menu:
Ml4
rule
a= .
produces with the Ml4 translator:
Counts
------
max. tree heigth: 5
no. of nodes: 6
======================
. Ml4jT
. . Ml4jModule
. . . Ml4jRule
. . . . id
. . . . Ml4jSrcExp
. . . . . Ml4jSrcFact
ASTBuilder
extension provides this functionality.
Its code may also serve as a guide for more sophisticated solutions.ASTBuilder
constructs the AST exploiting the nonterminal invocation extensibility. It appends
an ASTDefaultNode
to the AST for every successful nonterminal invocation. Modify the code for
running Depot4 from within a Java application as follows:
Dp4.Translator translator= new Dp4.Translator("MyTranslator");
ASTBuilder astBuilder= new ASTBuilder();
// initialize the ASTBuilder:
astBuilder.clear();
NTprocMonT.set(translator, astBuilder);
// call translator:
Dp4.trgts tt= Dp4.Tools.translate(translator, Dp4.Files.IFile("example.np"), "nanoPascal2C");
if (Dp4.Tools.isOk(translator)) {
// get the root of the AST:
ASTNode rootNode= astBuilder.getASTRoot();
// process it ...
}
Dp4
package.
public static String Date()
depot4.date.format
".
public static trgts translate(Dp4.Translator t, Dp4.Source s, Dp4.NonTerm ROOT)
public static trgts translate(Dp4.Translator t, Dp4.Source s, String ROOT)
public static trgts translate(Dp4.Source s, Dp4.NonTerm ROOT)
public static trgts translate(Dp4.Source s, String ROOT)
public static boolean isOk(Dp4.Translator t)
public static boolean isOk()
public static void setCap(boolean state)
public static boolean isCap()
identJava
identPascal
identX
idForApplet
ident
which does not access the local
file system and thus, cannot read an exclusion list from file. As the name tells it is intended
for use in applets.
Ml4
code clear of system specific notations. Some of the settings (e.g.,
all of them with regard to the Java compiler) make only sense for the building of translators.
There are three slots for the configuration of a Depot4 system:
java -classpath .;C:....\tools.jar Dp4.ide.Main -DpropertyName1=value1 -DpropertyName2=value2
Depot4 property names:
Dp4.HostCompiler
, which
is used as an internal compiler.javac
which accepts the same switches
as Sun's Java compiler. Details for this may be system dependent.Ml4Date
element. Possible formats are defined in java.text.DateFormat
.
java -classpath .;C:....jar Dp4.ide.Main -Ddepot4.work.dir=C:\work -Ddepot4.trans.packages=a.b.c;xx.y
cap=no /* insensitive */
cap=yes /* sensitive - default */
local
'id'<-'Dp4.idr'
'ident'<-'Dp4.idr'
map
'Dp4OP'='Dp4.OP'
'Other'='any.xxx.yyy.what'
PACKAGE= 'xx.yy.zz'
package ='a.b.c'
CAP=YES /* this is default */
map
'Dp4Streams'= 'Dp4.Streams'
'Dp4DocFiles' = 'Dp4.DocFiles'
'Dp4StrBuf'= 'Dp4.StrBuf'
PACKAGE ='xx.yy.zz'
package= 'a.b.c'
The configuration file is searched for in the current user directory.
Dp4.config
.
This class is intended for costumization by modifying its method translatorCreated
.Hint: Any of the classes can be substituted by creating a new class file and placing it in the classpath.
modulename_typename
. Of course, module names can be mapped on any complete
(i.e. including the full package name) class names.
IMPORT External;
ExamplRule=
VAR v1, v2: External.T1;
v3: External.T2;
...
External.M1(v1); ... v2:= External.T1("t"); ...
v2.M3();
public class External {
public static void M1(External_T1 t) { ... }
public static External_T1(String s) { ... }
}
public class External_T1 {
public void M3() { ... }
}
public class External_T2 {... }
INTEGER
on int
BOOLEAN
on boolean
REAL
on float
SYM
on java.lang.String
TXT
on Dp4.tNode
TARGET
on Dp4.trgts
Ml4
type definitions and let the system generate the appropriate Java code. (Hint: One can use the
translator by selecting "Ml4jT" as root.)
ML4
assumes a module concept which distinguishes between modules and types or classes, i. e. a module
is seen as a collection of types, each type determined by the pair modulename.typename
. Java does not not know
such a difference. So, if there is a need to declare variables of an external type (class), this class must be split
into two parts: a class with the module name and another interface with name modulename_typename.
As an example the type Dp4List.List
is translated into Dp4.List_List
, while a call
Dp4List.New(x)
will result in
Dp4.List.New(x);
. There is no need to use the same name for both parts, cf. Dp4Streams.Stream
.
Reminder: Of course, the location of the external (imported) classes must be reachable from the current working directory. Otherwise one has to append it to the classpath.
Class Dp4LogStub
implements a generic wrapper for logging with these methods:
public static LogStub getLog(String name)
public boolean isLogEnabled(int severity)
public void log(int severity, String msg)
public void log(int severity, String msg, Throwable ex)
Severity is an integer number, assuming 0 a default level, lesser values indicating more detailed logging.
This implementation offers an interface to Apache's Commons Logging.
During initialization Depot4 looks for the class org.apache.commons.logging.LogFactory
. If it is found,
it is instantiated and
all logging actions are delegated to it. Severities are mapped as follows:
<-1: trace -1: debug 0: info 1: warn 2: error >2: fatal
This logging interface is intended for extensions primarily. Currently, several classes of Depot4's runtime system use it, thus supporting the tracing facilities of the parser.
previous next contents