1
0
mirror of https://github.com/twiglet/cs2j.git synced 2025-01-18 13:15:17 +01:00

Import CSharpTranslator from Rustici Software subversion repository. This is the trunk branch.

This commit is contained in:
Kevin Glynn 2010-05-29 09:34:44 -05:00
parent 3bc9847b15
commit 416040160e
41 changed files with 14055 additions and 0 deletions

11
CSharpTranslator/.project Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CSharpTranslator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Translator", "Translator\Translator.csproj", "{D33074E4-1525-4F22-A1DB-A7F30989D8FE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8ECA4801-3F48-4FD1-91B4-4DFB567D913B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D33074E4-1525-4F22-A1DB-A7F30989D8FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D33074E4-1525-4F22-A1DB-A7F30989D8FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D33074E4-1525-4F22-A1DB-A7F30989D8FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D33074E4-1525-4F22-A1DB-A7F30989D8FE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,51 @@
build.dir=${basedir}/build
svntx.build.dir=${build.dir}/svntx
cs2jtx.build.dir=${build.dir}/cs2jtx
cs2jtx.bin.dir=${cs2jtx.build.dir}/Translator/bin/Debug
svntxexe.svnwc.dir=${basedir}/
## WARNING: If these boolean properties are shown through the launch dialog then
## we must deal with value == false
is.rebuild.cs2j=true
is.cs2j.svnwc=true
is.commit.javacode=false
svn.commit.msg.java=Auto-committed following cs2j translation
svn.commit.removed.msg.java=Auto-committed removed files following cs2j translation
svn.repo=https://svn.rusticisoftware.com/svn/projects
csharp.project=Products/ScormEngineNet
csharp.project.branch=trunk
csharp.tx.sub.dir=src/app/ScormEngine.Core
csharp.project.full=${csharp.project}/${csharp.project.branch}
csharpcode.branch.url=${svn.repo}/${csharp.project.full}/${csharp.tx.sub.dir}
csharptx.dir=ScormEngine.Core
csharpcode.dir=${svntx.build.dir}/${csharptx.dir}
csharpcode.tx.dir=${svntx.build.dir}/${csharptx.dir}/Logic
java.project=Products/ScormEngineJava
java.project.branch=${csharp.project.branch}
java.tx.sub.dir=RusticiSoftware.ScormContentPlayer.Logic/src
java.project.full=${java.project}/${java.project.branch}
javacode.branch.url=${svn.repo}/${java.project.full}/${java.tx.sub.dir}
javatx.dir=${java.tx.sub.dir}
javacode.svnwc.dir=${svntx.build.dir}/${javatx.dir}
javacode.old.svnwc.dir=${svntx.build.dir}/OldJava/${javatx.dir}
cs2j.project=Products/CS2JLibrary
#cs2j.project.branch=${csharp.project.branch}
cs2j.project.branch=trunk
cs2j.branch.url=${svn.repo}/${cs2j.project}/${cs2j.project.branch}/
cs2j.dir=${svntx.build.dir}/CS2JLibrary
cheats.dir=${svntx.build.dir}/Cheats
svn.exe=svn
builder.ant.lib=${basedir}/lib
builder.ant.dll=${basedir}/dll

View File

@ -0,0 +1,209 @@
<?xml-stylesheet type="text/xsl" href="file://C:\ant\etc\antex\antprettybuild\antprettybuild-3.1.1.xsl"?>
<project name="rusticiTranslator" default="launch" basedir="../" xmlns:dn="antlib:org.apache.ant.dotnet">
<description>
This script automates translation of a C# svn branch to a Java branch
</description>
<property file="${basedir}/RusticiLogicTranslator/launch.properties" />
<property file="${user.home}/${ant.project.name}.build.properties" />
<property file="${user.home}/build.properties" />
<property file="${basedir}/RusticiLogicTranslator/build.properties" />
<!-- load the ant-dotnet task, see http://ant.apache.org/antlibs/dotnet/index.html -->
<taskdef uri="antlib:org.apache.ant.dotnet" resource="org/apache/ant/dotnet/antlib.xml" classpath="${builder.ant.lib}/ant-dotnet-1.0.jar" />
<!-- Load AntForm tasks -->
<taskdef name="antform" classname="com.sardak.antform.AntForm" classpath="${builder.ant.lib}/antform.jar"/>
<taskdef name="antmenu" classname="com.sardak.antform.AntMenu" classpath="${builder.ant.lib}/antform.jar"/>
<target name="launch">
<antform title="C# to Java Translation" save="${basedir}/RusticiLogicTranslator/launch.properties">
<label>Enter a scratch directory to use for building</label>
<fileSelectionProperty label="build directory : " property="build.dir" directoryChooser="true" />
<separator />
<label>Enter the locations of the branches you want to translate from / to</label>
<textProperty label="ScormEngineNet branch : " property="csharp.project.full" />
<textProperty label="ScormEngineJava branch : " property="java.project.full" />
<separator />
<booleanProperty label="Commit Java code after translation " property="is.commit.javacode" />
<booleanProperty label="Refresh and Rebuild cs2j executable " property="is.rebuild.cs2j" />
<controlbar>
<button label="Cancel" type="cancel" target="cancel" newproject="false"/>
<button label="Reset" type="reset" />
<button label="OK" type="ok"/>
</controlbar>
</antform>
<antcall target="ok" />
</target>
<target name="cancel">
<echo message="Translation cancelled by user" />
<property name="is.run.cancelled" value="true" />
</target>
<target name="ok" unless="is.run.cancelled">
<!--antcall target="dumpProperties" inheritall="false" / -->
<antcall target="svntranslate" inheritall="false" />
</target>
<target name="svntranslate" description="translate a C# branch to a Java branch"
depends="clean,init,buildtranslator,checkoutCSharpJavaCode,translateCSharpToJava,setAddedFiles,commitAdded,setRemovedFiles,commitRemoved,commitJavaCode">
</target>
<!-- is.rebuild.cs2j can be set through launch window. rebuild iff var is set and not equal to false -->
<target name="-svn.rebuild.cs2j.check">
<condition property="internal.is.rebuild.cs2j">
<and>
<isset property="is.rebuild.cs2j" />
<not>
<equals arg1="${is.rebuild.cs2j}" arg2="false" />
</not>
</and>
</condition>
</target>
<target name="buildtranslator" depends="-svn.rebuild.cs2j.check" if="internal.is.rebuild.cs2j">
<antcall target="refreshtranslator" />
<ant antfile="build.xml" target="clean" />
<ant antfile="build.xml" target="buildTranslator" inheritall="true" />
</target>
<target name="refreshtranslator" if="is.cs2j.svnwc">
<dn:dotnetexec executable="${svn.exe}">
<arg value="update" />
<arg value="${svntxexe.svnwc.dir}" />
</dn:dotnetexec>
</target>
<target name="checkoutCSharpJavaCode" unless="is.donot.checkout.code">
<mkdir dir="${csharpcode.dir}" />
<delete failonerror="true" dir="${csharpcode.dir}" />
<mkdir dir="${javacode.svnwc.dir}" />
<delete failonerror="true" dir="${javacode.svnwc.dir}" />
<mkdir dir="${javacode.old.svnwc.dir}" />
<delete failonerror="true" dir="${javacode.old.svnwc.dir}" />
<dn:dotnetexec executable="${svn.exe}">
<arg value="export" />
<arg value="${csharpcode.branch.url}" />
<arg value="${csharpcode.dir}" />
</dn:dotnetexec>
<dn:dotnetexec executable="${svn.exe}">
<arg value="checkout" />
<arg value="${javacode.branch.url}" />
<arg value="${javacode.svnwc.dir}" />
</dn:dotnetexec>
</target>
<target name="checkoutCS2JProject" unless="is.donot.checkout.code">
<mkdir dir="${cs2j.dir}" />
<delete failonerror="true" dir="${cs2j.dir}" />
<dn:dotnetexec executable="${svn.exe}">
<arg value="export" />
<arg value="${cs2j.branch.url}" />
<arg value="${cs2j.dir}" />
</dn:dotnetexec>
</target>
<target name="makeCopyJavaCode">
<copy todir="${javacode.old.svnwc.dir}">
<fileset dir="${javacode.svnwc.dir}" defaultexcludes="false" />
</copy>
</target>
<target name="translateCSharpToJava" depends="buildtranslator,checkoutCS2JProject,checkoutCSharpJavaCode,makeCopyJavaCode">
<!-- Delete existing java files, they will be recreated by the translation if neccessary -->
<delete dir="${javacode.svnwc.dir}">
<include name="**/*.java" />
</delete>
<ant antfile="build.xml" target="translateCS2J">
<!-- There are no cheats -->
<property name="cheats.dir" value="${cheats.dir}" />
<property name="cs.app.dir" value="${csharpcode.dir}" />
<property name="java.output.dir" value="${javacode.svnwc.dir}" />
<property name="cs.tx.dir" value="${csharpcode.tx.dir}" />
</ant>
</target>
<!-- is.commit.javacode can be set through launch window. rebuild iff var is set and not equal to false -->
<target name="-svn.commit.javacode.check">
<condition property="internal.is.commit.javacode">
<and>
<isset property="is.commit.javacode" />
<not>
<equals arg1="${is.commit.javacode}" arg2="false" />
</not>
</and>
</condition>
</target>
<target name="commitJavaCode" depends="-svn.commit.javacode.check" if="internal.is.commit.javacode">
<dn:dotnetexec executable="${svn.exe}">
<arg value="commit" />
<arg value="--message" />
<arg value="${svn.commit.msg.java}" />
<arg value="${javacode.svnwc.dir}" />
</dn:dotnetexec>
</target>
<target name="dumpProperties" description="output all set properties, a useful sanity check">
<echoproperties />
</target>
<target name="init" depends="">
<mkdir dir="${svntx.build.dir}" />
</target>
<target name="clean" depends="" description="clean out build area">
<!-- create dir if it doesn't exist, so delete only fails if there is a real problem -->
<mkdir dir="${svntx.build.dir}"/>
<delete failonerror="true" dir="${svntx.build.dir}" />
</target>
<target name="setAddedFiles">
<pathconvert property="svn.added.files" pathsep='" "' setonempty="false">
<fileset dir="${javacode.svnwc.dir}" includes="**/*.java" id="java.added.fileset">
<present present="srconly" targetdir="${javacode.old.svnwc.dir}" />
</fileset>
</pathconvert>
</target>
<target name="commitAdded" if="svn.added.files">
<dn:dotnetexec executable="${svn.exe}">
<arg value="add" />
<arg value='"${svn.added.files}"' />
</dn:dotnetexec>
</target>
<target name="setRemovedFiles">
<pathconvert property="svn.removed.files" pathsep='" "' setonempty="false">
<fileset dir="${javacode.old.svnwc.dir}" includes="**/*.java" id="java.removed.fileset">
<present present="srconly" targetdir="${javacode.svnwc.dir}" />
</fileset>
</pathconvert>
</target>
<!-- We only remove files from subversion if there are files to remove and is.commit.javacode is set -->
<target name="-svn.remove.files.check" depends="-svn.commit.javacode.check">
<condition property="is.svn.remove.files">
<and>
<isset property="svn.removed.files"/>
<isset property="internal.is.commit.javacode"/>
</and>
</condition>
</target>
<target name="commitRemoved" depends="-svn.remove.files.check" if="is.svn.remove.files">
<dn:dotnetexec executable="${svn.exe}">
<arg value="remove" />
<arg value='"${svn.removed.files}"' />
</dn:dotnetexec>
<dn:dotnetexec executable="${svn.exe}">
<arg value="commit" />
<arg value="--message" />
<arg value="${svn.commit.removed.msg.java}" />
<arg value="${javacode.old.svnwc.dir}" />
</dn:dotnetexec>
</target>
</project>

View File

@ -0,0 +1,259 @@
/*
[The "BSD licence"]
Copyright (c) 2002-2005 Kunle Odutola
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace RusticiSoftware.Translator
{
using System;
using FileInfo = System.IO.FileInfo;
using StringBuilder = System.Text.StringBuilder;
using AST = antlr.collections.AST;
using BaseAST = antlr.BaseAST;
using ASTFactory = antlr.ASTFactory;
using IToken = antlr.IToken;
using CommonASTWithHiddenTokens = antlr.CommonASTWithHiddenTokens;
using CommonHiddenStreamToken = antlr.CommonHiddenStreamToken;
/// <summary>
/// Summary description for ASTNode.
/// </summary>
///
[Serializable()]
public class ASTNode : CommonASTWithHiddenTokens
{
new public static readonly ASTNode.ASTNodeCreator Creator = new ASTNodeCreator();
//---------------------------------------------------------------------
// CONSTRUCTORS
//---------------------------------------------------------------------
public ASTNode() : base()
{
//
// TODO: Add constructor logic here
//
}
public ASTNode(IToken tok) : base(tok)
{
}
//---------------------------------------------------------------------
// PUBLIC METHODS
//---------------------------------------------------------------------
override public void initialize(antlr.collections.AST t)
{
base.initialize(t);
ASTNode node = t as ASTNode;
if (null != node)
{
Column = node._column;
Line = node._line;
DotNetType = node._dotNetType;
_fileinfo = node._fileinfo;
_previousSibling = node._previousSibling;
_parentNode = node._parentNode;
}
}
override public void initialize(IToken tok)
{
base.initialize(tok);
Column = tok.getColumn();
Line = tok.getLine();
CustomHiddenStreamToken ctok = tok as CustomHiddenStreamToken;
if (null != ctok)
{
File = ctok.File;
}
}
public virtual ASTNode GetFirstChildOfType(int type)
{
ASTNode result = null;
AST sibling = getFirstChild();
while (sibling != null)
{
if (sibling.Type == type)
{
result = (ASTNode) sibling;
break;
}
sibling = sibling.getNextSibling();
}
return result;
}
public void CopyPositionFrom(ASTNode other)
{
Line = other.Line;
Column = other.Column;
}
//---------------------------------------------------------------------
// ACCESSORS & MUTATORS
//---------------------------------------------------------------------
/// <summary>
/// Gets or sets the contents of the hidden-before token stream.
/// </summary>
///
public CustomHiddenStreamToken HiddenBefore
{
get { return (CustomHiddenStreamToken) hiddenBefore; }
set { hiddenBefore = (CommonHiddenStreamToken) value; }
}
/// <summary>
/// Gets or sets the contents of the hidden-after token stream.
/// </summary>
///
public CustomHiddenStreamToken HiddenAfter
{
get { return (CustomHiddenStreamToken) hiddenAfter; }
set { hiddenAfter = (CommonHiddenStreamToken) value; }
}
/// <summary>
/// Gets or Sets the source file line position for this Node
/// </summary>
///
public int Line
{
get { return _line; }
set {_line = value; }
}
/// <summary>
/// Gets or Sets the source file column position for this Node
/// </summary>
///
public int Column
{
get { return _column; }
set {_column = value; }
}
/// <summary>
/// Gets or Sets the source file for this Node
/// </summary>
///
public FileInfo File
{
get { return _fileinfo; }
set { _fileinfo = value; }
}
public TypeRep DotNetType
{
get { return _dotNetType; }
set { _dotNetType = value; }
}
public ASTNode getParent()
{
return _parentNode;
}
public ASTNode getPreviousSibling()
{
return _previousSibling;
}
public void setParent(ASTNode parent)
{
this._parentNode = parent;
}
public void setPreviousSibling(ASTNode previousSibling)
{
this._previousSibling = previousSibling;
}
public virtual void addChildEx(ASTNode node)
{
if (node == null)
return ;
ASTNode t = (ASTNode) this.down;
if (t != null)
{
while (t.right != null)
{
t = (ASTNode) t.right;
}
t.right = (BaseAST) node;
node._previousSibling = t;
node._parentNode = this;
}
else
{
this.down = (BaseAST) node;
node._parentNode = this;
node._previousSibling = null;
}
}
//---------------------------------------------------------------------
// PRIVATE DATA MEMBERS
//---------------------------------------------------------------------
private int _column = -1;
private int _line = -1;
private FileInfo _fileinfo;
private ASTNode _parentNode;
private ASTNode _previousSibling;
private TypeRep _dotNetType = null;
public class ASTNodeCreator : antlr.ASTNodeCreator
{
public ASTNodeCreator() {}
/// <summary>
/// Returns the fully qualified name of the AST type that this
/// class creates.
/// </summary>
public override string ASTNodeTypeName
{
get
{
return typeof(ASTNode).FullName;;
}
}
/// <summary>
/// Constructs a <see cref="AST"/> instance.
/// </summary>
public override AST Create()
{
return new ASTNode();
}
}
}
}

View File

@ -0,0 +1,254 @@
/*
[The "BSD licence"]
Copyright (c) 2002-2005 Kunle Odutola
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace RusticiSoftware.Translator
{
using System;
using FileInfo = System.IO.FileInfo;
using AST = antlr.collections.AST;
using ASTPair = antlr.ASTPair;
using ASTFactory = antlr.ASTFactory;
public class ASTNodeFactory : ASTFactory
{
//---------------------------------------------------------------------
// CONSTRUCTORS
//---------------------------------------------------------------------
/// <summary>
/// Constructs an <c>ASTNodeFactory</c> with the default AST node type.
/// </summary>
public ASTNodeFactory() :
base(typeof(ASTNode).FullName)
{
setASTNodeCreator(new ASTNode.ASTNodeCreator());
}
/// <summary>
/// Constructs an <c>ASTNodeFactory</c> with the specified AST node type
/// as the default.
/// </summary>
/// <param name="nodeTypeName">Default AST node type name.</param>
public ASTNodeFactory(string nodeTypeName) :
base(typeof(ASTNode).FullName)
{
setASTNodeCreator(new ASTNode.ASTNodeCreator());
}
//---------------------------------------------------------------------
// DATA MEMBERS
//---------------------------------------------------------------------
private FileInfo filefinfo_;
//---------------------------------------------------------------------
// FUNCTION MEMBERS
//---------------------------------------------------------------------
public FileInfo FileInfo
{
get { return filefinfo_; }
set { filefinfo_ = value; }
}
/// <summary>
/// Add a child to the current AST
/// </summary>
/// <param name="currentAST">The AST to add a child to</param>
/// <param name="child">The child AST to be added</param>
public override void addASTChild(ref ASTPair currentAST, AST child)
{
if (child != null)
{
if (currentAST.root == null)
{
// Make new child the current root
currentAST.root = child;
((ASTNode) child).setParent(null);
}
else
{
((ASTNode) child).setParent((ASTNode) currentAST.root);
if (currentAST.child == null)
{
// Add new child to current root
currentAST.root.setFirstChild(child);
((ASTNode) child).setPreviousSibling(null);
}
else
{
currentAST.child.setNextSibling(child);
((ASTNode) child).setPreviousSibling((ASTNode) currentAST.child);
}
}
// Make new child the current child
currentAST.child = child;
currentAST.advanceChildToEnd();
}
}
/// <summary>
/// Duplicate AST Node tree rooted at specified AST node and all of it's siblings.
/// </summary>
/// <param name="t">Root of AST Node tree.</param>
/// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
public override AST dupList(AST t)
{
AST result = dupTree(t); // if t == null, then result==null
AST nt = result;
while (t != null)
{
// for each sibling of the root
t = t.getNextSibling();
AST d = dupTree(t);
nt.setNextSibling(d); // dup each subtree, building new tree
if (d != null) ((ASTNode) d).setPreviousSibling((ASTNode) nt);
nt = nt.getNextSibling();
}
return result;
}
/// <summary>
/// Duplicate AST Node tree rooted at specified AST node. Ignore it's siblings.
/// </summary>
/// <param name="t">Root of AST Node tree.</param>
/// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
public override AST dupTree(AST t)
{
AST result = dup(t); // make copy of root
// copy all children of root.
if (t != null)
{
AST d = dupList(t.getFirstChild());
result.setFirstChild(d);
if (d != null) ((ASTNode) d).setParent((ASTNode) result);
}
return result;
}
/// <summary>
/// Make a tree from a list of nodes. The first element in the
/// array is the root. If the root is null, then the tree is
/// a simple list not a tree. Handles null children nodes correctly.
/// For example, build(a, b, null, c) yields tree (a b c). build(null,a,b)
/// yields tree (nil a b).
/// </summary>
/// <param name="nodes">List of Nodes.</param>
/// <returns>AST Node tree.</returns>
public override AST make(params AST[] nodes)
{
if (nodes == null || nodes.Length == 0)
return null;
AST root = nodes[0];
AST tail = null;
if (root != null)
{
root.setFirstChild(null); // don't leave any old pointers set
}
// link in children;
for (int i = 1; i < nodes.Length; i++)
{
if (nodes[i] == null)
continue;
// ignore null nodes
if (root == null)
{
// Set the root and set it up for a flat list
root = (tail = nodes[i]);
}
else if (tail == null)
{
root.setFirstChild(nodes[i]);
((ASTNode) nodes[i]).setParent((ASTNode) root);
tail = root.getFirstChild();
}
else
{
((ASTNode) nodes[i]).setParent((ASTNode) root);
tail.setNextSibling(nodes[i]);
((ASTNode) nodes[i]).setPreviousSibling((ASTNode) tail);
tail = tail.getNextSibling();
}
// Chase tail to last sibling
while (tail.getNextSibling() != null)
{
tail = tail.getNextSibling();
}
}
return root;
}
/// <summary>
/// Make an AST the root of current AST.
/// </summary>
/// <param name="currentAST"></param>
/// <param name="root"></param>
public override void makeASTRoot(ref ASTPair currentAST, AST root)
{
if (root != null)
{
// Add the current root as a child of new root
((ASTNode) root).addChildEx((ASTNode) currentAST.root);
// The new current child is the last sibling of the old root
currentAST.child = currentAST.root;
currentAST.advanceChildToEnd();
// Set the new root
currentAST.root = root;
}
}
public override AST create()
{
ASTNode newNode = (ASTNode) base.create();
newNode.File = filefinfo_;
return newNode;
}
public override AST create(int type)
{
ASTNode newNode = (ASTNode) base.create(type);
newNode.File = filefinfo_;
return newNode;
}
public override AST create(int type, string txt)
{
ASTNode newNode = (ASTNode) base.create(type, txt);
newNode.File = filefinfo_;
return newNode;
}
public override AST create(int type, string txt, string ASTNodeTypeName)
{
ASTNode newNode = (ASTNode) base.create(type, txt, ASTNodeTypeName);
newNode.File = filefinfo_;
return newNode;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,622 @@
header
{
using System.IO;
using System.Globalization;
using TokenStreamSelector = antlr.TokenStreamSelector;
}
options
{
language = "CSharp";
namespace = "RusticiSoftware.Translator";
}
/*
[The "BSD licence"]
Copyright (c) 2002-2005 Kunle Odutola
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/// <summary>
/// A Lexer for the C# language including preprocessors directives.
/// </summary>
///
/// <remarks>
/// <para>
/// The Lexer defined below is based on the "C# Language Specification" as
/// documented in the ECMA-334 standard dated December 2001.
/// </para>
///
/// <para>
/// The Lexer depends on the existence of two companion lexers to which it will
/// delegate the handling of the rest of the contents of a line containing a C#
/// preprocessor directives after it has tokenized the directive itself. This
/// companion lexers must be registered with the names "preproLexer" and
/// "hooverLexer" in the <see cref="TokenStreamSelector"/> associated with this
/// Lexer via the Selector property.
/// </para>
///
/// <para>
/// History
/// </para>
///
/// <para>
/// 31-May-2002 kunle Created first cut from ECMA spec (renamed from Ecma344_CSharp.g) <br />
/// 08-Feb-2003 kunle Separated Lexer from the original combined Lexer/Parser grammar file <br />
/// 05-Apr-2004 kunle Post-directive handling is now delegated to one of two companion lexers. <br />
/// </para>
///
/// </remarks>
*/
class CSharpLexer extends CSharpLexerBase;
options
{
importVocab = CSharpLexerBase;
exportVocab = CSharpLexer;
charVocabulary = '\u0000'..'\uFFFE'; // All UNICODE characters except \uFFFF [and \u0000 to \u0002 used by ANTLR]
k = 3; // two characters of lookahead
testLiterals = false; // don't automatically test for literals
//defaultErrorHandler = true;
defaultErrorHandler = false;
codeGenMakeSwitchThreshold = 5; // Some optimizations
codeGenBitsetTestThreshold = 5;
}
//======================================
// Section A.1.7 Keywords
//
tokens // MUST be kept in sync with "keywordsTable" Hashtable below!!
{
ABSTRACT = "abstract";
AS = "as";
BASE = "base";
BOOL = "bool";
BREAK = "break";
BYTE = "byte";
CASE = "case";
CATCH = "catch";
CHAR = "char";
CHECKED = "checked";
CLASS = "class";
CONST = "const";
CONTINUE = "continue";
DECIMAL = "decimal";
// DEFAULT = "default";
DELEGATE = "delegate";
DO = "do";
DOUBLE = "double";
ELSE = "else";
ENUM = "enum";
EVENT = "event";
EXPLICIT = "explicit";
EXTERN = "extern";
// FALSE = "false";
FINALLY = "finally";
FIXED = "fixed";
FLOAT = "float";
FOR = "for";
FOREACH = "foreach";
GOTO = "goto";
IF = "if";
IMPLICIT = "implicit";
IN = "in";
INT = "int";
INTERFACE = "interface";
INTERNAL = "internal";
IS = "is";
LOCK = "lock";
LONG = "long";
NAMESPACE = "namespace";
NEW = "new";
NULL = "null";
OBJECT = "object";
OPERATOR = "operator";
OUT = "out";
OVERRIDE = "override";
PARAMS = "params";
PRIVATE = "private";
PROTECTED = "protected";
PUBLIC = "public";
READONLY = "readonly";
REF = "ref";
RETURN = "return";
SBYTE = "sbyte";
SEALED = "sealed";
SHORT = "short";
SIZEOF = "sizeof";
STACKALLOC = "stackalloc";
STATIC = "static";
STRING = "string";
STRUCT = "struct";
SWITCH = "switch";
THIS = "this";
THROW = "throw";
// TRUE = "true";
TRY = "try";
TYPEOF = "typeof";
UINT = "uint";
ULONG = "ulong";
UNCHECKED = "unchecked";
UNSAFE = "unsafe";
USHORT = "ushort";
USING = "using";
VIRTUAL = "virtual";
VOID = "void";
VOLATILE = "volatile";
WHILE = "while";
DOT;
UINT_LITERAL;
LONG_LITERAL;
ULONG_LITERAL;
DECIMAL_LITERAL;
FLOAT_LITERAL;
DOUBLE_LITERAL;
"add";
"remove";
"get";
"set";
"assembly";
"field";
"method";
"module";
"param";
"property";
"type";
}
{
/// <summary>
/// A <see cref="TokenStreamSelector"> for switching between this Lexer and the Preprocessor Lexer.
/// </summary>
private TokenStreamSelector selector_;
/// <summary>
/// A <see cref="TokenStreamSelector"> for switching between this Lexer and the Preprocessor Lexer.
/// </summary>
public TokenStreamSelector Selector
{
get { return selector_; }
set { selector_ = value; }
}
private FileInfo _fileinfo = null;
/// <summary>
/// Update _fileinfo member whenever filename changes.
/// </summary>
public override void setFilename(string f)
{
base.setFilename(f);
_fileinfo = new FileInfo(f);
}
/// <summary>
/// Ensures all tokens have access to the source file's details.
/// </summary>
protected override IToken makeToken(int t)
{
IToken result = base.makeToken(t);
CustomHiddenStreamToken customToken = result as CustomHiddenStreamToken;
if ( customToken != null )
{
customToken.File = _fileinfo;
}
return result;
}
/// <summary>
/// This table is used to keep a searchable list of keywords only. This is used mainly
/// as for section "A.1.6 Identifers" for determining if an identifier is indeed a
/// VERBATIM_IDENTIFIER. It's contents MUST be kept in sync with the contents of section
/// "A.1.7 Keywords" above.
/// </summary>
///
private static Hashtable keywordsTable = new Hashtable();
static CSharpLexer()
{
keywordsTable.Add(ABSTRACT, "abstract");
keywordsTable.Add(AS, "as");
keywordsTable.Add(BASE, "base");
keywordsTable.Add(BOOL, "bool");
keywordsTable.Add(BREAK, "break");
keywordsTable.Add(BYTE, "byte");
keywordsTable.Add(CASE, "case");
keywordsTable.Add(CATCH, "catch");
keywordsTable.Add(CHAR, "char");
keywordsTable.Add(CHECKED, "checked");
keywordsTable.Add(CLASS, "class");
keywordsTable.Add(CONST, "const");
keywordsTable.Add(CONTINUE, "continue");
keywordsTable.Add(DECIMAL, "decimal");
keywordsTable.Add(DEFAULT, "default");
keywordsTable.Add(DELEGATE, "delegate");
keywordsTable.Add(DO, "do");
keywordsTable.Add(DOUBLE, "double");
keywordsTable.Add(ELSE, "else");
keywordsTable.Add(ENUM, "enum");
keywordsTable.Add(EVENT, "event");
keywordsTable.Add(EXPLICIT, "explicit");
keywordsTable.Add(EXTERN, "extern");
keywordsTable.Add(FALSE, "false");
keywordsTable.Add(FINALLY, "finally");
keywordsTable.Add(FIXED, "fixed");
keywordsTable.Add(FLOAT, "float");
keywordsTable.Add(FOR, "for");
keywordsTable.Add(FOREACH, "foreach");
keywordsTable.Add(GOTO, "goto");
keywordsTable.Add(IF, "if");
keywordsTable.Add(IMPLICIT, "implicit");
keywordsTable.Add(IN, "in");
keywordsTable.Add(INT, "int");
keywordsTable.Add(INTERFACE, "interface");
keywordsTable.Add(INTERNAL, "internal");
keywordsTable.Add(IS, "is");
keywordsTable.Add(LOCK, "lock");
keywordsTable.Add(LONG, "long");
keywordsTable.Add(NAMESPACE, "namespace");
keywordsTable.Add(NEW, "new");
keywordsTable.Add(NULL, "null");
keywordsTable.Add(OBJECT, "object");
keywordsTable.Add(OPERATOR, "operator");
keywordsTable.Add(OUT, "out");
keywordsTable.Add(OVERRIDE, "override");
keywordsTable.Add(PARAMS, "params");
keywordsTable.Add(PRIVATE, "private");
keywordsTable.Add(PROTECTED, "protected");
keywordsTable.Add(PUBLIC, "public");
keywordsTable.Add(READONLY, "readonly");
keywordsTable.Add(REF, "ref");
keywordsTable.Add(RETURN, "return");
keywordsTable.Add(SBYTE, "sbyte");
keywordsTable.Add(SEALED, "sealed");
keywordsTable.Add(SHORT, "short");
keywordsTable.Add(SIZEOF, "sizeof");
keywordsTable.Add(STACKALLOC, "stackalloc");
keywordsTable.Add(STATIC, "static");
keywordsTable.Add(STRING, "string");
keywordsTable.Add(STRUCT, "struct");
keywordsTable.Add(SWITCH, "switch");
keywordsTable.Add(THIS, "this");
keywordsTable.Add(THROW, "throw");
keywordsTable.Add(TRUE, "true");
keywordsTable.Add(TRY, "try");
keywordsTable.Add(TYPEOF, "typeof");
keywordsTable.Add(UINT, "uint");
keywordsTable.Add(ULONG, "ulong");
keywordsTable.Add(UNCHECKED, "unchecked");
keywordsTable.Add(UNSAFE, "unsafe");
keywordsTable.Add(USHORT, "ushort");
keywordsTable.Add(USING, "using");
keywordsTable.Add(VIRTUAL, "virtual");
keywordsTable.Add(VOID, "void");
keywordsTable.Add(WHILE, "while");
}
public bool IsLetterCharacter(string s)
{
return ( (UnicodeCategory.LowercaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Ll
(UnicodeCategory.ModifierLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lm
(UnicodeCategory.OtherLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lo
(UnicodeCategory.TitlecaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lt
(UnicodeCategory.UppercaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lu
(UnicodeCategory.LetterNumber == Char.GetUnicodeCategory(s, 1)) //UNICODE class Nl
);
}
public bool IsIdentifierCharacter(string s)
{
return ( (UnicodeCategory.LowercaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Ll
(UnicodeCategory.ModifierLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lm
(UnicodeCategory.OtherLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lo
(UnicodeCategory.TitlecaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lt
(UnicodeCategory.UppercaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lu
(UnicodeCategory.LetterNumber == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Nl
(UnicodeCategory.NonSpacingMark == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Mn
(UnicodeCategory.SpacingCombiningMark == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Mc
(UnicodeCategory.DecimalDigitNumber == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Nd
(UnicodeCategory.ConnectorPunctuation == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Pc
(UnicodeCategory.Format == Char.GetUnicodeCategory(s, 1)) //UNICODE class Cf
);
}
public bool IsCombiningCharacter(string s)
{
return ( (UnicodeCategory.NonSpacingMark == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Mn
(UnicodeCategory.SpacingCombiningMark == Char.GetUnicodeCategory(s, 1)) //UNICODE class Mc
);
}
}
//======================================
// Start of Lexer Rules
//======================================
//======================================
// Section A.1.1 Line terminators
//
NEWLINE
: ( '\r' // MacOS-style newline
( options { generateAmbigWarnings=false; }
: '\n' // DOS/Windows style newline
)?
| '\n' // UNIX-style newline
| '\u2028' // UNICODE line separator
| '\u2029' // UNICODE paragraph separator
)
{ newline();
}
;
//======================================
// Section A.1.2 White space
//
WHITESPACE
: pp1:PP_DIRECTIVE
{ if ( pp1.getColumn() == 1)
{
$setType(pp1.Type);
if ((pp1.Type == PP_REGION) || (pp1.Type == PP_ENDREGION) || (pp1.Type == PP_WARNING) || (pp1.Type == PP_ERROR))
selector_.push("hooverLexer");
else
selector_.push("directivesLexer");
}
else
$setType(PP_STRING);
}
| nnw:NON_NEWLINE_WHITESPACE (NON_NEWLINE_WHITESPACE)*
( { (nnw.getColumn() == 1) }? pp2:PP_DIRECTIVE
{
$setType(pp2.Type);
if ((pp2.Type == PP_REGION) || (pp2.Type == PP_ENDREGION) || (pp2.Type == PP_WARNING) || (pp2.Type == PP_ERROR))
selector_.push("hooverLexer");
else
selector_.push("directivesLexer");
}
)?
;
//======================================
// Section A.1.3 Comments
//
ML_COMMENT
: "/*"
( options { generateAmbigWarnings=false; } // ignore non-determinism on "*/" between me and block exit
: { LA(2) != '/' }? '*'
| NEWLINE //{ newline(); }
| ~( '*' | '\r' | '\n' | '\u2028' | '\u2029') // ~( NEWLINE | '*' ) -- generated error
)*
"*/" //{ $setType(Token.SKIP); }
;
//======================================
// A.1.6 Identifiers
//
IDENTIFIER
options { testLiterals = true; }
: '@' '"' { $setType(STRING_LITERAL); }
( ~( '"' )
| ('"' '"')
)*
'"'
| ( '@' )?
(
( '_'
| LETTER_CHARACTER
| { IsLetterCharacter(eseq.getText()) }? eseq:UNICODE_ESCAPE_SEQUENCE
)
( LETTER_CHARACTER
| DECIMAL_DIGIT_CHARACTER
| CONNECTING_CHARACTER
| COMBINING_CHARACTER
| FORMATTING_CHARACTER
| { IsIdentifierCharacter(eseq2.getText()) }? eseq2:UNICODE_ESCAPE_SEQUENCE
)*
)
;
//======================================
// A.1.8 Literals
//
//
INT_LITERAL // BYTE, SHORT, INT, LONG
: '0' ('x' | 'X') (HEX_DIGIT)+
( ('l' | 'L') { $setType(LONG_LITERAL); }
( ('u' | 'U') { $setType(ULONG_LITERAL); } )?
| ('u' | 'U') { $setType(UINT_LITERAL); }
( ('l' | 'L') { $setType(ULONG_LITERAL); } )?
)?
| '.' { $setType(DOT); }
( (DECIMAL_DIGIT)+ { $setType(DOUBLE_LITERAL); }
( ('e'|'E') ('+'|'-')? (DECIMAL_DIGIT)+ )?
( ( 'f' | 'F' ) { $setType(FLOAT_LITERAL); }
| ( 'd' | 'D' )
| ( 'm' | 'M' ) { $setType(DECIMAL_LITERAL); }
)?
)?
| (DECIMAL_DIGIT)+
( '.' (DECIMAL_DIGIT)+ { $setType(DOUBLE_LITERAL); }
( ('e'|'E') ('+'|'-')? (DECIMAL_DIGIT)+ )?
( ( 'f' | 'F' ) { $setType(FLOAT_LITERAL); }
| ( 'd' | 'D' )
| ( 'm' | 'M' ) { $setType(DECIMAL_LITERAL); }
)?
| ('e'|'E') ('+'|'-')?
(DECIMAL_DIGIT)+ { $setType(DOUBLE_LITERAL); }
( ( 'f' | 'F' ) { $setType(FLOAT_LITERAL); }
| ( 'd' | 'D' )
| ( 'm' | 'M' ) { $setType(DECIMAL_LITERAL); }
)?
| ( ( 'f' | 'F' ) { $setType(FLOAT_LITERAL); }
| ( 'd' | 'D' ) { $setType(DOUBLE_LITERAL); }
| ( 'm' | 'M' ) { $setType(DECIMAL_LITERAL); }
)
| ( ('l' | 'L') { $setType(LONG_LITERAL); }
( ('u' | 'U') { $setType(ULONG_LITERAL); } )?
| ('u' | 'U') { $setType(UINT_LITERAL); }
( ('l' | 'L') { $setType(ULONG_LITERAL); } )?
)
)?
;
CHAR_LITERAL
: '\''
( ~( '\'' | '\\' | '\r' | '\n' | '\u2028' | '\u2029' )
| ESCAPED_LITERAL
)
'\''
;
STRING_LITERAL
: '"'
( ~( '"' | '\\' | '\r' | '\n' | '\u2028' | '\u2029' )
| ESCAPED_LITERAL
)*
'"'
;
// The ESCAPED_LITERAL rule represents a common subset of the definitons of both STRING_LITERAL
// and CHAR_LITERAL. It was extracted from both to ensure that multiples copies of the same
// [semi-complex] sub-recognizer isn't maintained in multiple places.
//
protected ESCAPED_LITERAL
: '\\'
( '\''
| '"'
| '\\'
| '0'
| 'a'
| 'b'
| 'f'
| 'n'
| 'r'
| 't'
| 'v'
| 'x' HEX_DIGIT
( options { generateAmbigWarnings=false; }
: HEX_DIGIT
( options { generateAmbigWarnings=false; }
: HEX_DIGIT
( options { generateAmbigWarnings=false; }
: HEX_DIGIT
)?
)?
)?
)
| UNICODE_ESCAPE_SEQUENCE
;
//======================================
// A.1.9 Operators and punctuators
//
OPEN_CURLY : '{' ;
CLOSE_CURLY : '}' ;
OPEN_BRACK : '[' ;
CLOSE_BRACK : ']' ;
OPEN_PAREN : '(' ;
CLOSE_PAREN : ')' ;
//DOT : '.' ; // moved to INTEGER_LITERAL rule to avoid conflict
COMMA : ',' ;
COLON : ':' ;
SEMI : ';' ;
PLUS : '+' ;
MINUS : '-' ;
STAR : '*' ;
DIV : '/' ;
MOD : '%' ;
BIN_AND : '&' ;
BIN_OR : '|' ;
BIN_XOR : '^' ;
LOG_NOT : '!' ;
BIN_NOT : '~' ;
ASSIGN : '=' ;
LTHAN : '<' ;
GTHAN : '>' ;
QUESTION : '?' ;
INC : "++" ;
DEC : "--" ;
LOG_AND : "&&" ;
LOG_OR : "||" ;
SHIFTL : "<<" ;
SHIFTR : ">>" ;
EQUAL : "==" ;
NOT_EQUAL : "!=" ;
LTE : "<=" ;
GTE : ">=" ;
PLUS_ASSIGN : "+=" ;
MINUS_ASSIGN : "-=" ;
STAR_ASSIGN : "*=" ;
DIV_ASSIGN : "/=" ;
MOD_ASSIGN : "%=" ;
BIN_AND_ASSIGN : "&=" ;
BIN_OR_ASSIGN : "|=" ;
BIN_XOR_ASSIGN : "^=" ;
SHIFTL_ASSIGN : "<<=" ;
SHIFTR_ASSIGN : ">>=" ;
DEREF : "->" ;
//======================================
// A.1.10 Pre-processing directives
//
protected PP_DIRECTIVE
: '#' (NON_NEWLINE_WHITESPACE)*
( "define" { $setType(PP_DEFINE); }
| "undef" { $setType(PP_UNDEFINE); }
| "if" { $setType(PP_COND_IF); }
| "line" { $setType(PP_LINE); }
| "error" { $setType(PP_ERROR); }
| "warning" { $setType(PP_WARNING); }
| "region" { $setType(PP_REGION); }
| 'e'
( 'l'
( "se" { $setType(PP_COND_ELSE); }
| "if" { $setType(PP_COND_ELIF); }
)
| "nd"
( "if" { $setType(PP_COND_ENDIF); }
| "region" { $setType(PP_ENDREGION); }
)
)
)
;

View File

@ -0,0 +1,201 @@
header
{
using System.Globalization;
}
options
{
language = "CSharp";
namespace = "RusticiSoftware.Translator";
}
/*
[The "BSD licence"]
Copyright (c) 2002-2005 Kunle Odutola
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/// <summary>
/// The basic building block of C# Preprocessors and Lexers.
/// </summary>
///
/// <remarks>
/// <para>
/// The Lexer defined below is effectively an abstract base class that collects together a
/// number of rules that are useful to all Preprocessors and Lexers for the C# language.
/// </para>
///
/// <para>
/// History
/// </para>
///
/// <para>
/// 26-Jan-2003 kunle Derived this Lexer from the original combined grammar <br/>
/// </para>
///
/// </remarks>
*/
class CSharpLexerBase extends UnicodeLexerBase;
options
{
importVocab = UnicodeLexerBase;
exportVocab = CSharpLexerBase;
charVocabulary = '\u0000'..'\uFFFE'; // All UNICODE characters except \uFFFF [and \u0000 to \u0002 used by ANTLR]
k = 2;
testLiterals = false; // don't automatically test for literals
defaultErrorHandler = false;
}
tokens
{
TRUE = "true";
FALSE = "false";
DEFAULT = "default";
PP_DEFINE;
PP_UNDEFINE;
PP_COND_IF;
PP_COND_ELIF;
PP_COND_ELSE;
PP_COND_ENDIF;
PP_LINE;
PP_ERROR;
PP_WARNING;
PP_REGION;
PP_ENDREGION;
PP_FILENAME;
PP_IDENT;
PP_STRING;
PP_NUMBER;
WHITESPACE;
}
//======================================
// Start of Lexer Rules
//======================================
// The following group of rules are shared by C# Preprocessors and Lexers
QUOTE : '"' ;
OPEN_PAREN : '(' ;
CLOSE_PAREN : ')' ;
LOG_NOT : '!' ;
LOG_AND : "&&" ;
LOG_OR : "||" ;
EQUAL : "==" ;
NOT_EQUAL : "!=" ;
//======================================
// Section A.1.3 Comments
//
SL_COMMENT
: "//" ( NOT_NEWLINE )* (NEWLINE)?
;
//======================================
// Section A.1.1 Line terminators
//
//protected
NEWLINE
: ( '\r' // MacOS-style newline
( options { generateAmbigWarnings=false; }
: '\n' // DOS/Windows style newline
)?
| '\n' // UNIX-style newline
| '\u2028' // UNICODE line separator
| '\u2029' // UNICODE paragraph separator
)
{ newline(); }
;
protected NOT_NEWLINE
: ~( '\r' | '\n' | '\u2028' | '\u2029' )
;
//======================================
// Section A.1.2 White space
//
protected NON_NEWLINE_WHITESPACE
: '\t' // horiz_tab
// | ' ' // space -- commented out because UNICODE_CLASS_Zs contains space too
| '\f' // form_feed
| '\u000B' // '\u000B' == '\v' == vert_tab
| UNICODE_CLASS_Zs
;
//======================================
// Section A.1.5 Unicode character escape sequences
//
protected UNICODE_ESCAPE_SEQUENCE
: '\\'
( 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
| 'U' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
)
;
protected DECIMAL_DIGIT
: ('0'..'9')
;
protected HEX_DIGIT
: ('0'..'9'|'A'..'F'|'a'..'f')
;
protected LETTER_CHARACTER
: UNICODE_CLASS_Lu
| UNICODE_CLASS_Ll
| UNICODE_CLASS_Lt
| UNICODE_CLASS_Lm
| UNICODE_CLASS_Lo
| UNICODE_CLASS_Nl
;
protected DECIMAL_DIGIT_CHARACTER
: UNICODE_CLASS_Nd
;
protected CONNECTING_CHARACTER
: UNICODE_CLASS_Pc
;
protected COMBINING_CHARACTER
: UNICODE_CLASS_Mn
| UNICODE_CLASS_Mc
;
protected FORMATTING_CHARACTER
: UNICODE_CLASS_Cf
;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
[The "BSD licence"]
Copyright (c) 2002-2005 Kunle Odutola
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code MUST RETAIN the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form MUST REPRODUCE the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior WRITTEN permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,139 @@
kcsparse - a ECMA-334 C# Grammar Sample for ANTLR 2.7.7
1 December, 2005
Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
Micheal Jordan
1. INTRODUCTION
Congratulations, you have found 'kcsparse' - a nice YAC#GFA[*]!
We hope you find 'kcsparse' delightful and useful even but, as per the
license under which you may use it, this software is not guaranteed to
work. See LICENSE.TXT for the full text of the license.
----------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
2. WHAT'S A YAC#GFA?
Yet Another C# Grammar For ANTLR.
This particular example is called 'kcsparse' and we hope you like it.
It is probably a more complete and usable YAC#GFA than others. It is
deliberately packaged in the style of the samples that are included with
ANTLR itself (and may become one of the standard samples). In any event,
it should just work out-of-the box for many C# source files.
2.1 WHAT kcsparse CAN DO
- Parse C# 1.x source code including some with C# preprocessing directives.
- Build an AST from the C# source.
- Display the AST it builts from C# source.
- Unparse the AST (i.e. pretty prints the AST) back to source code.
2.2 WHAT kcsparse CAN'T DO?
- Full parse and resolve of the input C# source code.
(kcsparse is NOT a C# front-end but, you can build one based on it)
- Parse all C# 1.x source code (esp. those with use of preprocessing directives).
(kcsparse is NOT a full C# 1.0 parser - it particularly fails on C# source
files where simply deleting (or commenting out) all preprocessing directives
results in illegal C# source but, you extend it to be)
- Parse C# source code with C# 2.0 or later features like generics.
(kcsparse is NOT a C# 2.0 parser but, you extend it to be)
- Compile C# source code to MSIL, bytecode or any other lanaguage
(kcsparse is NOT a C# translator/compiler but, you can build one based on it)
- Interpret C# source code
(kcsparse is NOT a C# interpreter but, you can build one based on it)
- Mow your lawns or fetch you a cold beer
(But we would like it to be!)
3. WHAT'S IN THE PACK?
Along with this with file, you should have received the following:
README.TXT This file
LICENSE.TXT Our license for this software
csharp_v1.build NAnt build file
CSharpLexer.g Main C# lexer grammar file
CSharpPreprocessorLexer.g C# lexer grammar file (used for preprocessor directives)
CSharpPreprocessorHooverLexer.g C# lexer grammar file (used for preprocessor directives)
CSharpLexerBase.g Common base for all C# lexer grammars
UnicodeLexerBase.g Common base for unicode-savvy lexer grammars
CSharpParser.g C# parser grammar file
CSharpPrettyPrinter.g C# pretty printer grammar file
CustomHiddenStreamToken.cs Custom IToken class
ASTNode.cs Custom AST node class
ASTNodeFactory.cs Custom ASTFactory class
CodeMaskEnums.cs Helper class
Main.cs Contains sample parsing application
csharp.flex Lexer grammar file for use with C# Flex
testfiles Directory containing test files to test C# parsing
AllCSharpConstructs.cs
Empty.cs
EmptyNamespace.cs
Testing.cs
Using.cs
UsingGlobalAttributes.cs
Tools
csflex.exe C# Flex executable
runtime.dll [supplied with C# Flex]
4. USING kscparse
The easiest way to use kcsparse is to unpack the files into a directory below
the %ANTLR_HOME%/examples/csharp/ directory. This would "install" it just like
any of the other ANTLR C# examples. Be sure to maintain the directory
structure of the archive as shown above.
Then, just type 'nant' (without the single quotes) to build and try kcsparse.
This assumes that the ANTLR C# runtimes files have been compiled and are in the
expected location.
Once it is built, you can also run kcsparse directly yourself:
kcsparse <filename> -- parse the specified <filename>
kcsparse -flex <filename> -- parse the specified <filename> (uses flex lexer)
kcsparse <directory> -- parse all *.cs files in <directory>
kcsparse -flex <directory> -- parse all *.cs files in <directory> (uses flex lexer)
kcsparse -showtree <file_or_directory> -- parse all *.cs files in <file_or_directory> and
display the AST
kcsparse -prettyprint <filename> -- parse <filename> and unparse (pretty-print)
the AST to the console
kcsparse -flex -prettyprint <filename> -- parse <filename> and unparse (pretty-print)
the AST to the console (uses flex lexer)
5. kscparse STATUS
kcsparse still has some bugs. kcsparse is mostly complete but expect a few rough edges.

View File

@ -0,0 +1,243 @@
header
{
using System.IO;
using System.Globalization;
using TokenStreamSelector = antlr.TokenStreamSelector;
}
options
{
language = "CSharp";
namespace = "RusticiSoftware.Translator";
}
/*
[The "BSD licence"]
Copyright (c) 2002-2005 Kunle Odutola
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/// <summary>
/// A Preprocessor Lexer for the C# Language
/// </summary>
///
/// <remarks>
/// <para>
/// The Lexer defined below is designed to match and identify only tokens related to the
/// handling of preprocessing directives for the C# language in the source text. It is
/// designed to match the tokens that can occur after any of the following directives
/// (on the same line):
/// <list type="bullet">
/// <item>
/// <term>#region</term>
/// </item>
/// <item>
/// <term>#endregion</term>
/// </item>
/// <item>
/// <term>#error</term>
/// </item>
/// <item>
/// <term>#warning</term>
/// </item>
/// </list>
/// </para>
///
/// <para>
/// This preprocessing lexer is designed to work in tandem with the C# Lexer defined
/// in the CSharpLexer.g file. In order words, the lexing of all the input not handled
/// here is assumed to be handled by the other C# Lexer. This other C# Lexer may or may
/// not be aware of C# preprocessing directives. The co-operation is implemented via
/// ANTLR's TokenStreamSelector mechanism.
/// </para>
///
/// <para>
/// The operation of this C# preprocessing lexer is based on the "C# Language Specification"
/// as documented in the ECMA-334 standard dated December 2001.
/// </para>
///
/// <para>
/// History
/// </para>
///
/// <para>
/// 05-Apr-2004 kunle Derived this Lexer from the CSharpPreprocessorLexer<br/>
/// </para>
///
*/
class CSharpPreprocessorHooverLexer extends CSharpLexerBase;
options
{
importVocab = CSharpLexerBase;
exportVocab = CSharpHoover;
charVocabulary = '\u0000'..'\uFFFE'; // All UNICODE characters except \uFFFF [and \u0000 to \u0002 used by ANTLR]
k = 3; // three characters of lookahead
testLiterals = false; // don't automatically test for literals
//defaultErrorHandler = true;
defaultErrorHandler = false;
codeGenMakeSwitchThreshold = 5; // Some optimizations
codeGenBitsetTestThreshold = 5;
}
{
/// <summary>
/// A <see cref="TokenStreamSelector"> for switching between this Lexer and the C#-only Lexer.
/// </summary>
private TokenStreamSelector selector_;
/// <summary>
/// A <see cref="TokenStreamSelector"> for switching between this Lexer and the C#-only Lexer.
/// </summary>
public TokenStreamSelector Selector
{
get { return selector_; }
set { selector_ = value; }
}
private FileInfo _fileinfo = null;
/// <summary>
/// Update _fileinfo member whenever filename changes.
/// </summary>
public override void setFilename(string f)
{
base.setFilename(f);
_fileinfo = new FileInfo(f);
}
/// <summary>
/// Ensures all tokens have access to the source file's details.
/// </summary>
protected override IToken makeToken(int t)
{
IToken result = base.makeToken(t);
CustomHiddenStreamToken customToken = result as CustomHiddenStreamToken;
if ( customToken != null )
{
customToken.File = _fileinfo;
}
return result;
}
public bool IsLetterCharacter(string s)
{
return ( (UnicodeCategory.LowercaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Ll
(UnicodeCategory.ModifierLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lm
(UnicodeCategory.OtherLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lo
(UnicodeCategory.TitlecaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lt
(UnicodeCategory.UppercaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lu
(UnicodeCategory.LetterNumber == Char.GetUnicodeCategory(s, 1)) //UNICODE class Nl
);
}
public bool IsIdentifierCharacter(string s)
{
return ( (UnicodeCategory.LowercaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Ll
(UnicodeCategory.ModifierLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lm
(UnicodeCategory.OtherLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lo
(UnicodeCategory.TitlecaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lt
(UnicodeCategory.UppercaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lu
(UnicodeCategory.LetterNumber == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Nl
(UnicodeCategory.NonSpacingMark == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Mn
(UnicodeCategory.SpacingCombiningMark == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Mc
(UnicodeCategory.DecimalDigitNumber == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Nd
(UnicodeCategory.ConnectorPunctuation == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Pc
(UnicodeCategory.Format == Char.GetUnicodeCategory(s, 1)) //UNICODE class Cf
);
}
public bool IsCombiningCharacter(string s)
{
return ( (UnicodeCategory.NonSpacingMark == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Mn
(UnicodeCategory.SpacingCombiningMark == Char.GetUnicodeCategory(s, 1)) //UNICODE class Mc
);
}
}
//======================================
// Start of Lexer Rules
//======================================
//======================================
// Section A.1.3 Comments
//
SL_COMMENT
: '/'
( '/' ( NOT_NEWLINE )*
// (NEWLINE)?
//
( ('\r' ( options { generateAmbigWarnings=false; } : '\n' )?
| '\n'
| '\u2028'
| '\u2029'
)
{ newline(); }
)?
{ selector_.pop(); }
| ~( '/' | '\r' | '\n' | '\u2028' | '\u2029' ) ( NOT_NEWLINE )*
{ $setType(PP_STRING); }
)
;
//======================================
// Section A.1.1 Line terminators
//
NEWLINE
: ( '\r' // MacOS-style newline
( options { generateAmbigWarnings=false; }
: '\n' // DOS/Windows style newline
)?
| '\n' // UNIX-style newline
| '\u2028' // UNICODE line separator
| '\u2029' // UNICODE paragraph separator
)
{ newline();
selector_.pop();
}
;
PP_STRING
: ~( '/' | '\r' | '\n' | '\u2028' | '\u2029' ) (NOT_NEWLINE)*
;
// undefine these inherited rules to remove a non-determinismn conflict with PP_STRING
//
protected LOG_NOT : ;
protected LOG_AND : ;
protected LOG_OR : ;
protected EQUAL : ;
protected NOT_EQUAL : ;
protected QUOTE : ;
protected OPEN_PAREN : ;
protected CLOSE_PAREN : ;

View File

@ -0,0 +1,265 @@
header
{
using System.IO;
using System.Globalization;
using TokenStreamSelector = antlr.TokenStreamSelector;
}
options
{
language = "CSharp";
namespace = "RusticiSoftware.Translator";
}
/*
[The "BSD licence"]
Copyright (c) 2002-2005 Kunle Odutola
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/// <summary>
/// A Preprocessor Lexer for the C# Language
/// </summary>
///
/// <remarks>
/// <para>
/// The Lexer defined below is designed to match and identify only tokens related to the
/// handling of preprocessing directives for the C# language in the source text. It is
/// designed to match the tokens that can occur after any of the following directives
/// (on the same line):
/// <list type="bullet">
/// <item>
/// <term>#define</term>
/// </item>
/// <item>
/// <term>#undefine</term>
/// </item>
/// <item>
/// <term>#if</term>
/// </item>
/// <item>
/// <term>#elif</term>
/// </item>
/// <item>
/// <term>#else</term>
/// </item>
/// <item>
/// <term>#endif</term>
/// </item>
/// <item>
/// <term>#line</term>
/// </item>
/// </list>
/// </para>
///
/// <para>
/// This preprocessing lexer is designed to work in tandem with the C# Lexer defined
/// in the CSharpLexer.g file. In order words, the lexing of all the input not handled
/// here is assumed to be handled by the other C# Lexer. This other C# Lexer may or may
/// not be aware of C# preprocessing directives. The co-operation is implemented via
/// ANTLR's TokenStreamSelector mechanism.
/// </para>
///
/// <para>
/// The operation of this C# preprocessing lexer is based on the "C# Language Specification"
/// as documented in the ECMA-334 standard dated December 2001.
/// </para>
///
/// <para>
/// History
/// </para>
///
/// <para>
/// 26-Jan-2003 kunle Derived this Lexer from the original combined grammar <br/>
/// 28-Jan-2003 kunle Retired this Lexer in favour of single-lexer approach <br/>
/// 25-Feb-2003 kunle Revived this Lexer after issues with single-lexer approach <br/>
/// </para>
///
*/
class CSharpPreprocessorLexer extends CSharpLexerBase;
options
{
importVocab = CSharpLexerBase;
exportVocab = CSharpPreprocess;
charVocabulary = '\u0000'..'\uFFFE'; // All UNICODE characters except \uFFFF [and \u0000 to \u0002 used by ANTLR]
k = 3; // three characters of lookahead
testLiterals = false; // don't automatically test for literals
//defaultErrorHandler = true;
defaultErrorHandler = false;
codeGenMakeSwitchThreshold = 5; // Some optimizations
codeGenBitsetTestThreshold = 5;
}
{
/// <summary>
/// A <see cref="TokenStreamSelector"> for switching between this Lexer and the C#-only Lexer.
/// </summary>
private TokenStreamSelector selector_;
/// <summary>
/// A <see cref="TokenStreamSelector"> for switching between this Lexer and the C#-only Lexer.
/// </summary>
public TokenStreamSelector Selector
{
get { return selector_; }
set { selector_ = value; }
}
private FileInfo _fileinfo = null;
/// <summary>
/// Update _fileinfo member whenever filename changes.
/// </summary>
public override void setFilename(string f)
{
base.setFilename(f);
_fileinfo = new FileInfo(f);
}
/// <summary>
/// Ensures all tokens have access to the source file's details.
/// </summary>
protected override IToken makeToken(int t)
{
IToken result = base.makeToken(t);
CustomHiddenStreamToken customToken = result as CustomHiddenStreamToken;
if ( customToken != null )
{
customToken.File = _fileinfo;
}
return result;
}
public bool IsLetterCharacter(string s)
{
return ( (UnicodeCategory.LowercaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Ll
(UnicodeCategory.ModifierLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lm
(UnicodeCategory.OtherLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lo
(UnicodeCategory.TitlecaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lt
(UnicodeCategory.UppercaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lu
(UnicodeCategory.LetterNumber == Char.GetUnicodeCategory(s, 1)) //UNICODE class Nl
);
}
public bool IsIdentifierCharacter(string s)
{
return ( (UnicodeCategory.LowercaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Ll
(UnicodeCategory.ModifierLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lm
(UnicodeCategory.OtherLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lo
(UnicodeCategory.TitlecaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lt
(UnicodeCategory.UppercaseLetter == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Lu
(UnicodeCategory.LetterNumber == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Nl
(UnicodeCategory.NonSpacingMark == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Mn
(UnicodeCategory.SpacingCombiningMark == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Mc
(UnicodeCategory.DecimalDigitNumber == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Nd
(UnicodeCategory.ConnectorPunctuation == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Pc
(UnicodeCategory.Format == Char.GetUnicodeCategory(s, 1)) //UNICODE class Cf
);
}
public bool IsCombiningCharacter(string s)
{
return ( (UnicodeCategory.NonSpacingMark == Char.GetUnicodeCategory(s, 1)) || //UNICODE class Mn
(UnicodeCategory.SpacingCombiningMark == Char.GetUnicodeCategory(s, 1)) //UNICODE class Mc
);
}
}
//======================================
// Start of Lexer Rules
//======================================
PP_IDENT
options { testLiterals = true; }
: ( '_'
| LETTER_CHARACTER
| { IsLetterCharacter(eseq.getText()) }? eseq:UNICODE_ESCAPE_SEQUENCE
)
( LETTER_CHARACTER
| DECIMAL_DIGIT_CHARACTER
| CONNECTING_CHARACTER
| COMBINING_CHARACTER
| FORMATTING_CHARACTER
| { IsIdentifierCharacter(eseq2.getText()) }? eseq2:UNICODE_ESCAPE_SEQUENCE
)*
;
PP_FILENAME
: '"'
( ~( '"' | '\r' | '\n' | '\u2028' | '\u2029' ) )*
'"'
;
PP_NUMBER
: (DECIMAL_DIGIT)+
;
//======================================
// Section A.1.3 Comments
//
SL_COMMENT
: "//" ( NOT_NEWLINE )*
// (NEWLINE)?
//
( ('\r' ( options { generateAmbigWarnings=false; } : '\n' )?
| '\n'
| '\u2028'
| '\u2029'
)
{ newline(); }
)?
{ selector_.pop(); }
;
//======================================
// Section A.1.1 Line terminators
//
NEWLINE
: ( '\r' // MacOS-style newline
( options { generateAmbigWarnings=false; }
: '\n' // DOS/Windows style newline
)?
| '\n' // UNIX-style newline
| '\u2028' // UNICODE line separator
| '\u2029' // UNICODE paragraph separator
)
{ newline();
selector_.pop();
}
;
WHITESPACE
: (NON_NEWLINE_WHITESPACE)+
;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,50 @@
/*
[The "BSD licence"]
Copyright (c) 2002-2005 Kunle Odutola
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace RusticiSoftware.Translator
{
using System;
/// <summary>
/// Bit masks for specifying valid CSharp syntax constructs in Parser productions.
/// </summary>
public enum CodeMaskEnums
{
PreprocessorDirectivesOnly = 0x0000,
UsingDirectives = 0x0001,
GlobalAttributes = 0x0002,
Attributes = 0x0004,
ClassMemberDeclarations = 0x0008,
StructMemberDeclarations = 0x0010,
InterfaceMemberDeclarations = 0x0020,
NamespaceMemberDeclarations = 0x0040,
Statements = 0x0080,
}
}

View File

@ -0,0 +1,146 @@
/*
[The "BSD licence"]
Copyright (c) 2002-2005 Kunle Odutola
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace RusticiSoftware.Translator
{
using System;
using FileInfo = System.IO.FileInfo;
using IToken = antlr.IToken;
using TokenCreator = antlr.TokenCreator;
using CommonHiddenStreamToken = antlr.CommonHiddenStreamToken;
/// <summary>
/// A sub-class of antlr.CommonHiddenStreamToken that can be used to track the
/// file from which a token was created.
///
/// Has an ugly but convenient dependency on the CSharpParser class. See
/// ToString() below.
/// </summary>
///
public class CustomHiddenStreamToken : CommonHiddenStreamToken
{
private string filename_;
private FileInfo fileinfo_;
protected CustomHiddenStreamToken() : base()
{
}
public CustomHiddenStreamToken(int t, string txt) : base(t, txt)
{
}
public CustomHiddenStreamToken(int t, string txt, FileInfo fileinfo) : base(t, txt)
{
fileinfo_ = fileinfo;
}
public CustomHiddenStreamToken(int t, string txt, FileInfo fileinfo, int line, int col) : base(t, txt)
{
this.fileinfo_ = fileinfo;
this.line = line;
this.col = col;
}
public override string getFilename()
{
if (fileinfo_ != null)
return fileinfo_.FullName;
else
return null;
}
override public string ToString()
{
return "[\"" + getText() + "\",<" + CSharpParser.tokenNames_[type_] + ">,line=" + line + ",col=" + col + "]";
}
/// <summary>
/// Sets the source file of the token
/// </summary>
///
public FileInfo File
{
[System.Diagnostics.DebuggerStepThrough]
get { return fileinfo_; }
[System.Diagnostics.DebuggerStepThrough]
set { fileinfo_ = value; }
}
/// <summary>
/// Gets or sets the contents of the hidden-before token stream.
/// </summary>
///
public CustomHiddenStreamToken HiddenBefore
{
[System.Diagnostics.DebuggerStepThrough]
get { return (CustomHiddenStreamToken) hiddenBefore; }
[System.Diagnostics.DebuggerStepThrough]
set { hiddenBefore = (CommonHiddenStreamToken) value; }
}
/// <summary>
/// Gets or sets the contents of the hidden-after token stream.
/// </summary>
///
public CustomHiddenStreamToken HiddenAfter
{
[System.Diagnostics.DebuggerStepThrough]
get { return (CustomHiddenStreamToken) hiddenAfter; }
[System.Diagnostics.DebuggerStepThrough]
set { hiddenAfter = (CommonHiddenStreamToken) value; }
}
public class CustomHiddenStreamTokenCreator : TokenCreator
{
public CustomHiddenStreamTokenCreator() {}
/// <summary>
/// Returns the fully qualified name of the Token type that this
/// class creates.
/// </summary>
public override string TokenTypeName
{
[System.Diagnostics.DebuggerStepThrough]
get
{
return typeof(CustomHiddenStreamToken).FullName;;
}
}
/// <summary>
/// Constructs a <see cref="Token"/> instance.
/// </summary>
public override IToken Create()
{
return new CustomHiddenStreamToken();
}
}
}
}

View File

@ -0,0 +1,291 @@
using System;
using System.Collections;
using System.Text;
namespace RusticiSoftware.Translator
{
// Implements a hierarchy of directories.
public class DirectoryHT : IDictionary
{
private DirectoryHT _parent = null;
private Hashtable leaves = new Hashtable();
private Hashtable children = new Hashtable();
public DirectoryHT(DirectoryHT p)
{
_parent = p;
}
public DirectoryHT()
: this(null)
{ }
public Hashtable Leaves
{
get { return leaves; }
}
// p is key to a sub directory
public DirectoryHT subDir(string p)
{
string[] components = p.Split(new char[] { '.' }, 2);
if (components.Length == 1)
{
return (DirectoryHT) children[components[0]];
}
else
{
DirectoryHT child = (DirectoryHT)children[components[0]];
return (child == null ? null : child.subDir(components[1]));
}
}
#region IDictionary Members
public void Add(object key, object value)
{
if (!(key is string))
throw new Exception("The method or operation is not implemented.");
string[] components = ((string)key).Split(new char[] { '.' }, 2);
if (components.Length == 1)
{
leaves[components[0]] = value;
}
else
{
if (children[components[0]] == null)
children[components[0]] = new DirectoryHT(this);
((DirectoryHT)children[components[0]]).Add(components[1], value);
}
}
public void Clear()
{
leaves.Clear();
children.Clear();
}
public bool Contains(object key)
{
if (!(key is string))
throw new Exception("The method or operation is not implemented.");
string[] components = ((String)key).Split(new char[] { '.' }, 2);
if (components.Length == 1)
{
return leaves.Contains(components[0]);
}
else
{
return ((DirectoryHT)children[components[0]]).Contains(components[1]);
}
}
public IDictionaryEnumerator GetEnumerator()
{
IDictionaryEnumerator[] des = new IDictionaryEnumerator[1 + children.Count];
string[] pres = new string[1 + children.Count];
int i = 1;
pres[0] = "";
des[0] = leaves.GetEnumerator();
foreach (DictionaryEntry de in children)
{
pres[i] = ((string)de.Key) + ".";
des[i] = ((DirectoryHT)de.Value).GetEnumerator();
i++;
}
return new DirectoryHTEnumerator(pres,des);
}
public bool IsFixedSize
{
get { return false; }
}
public bool IsReadOnly
{
get { return false; }
}
public ICollection Keys
{
get {
ArrayList keys = new ArrayList();
foreach (object k in leaves.Keys)
keys.Add(k);
foreach (DictionaryEntry de in children)
foreach (string k in ((DirectoryHT)de.Value).Keys)
keys.Add(de.Key + "." + k);
return keys;
}
}
public void Remove(object key)
{
if (!(key is string))
throw new Exception("The method or operation is not implemented.");
string[] components = ((string)key).Split(new char[] { '.' }, 2);
if (components.Length == 1)
{
leaves.Remove(components[0]);
}
else
{
((DirectoryHT)children[components[0]]).Remove(components[1]);
}
}
public ICollection Values
{
get {
ArrayList vals = new ArrayList();
foreach (object v in leaves.Values)
vals.Add(v);
foreach (DictionaryEntry de in children)
foreach (object v in ((DirectoryHT)de.Value).Values)
vals.Add(v);
return vals;
}
}
public object this[object key]
{
get
{
if (!(key is string))
throw new Exception("The method or operation is not implemented.");
string[] components = ((string)key).Split(new char[] { '.' }, 2);
if (components.Length == 1)
{
object val = leaves[components[0]];
return (val != null ? val : children[components[0]]);
}
else
{
DirectoryHT child = (DirectoryHT)children[components[0]];
return (child == null ? null : child[components[1]]);
}
}
set
{
Add(key, value);
}
}
#endregion
#region ICollection Members
public void CopyTo(Array array, int index)
{
throw new Exception("The method or operation is not implemented.");
}
public int Count
{
get
{
int count = leaves.Count;
foreach (DirectoryHT c in children.Values)
count += c.Count;
return count;
}
}
public bool IsSynchronized
{
get { throw new Exception("The method or operation is not implemented."); }
}
public object SyncRoot
{
get { throw new Exception("The method or operation is not implemented."); }
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
}
public class DirectoryHTEnumerator : IDictionaryEnumerator
{
private int _pos = 0;
private string[] _prefixes;
private IDictionaryEnumerator[] _enums;
public DirectoryHTEnumerator(string[] pres, IDictionaryEnumerator[] des)
{
_prefixes = pres;
_enums = des;
}
#region IDictionaryEnumerator Members
public DictionaryEntry Entry
{
get { return (DictionaryEntry)Current; }
}
public object Key
{
get { return Entry.Key; }
}
public object Value
{
get { return Entry.Value; }
}
#endregion
#region IEnumerator Members
public object Current
{
get { ValidateIndex();
return new DictionaryEntry(_prefixes[_pos] + (string)((DictionaryEntry)_enums[_pos].Current).Key,
((DictionaryEntry)_enums[_pos].Current).Value);
}
}
public bool MoveNext()
{
if (_pos >= _enums.Length)
return false;
while (_pos < _enums.Length && !_enums[_pos].MoveNext())
_pos++;
return _pos != _enums.Length;
}
public void Reset()
{
_pos = 0;
}
// Validate the enumeration index and throw an exception if the index is out of range.
private void ValidateIndex()
{
if (_pos < 0 || _pos >= _enums.Length)
throw new InvalidOperationException("Enumerator is before or after the collection.");
}
#endregion
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace RusticiSoftware.Translator
{
class CorruptCompilationUnit : Exception
{
ASTNode ast = null;
public CorruptCompilationUnit(ASTNode astIn)
{
ast = astIn;
}
}
class UnexpectedAST : Exception
{
ASTNode ast = null;
public UnexpectedAST(ASTNode astIn)
{
ast = astIn;
}
}
}

View File

@ -0,0 +1,778 @@
header {
using System.Collections;
using System.IO;
using System.Xml;
using TokenStreamHiddenTokenFilter = antlr.TokenStreamHiddenTokenFilter;
}
options {
language = "CSharp";
namespace = "RusticiSoftware.Translator";
}
/** Java 1.3 AST Pretty Printer
*
* Author: Kevin Glynn <kevin.glynn@scorm.com>
*
* This grammar is based on the java tree walker included in ANTLR examples
*
*/
class JavaPrettyPrinter extends TreeParser("RusticiSoftware.Translator.JavaTreeParser");
options {
importVocab = CSharpJava;
buildAST = false;
}
{
private int indentLevel = 0;
private const string INDENT = " ";
private bool indented = false;
private bool doIndent = true;
private const int MAX_TOKEN_TYPE=350; // imprecise but big enough
private TokenStreamHiddenTokenFilter filter;
private XmlTextWriter enumXmlWriter;
private ArrayList enumMembers = new ArrayList();
/** walk list of hidden tokens in order, printing them out */
public void dumpHidden(TextWriter w, antlr.IHiddenStreamToken t) {
for ( ; t!=null ; t=filter.getHiddenAfter(t) ) {
w.Write(t.getText());
}
}
/// <summary>
/// Prints the text of the specified AST node
/// </summary>
/// <param name="w">The output destination.</param>
/// <param name="node">The AST node to print.</param>
private void Print(TextWriter w, AST node)
{
Print(w, node, null);
}
/// <summary>
/// Prints the text
/// </summary>
/// <param name="w">The output destination.</param>
/// <param name="node">The AST node to print.</param>
private void Print(TextWriter w, string text)
{
Print(w, null, text);
}
/// <summary>
/// Prints the text of the AST node if it exists, then the text if it exists
/// </summary>
/// <param name="w">The output destination.</param>
/// <param name="node">The AST node to print.</param>
private void Print(TextWriter w, AST node, string text)
{
if (doIndent && !indented) {
PrintIndent(w);
}
if (node != null)
{
w.Write(node.getText());
}
if (text != null)
{
w.Write(text);
}
if (node != null)
{
// disable for now
// dumpHidden(w, ((antlr.CommonASTWithHiddenTokens)node).getHiddenAfter());
}
}
private void PrintNL(TextWriter w)
{
w.Write("\n"); // Should we take newline from environment?
if (doIndent) indented = false;
}
private void PrintNLIfReq(TextWriter w)
{
if (doIndent && indented)
PrintNL(w);
}
private void PrintIndent(TextWriter w)
{
for (int i = 0; i < indentLevel; i++) {
w.Write(INDENT);
}
if (doIndent) indented = true;
}
private void WriteStartEnum(AST node)
{
if (enumXmlWriter != null)
{
enumXmlWriter.WriteStartElement("enum");
enumXmlWriter.WriteAttributeString("id", node.getText());
}
}
private void WriteEndEnum()
{
if (enumXmlWriter != null)
{
enumXmlWriter.WriteEndElement();
}
}
private void WriteEnumMembers()
{
if (enumXmlWriter != null)
{
int num = 0;
foreach (AST node in enumMembers)
{
enumXmlWriter.WriteStartElement("member");
enumXmlWriter.WriteAttributeString("id", node.getText());
enumXmlWriter.WriteAttributeString("value", num.ToString());
enumXmlWriter.WriteEndElement();
num++;
}
}
}
// keving: Found this precedence table on the ANTLR site.
/** Encodes precedence of various operators; indexed by token type.
* If precedence[op1] > precedence[op2] then op1 should happen
* before op2;
*/
private static int[] precedence = new int[MAX_TOKEN_TYPE];
static JavaPrettyPrinter()
{
for (int i=0; i<precedence.Length; i++) {
// anything but these operators binds super tight
// for example METHOD_CALL binds tighter than PLUS
precedence[i] = int.MaxValue;
}
precedence[ASSIGN] = 1;
precedence[PLUS_ASSIGN] = 1;
precedence[MINUS_ASSIGN] = 1;
precedence[STAR_ASSIGN] = 1;
precedence[DIV_ASSIGN] = 1;
precedence[MOD_ASSIGN] = 1;
precedence[SHIFTR_ASSIGN] = 1;
//precedence[BSR_ASSIGN] = 1;
precedence[SHIFTL_ASSIGN] = 1;
precedence[BIN_AND_ASSIGN] =1;
precedence[BIN_XOR_ASSIGN] = 1;
precedence[BIN_OR_ASSIGN] = 1;
precedence[QUESTION] = 2;
precedence[LOG_OR] = 3;
precedence[LOG_AND] = 4;
precedence[BIN_OR] = 5;
precedence[BIN_XOR] = 6;
precedence[BIN_AND] = 7;
precedence[NOT_EQUAL] = 8;
precedence[EQUAL] = 8;
precedence[LTHAN] = 9;
precedence[GTHAN] = 9;
precedence[LTE] = 9;
precedence[GTE] = 9;
precedence[INSTANCEOF] = 9;
precedence[SHIFTL] = 10;
precedence[SHIFTR] = 10;
//precedence[BSR] = 10;
precedence[PLUS] = 11;
precedence[MINUS] = 11;
precedence[DIV] = 12;
precedence[MOD] = 12;
precedence[STAR] = 12;
precedence[INC] = 13;
precedence[DEC] = 13;
precedence[BIN_NOT] = 13;
precedence[LOG_NOT] = 13;
precedence[UNARY_MINUS] = 13;
precedence[UNARY_PLUS] = 13;
precedence[POST_INC_EXPR] = 14;
precedence[POST_DEC_EXPR] = 14;
}
// Compares precedence of op1 and op2.
// Returns -1 if op2 < op1
// 0 if op1 == op2
// 1 if op2 > op1
public static int comparePrecedence(AST op1, AST op2) {
// A gross hack for "instanceof" (no longer necessary with C# front end :-))
// if (op1.getText() == "instanceof")
// precedence[op1.Type] = 9;
// if (op2.getText() == "instanceof")
// precedence[op2.Type] = 9;
return Math.Sign(precedence[op2.Type]-precedence[op1.Type]);
}
}
compilationUnit [TextWriter w, XmlTextWriter enumXmlWriter, TokenStreamHiddenTokenFilter f]
{ filter = f; this.enumXmlWriter = enumXmlWriter; }
: #( COMPILATION_UNIT
packageDefinition[w]
useDefinitions[TextWriter.Null] // No output for uses
importDefinitions[w]
(typeDefinition[w])*
)
;
packageDefinition [TextWriter w]
: #( pkg:PACKAGE_DEF ({ Print(w, #pkg, " "); } identifier[w] { Print(w, ";"); PrintNL(w); })? )
;
useDefinitions [TextWriter w]
: #( USING_DIRECTIVES
(useDefinition[w])*
)
;
useDefinition [TextWriter w]
: #( USING_NAMESPACE_DIRECTIVE
identifier[w]
)
| #( USING_ALIAS_DIRECTIVE
alias:identifier[w]
pna:identifier[w]
)
;
importDefinitions [TextWriter w]
: #( IMPORTS
( { PrintNL(w); } (importDefinition[w])+ )?
) { PrintNL(w); }
;
importDefinition [TextWriter w]
: #( imp:IMPORT { Print(w, #imp, " "); }
identifier[w] { Print(w, ";"); PrintNL(w); }
)
;
typeDefinition [TextWriter w]
: #(cl:CLASS
modifiers[w]
id:IDENTIFIER { Print(w, "class "); Print(w, #id, " "); }
extendsClause[w]
implementsClause[w] { PrintNL(w); Print(w, "{"); PrintNL(w); indentLevel++; }
objBlock[w] { indentLevel--; Print(w, "}"); PrintNL(w); }
)
| #(INTERFACE
modifiers[w]
ifid:IDENTIFIER { Print(w, "interface "); Print(w, #ifid, " "); }
implementsClause[w] { PrintNL(w); Print(w, "{"); PrintNL(w); indentLevel++; }
interfaceBlock[w] { indentLevel--; Print(w, "}"); PrintNL(w); }
)
| #(ENUM
modifiers[w]
enmid:IDENTIFIER { Print(w, "enum "); Print(w, #enmid, " "); WriteStartEnum(#enmid); }
implementsClause[w] { PrintNL(w); Print(w, "{"); PrintNL(w); indentLevel++; }
enumBlock[w] { indentLevel--; Print(w, "}"); PrintNL(w); WriteEndEnum(); }
)
| #(ann:ANNOTATION
modifiers[w]
annid:IDENTIFIER { Print(w, "@interface "); Print(w, #annid, " "); PrintNL(w); Print(w, "{"); PrintNL(w); indentLevel++;}
objBlock[w] { indentLevel--; Print(w, "}"); PrintNL(w); }
)
;
typeSpec [TextWriter w]
: #(TYPE
( identifier[w]
| builtInType[w]
)
rankSpecifiers[w]
)
;
rankSpecifiers [TextWriter w]
: #( ARRAY_RANKS
( rankSpecifier[w]
)*
)
;
rankSpecifier [TextWriter w]
: #(ARRAY_RANK
( COMMA // Notice, we ignore dimensions.
)*
) { Print(w, "[]"); }
;
typeSpecArray [TextWriter w]
: #( ARRAY_DECLARATOR
typeSpecArray[w] { Print(w, "[]"); }
)
| type[w]
;
type [TextWriter w]
: identifier[w]
| builtInType[w]
;
builtInType [TextWriter w]
: tvo:VOID { Print(w, #tvo); }
| tbo:BOOL { Print(w, #tbo); }
| tst:STRING { Print(w, #tst); }
| tby:SBYTE { Print(w, #tby); }
| tch:"char" { Print(w, #tch); }
| tsh:"short" { Print(w, #tsh); }
| tin:"int" { Print(w, #tin); }
| tfl:"float" { Print(w, #tfl); }
| tlo:"long" { Print(w, #tlo); }
| tdo:"double" { Print(w, #tdo); }
| tuby: UBYTE { Print(w, #tuby); }
| tudec: DECIMAL { Print(w, #tudec); }
| tuint: UINT { Print(w, #tuint); }
| tulng: ULONG { Print(w, #tulng); }
| tush: USHORT { Print(w, #tush); }
| tb: BYTE { Print(w, #tb); }
;
modifiers [TextWriter w]
: #( MODIFIERS (modifier[w] { Print (w, " "); }
)* )
;
modifier [TextWriter w]
: mpr:"private" { Print(w, #mpr); }
| mpu:"public" { Print(w, #mpu); }
| mpt:"protected" { Print(w, #mpt); }
| mst:"static" { Print(w, #mst); }
| mtr:"transient" { Print(w, #mtr); }
| mfi:FINAL { Print(w, #mfi); }
| mab:ABSTRACT { Print(w, #mab); }
| mna:"native" { Print(w, #mna); }
| mth:"threadsafe" { Print(w, #mth); }
| msy:"synchronized" { Print(w, #msy); }
| mco:"const" { Print(w, #mco); }
| mvo:"volatile" { Print(w, #mvo); }
| msf:"strictfp" { Print(w, #msf); }
;
extendsClause [TextWriter w]
//OK, OK, really we can only extend 1 class, but the tree stores a list so ....
: #(EXTENDS_CLAUSE
( { Print(w, "extends "); } identifier[w] ({ Print(w, ", "); } identifier[w])* { Print(w, " "); } )?
)
;
implementsClause [TextWriter w]
: #(IMPLEMENTS_CLAUSE
( { Print(w, "implements "); } identifier[w] ({ Print(w, ", "); } identifier[w])* { Print(w, " "); } )?
)
;
interfaceBlock [TextWriter w]
: #( MEMBER_LIST
( methodDecl[w] { Print(w, ";"); PrintNL(w); }
| variableDef[w] { Print(w, ";"); PrintNL(w); }
| typeDefinition[w]
)*
)
;
objBlock [TextWriter w]
: #( MEMBER_LIST
(
( { PrintNL(w); } ctorDef[w]
| { PrintNL(w); } methodDef[w]
| variableDef[w] { Print(w, ";"); }
| { PrintNL(w); } typeDefinition[w]
| { PrintNL(w); } #(STATIC_CTOR_DECL { Print(w, "static"); PrintNL(w); }
slist[w] )
| { PrintNL(w); } #(INSTANCE_INIT
slist[w] )
) { PrintNLIfReq(w); }
)*
)
;
// This enumblock is from Java 1.3, in theory enums can have methods, nested enums, ....
enumBlock [TextWriter w]
{ enumMembers.Clear(); }
: #( MEMBER_LIST ( alt1:IDENTIFIER { Print(w, #alt1); enumMembers.Add(#alt1); } ( alts:IDENTIFIER { Print(w, ", "); Print(w, #alts); enumMembers.Add(#alts); } )* { PrintNL(w); WriteEnumMembers(); } )? )
;
ctorDef [TextWriter w]
: #(CTOR_DECL
modifiers[w]
methodHead[w]
(slist[w])?)
;
methodDecl [TextWriter w]
: #(METHOD_DECL
modifiers[w]
typeSpec[w] { Print(w, " "); }
methodHead[w])
;
methodDef [TextWriter w]
: #(METHOD_DECL
modifiers[w]
typeSpec[w] { Print(w, " "); }
methodHead[w]
(slist[w])?
)
;
variableDef [TextWriter w]
: #(FIELD_DECL
modifiers[w]
typeSpec[w] { Print(w, " "); }
variableDeclarator[w] ( {Print(w, ", "); } variableDeclarator[w])*
//varInitializer[w]
)
;
parameterDef [TextWriter w]
: #(PARAMETER_FIXED
typeSpec[w] { Print(w, " "); }
id:IDENTIFIER { Print(w, #id); }
)
| #(PARAMS typeSpec[w] { Print(w, "... "); } ids:IDENTIFIER { Print(w, #ids); } )
;
objectinitializer [TextWriter w]
: #(INSTANCE_INIT
slist[w] )
;
variableDeclarator [TextWriter w]
: #( VAR_DECLARATOR
id:IDENTIFIER { Print(w, #id); }
(varInitializer[w])?
)
// | LBRACK variableDeclarator[w] { Print(w, "[]"); }
;
varInitializer [TextWriter w]
: #(VAR_INIT { Print(w, " = "); }
initializer[w])
;
initializer [TextWriter w]
: expression[w]
| arrayInitializer[w]
;
arrayInitializer [TextWriter w]
: #(ARRAY_INIT
{ Print(w, "{"); }
( initializer[w] ( { Print(w, ", "); } initializer[w] )* )?
{ Print(w, "}"); }
)
;
methodHead [TextWriter w]
: id:IDENTIFIER { Print(w, #id); }
#( FORMAL_PARAMETER_LIST
{ Print(w, "("); }
( parameterDef[w] ( { Print(w, ", "); } parameterDef[w] )* )?
{ Print(w, ") "); }
)
( throwsClause[w])? { PrintNL(w); }
;
throwsClause [TextWriter w]
: #( th:"throws" { Print(w, #th, " "); }
( identifier[w] ( { Print(w, ", "); } identifier[w] )* )?
)
;
identifier [TextWriter w]
: id:IDENTIFIER { Print(w, #id); }
| #( DOT id1:IDENTIFIER { Print(w, #id1); Print(w, "."); } identifier[w] )
;
identifierStar [TextWriter w]
: id:IDENTIFIER { Print(w, #id); }
| st:STAR { Print(w, "."); Print(w, #st); }
| #( DOT id1:IDENTIFIER { Print(w, #id1); Print(w, "."); } identifier[w] )
;
slist [TextWriter w]
: #( BLOCK { Print(w, "{"); PrintNL(w); indentLevel++; } (stat[w])* { indentLevel--; Print(w, "}"); PrintNL(w); } )
| EMPTY_STMT { Print(w, ";"); PrintNL(w); }
;
// Like a slist[] but we don't indent. Appears in switch alternatives
statementList [TextWriter w]
: #( STMT_LIST (stat[w])* )
;
stat [TextWriter w]
:(
typeDefinition[w]
| variableDef[w] { Print(w, ";"); }
| #(EXPR_STMT expression[w]) { Print(w, ";"); }
| #(LABELED_STAT id:IDENTIFIER { Print(w, #id, ": "); } stat[w])
| #(lif:IF { Print(w, #lif, " ("); }
expression[w] { Print(w, ")"); PrintNL(w); }
stat[w]
( #(ELSE { Print(w, "else"); PrintNL(w); }
stat[w])
)?
)
| #( fo:"for" { Print(w, #fo, " ("); }
#(FOR_INIT (variableDef[w])* (expression[w] ( { Print(w, ", "); } expression[w])* )?) { Print(w, "; "); }
#(FOR_COND (expression[w])?) { Print(w, "; "); }
#(FOR_ITER (expression[w] ( { Print(w, ", "); } expression[w])* )?) { Print(w, ")"); PrintNL(w); }
stat[w]
)
| #(fe:"foreach" { Print(w, "for ("); }
variableDef[w] { Print(w, " : "); }
expression[w] { Print(w, ")"); PrintNL(w); }
stat[w]
)
| #(wh:"while" { Print(w, #wh, " ("); }
expression[w] { Print(w, ")"); PrintNL(w); }
stat[w]
)
| #(dd:"do" { Print(w, #dd); PrintNL(w); }
stat[w] { Print(w, "while ("); }
expression[w] { Print(w, ");"); }
)
| #(br:"break" { Print(w, #br); } ( { Print(w, " "); } IDENTIFIER)? { Print(w, ";"); } )
| #(co:"continue" { Print(w, #co); } ( { Print(w, " "); } IDENTIFIER)? { Print(w, ";"); } )
| #(re:"return" { Print(w, #re); } ( { Print(w, " "); } expression[w])? { Print(w, ";"); } )
| #(sw:"switch" { Print(w, #sw, " ("); }
expression[w] { Print(w, ")"); PrintNL(w); Print(w, "{"); indentLevel++; PrintNL(w); }
(caseGroup[w])*
) { indentLevel--; Print(w, "}"); }
| #(th:"throw" { Print(w, #th, " "); } expression[w] { Print(w, ";"); } )
| #(sy:"synchronized" { Print(w, #sy, " ("); }
expression[w] { Print(w, ")"); PrintNL(w); }
stat[w]
)
| tryBlock[w]
| slist[w] // nested SLIST (keving: should this be surrounded by braces?)
// uncomment to make assert JDK 1.4 stuff work
// | #("assert" expression[w] (expression[w])?)
| ctorCall[w] { Print(w, ";"); }
) { PrintNLIfReq(w); }
;
caseGroup [TextWriter w]
: #(SWITCH_SECTION (#(ca:"case" { Print(w, #ca, " "); }
expression[w]) { Print(w, ":"); PrintNL(w); indentLevel++; }
| de:"default" { Print(w, #de, ":"); PrintNL(w); indentLevel++; } )+
statementList[w] ) { indentLevel--; }
;
tryBlock [TextWriter w]
: #( tr:"try" { Print(w, #tr); PrintNL(w); }
slist[w]
(handler[w])*
(#(fi:"finally" { Print(w, #fi); PrintNL(w); }
slist[w]
))?
)
;
handler [TextWriter w]
: #( ca:"catch" { Print(w, #ca, " ("); }
( typeSpec[w] | variableDef[w]) { Print(w, ")"); PrintNL(w); }
slist[w]
)
;
elist [TextWriter w]
: #( EXPR_LIST
( expression[w] ( { Print(w, ", "); } expression[w] )* )?
)
;
expression [TextWriter w]
: #(EXPR expr[w])
;
expr [TextWriter w]
// QUESTION is right associative in C# and left-associative in Java, but we always parenthesize :-)
: #(QUESTION { Print(w, "( "); } expr[w] { Print(w, " ? "); } expr[w] { Print(w, " : "); } expr[w] { Print(w, " )"); }) // trinary operator
// binary operators...
| (ASSIGN|PLUS_ASSIGN|MINUS_ASSIGN|STAR_ASSIGN|DIV_ASSIGN
|MOD_ASSIGN|SHIFTR_ASSIGN|BSR_ASSIGN|SHIFTL_ASSIGN|BIN_AND_ASSIGN
|BIN_XOR_ASSIGN|BIN_OR_ASSIGN|LOG_OR|LOG_AND|BIN_OR|BIN_XOR|BIN_AND|NOT_EQUAL
|EQUAL|LTHAN|GTHAN|LTE|GTE|SHIFTL|SHIFTR|BSR|PLUS|MINUS|DIV|MOD|STAR|INSTANCEOF
)
{
AST op = #expr;
AST left = op.getFirstChild();
AST right = left.getNextSibling();
bool lp = false;
bool rp = false;
switch ( comparePrecedence(op,left) )
{
case -1 :
lp = true;
break;
case 0 :
if (op.Type == ASSIGN) lp = true; // ASSIGN/QUESTION is right associative in C#
break;
case 1:
break;
}
switch ( comparePrecedence(op,right) )
{
case -1:
rp = true;
break;
case 0:
if (op.Type != ASSIGN) rp = true; // All operators except ASSIGN/QUESTION are left associative in C#
break;
case 1:
break;
}
if ( lp ) Print(w, "(");
expr(left,w);
if ( lp ) Print(w, ")");
Print(w, " "+#op.getText()+" ");
if ( rp ) Print(w, "(");
expr(right,w); // manually invoke
if ( rp ) Print(w, ")");
}
| (INC|DEC|BIN_NOT|LOG_NOT|UNARY_MINUS|UNARY_PLUS)
{
AST op = #expr;
AST opnd = op.getFirstChild();
bool p = false;
if ( comparePrecedence(op,opnd) == -1) {
p = true;
}
Print(w, op.getText());
if ( p ) Print(w, "(");
expr(opnd, w);
if ( p ) Print(w, ")");
}
| #( POST_INC_EXPR expr[w] {Print(w, "++");} )
| #( POST_DEC_EXPR expr[w] {Print(w, "--");} )
| primaryExpression[w]
;
primaryExpression [TextWriter w]
: id:IDENTIFIER { Print(w, #id); }
| #( MEMBER_ACCESS_EXPR
( expr[w] { Print(w, "."); }
( did:IDENTIFIER { Print(w, #did); }
| arrayIndex[w]
| dth:"this" { Print(w, #dth); }
| dcl:"class" { Print(w, #dcl); }
| #( dne:"new" dni:IDENTIFIER { Print(w, #dne, " "); Print(w, dni, "("); } elist[w] { Print(w, ")"); } )
| dsu:"super" { Print(w, #dsu); }
)
| { Print(w, "."); } #(ARRAY_DECLARATOR typeSpecArray[w] { Print(w, "[]"); } )
| { Print(w, "."); } builtInType[w] (ddcl:"class" { Print(w, #ddcl); } )?
)
)
| arrayIndex[w]
| #(INVOCATION_EXPR primaryExpression[w] { Print(w, "("); } elist[w] { Print(w, ")"); })
| #(CAST_EXPR { Print(w, "(("); } typeSpec[w] { Print(w, ")("); } expr[w] { Print(w, "))"); } )
| newExpression[w]
| constant[w]
| su:"super" { Print(w, #su); }
| tr:"true" { Print(w, #tr); }
| fa:"false" { Print(w, #fa); }
| th:"this" { Print(w, #th); }
| nu:NULL { Print(w, #nu); }
| typeSpec[w] // type name used with instanceof
// javaTxt = text to be printed
// env = map from env-vars to AST
| javaWrapper[w]
;
javaWrapper [TextWriter w]
{ string javaTxt = ""; }
: #( JAVAWRAPPER javaTemplate:IDENTIFIER { javaTxt = javaTemplate.getText(); }
( { StringWriter sw = new StringWriter();
bool saveDoIndent = doIndent;
doIndent = false;
}
v:IDENTIFIER (expression[sw] | expr[sw] | elist[sw] )
{ javaTxt = javaTxt.Replace(#v.getText(), sw.ToString());
sw.Close();
doIndent = saveDoIndent; } )*
)
{ Print(w, javaTxt); }
;
ctorCall [TextWriter w]
: #( THIS { Print(w, "this("); } elist[w] { Print(w, ")"); })
| #( BASE { Print(w, "super("); } elist[w] { Print(w, ")"); })
;
arrayIndex [TextWriter w]
: #(ELEMENT_ACCESS_EXPR expr[w] { Print(w, "["); } elist[w] { Print(w, "]"); } )
;
constant [TextWriter w]
: it:INT_LITERAL { Print(w, #it); }
| ch:CHAR_LITERAL { Print(w, #ch); }
| st:STRING_LITERAL { Print(w, #st); }
| fl:NUM_FLOAT { Print(w, #fl); }
| db:DOUBLE_LITERAL { Print(w, #db); }
| flr:FLOAT_LITERAL { Print(w, #flr); }
| lo:LONG_LITERAL { Print(w, #lo); Print(w, "L"); }
| ul:ULONG_LITERAL { Print(w, #ul); Print(w, "L"); }
| de:DECIMAL_LITERAL { Print(w, #de, "/* Unsupported Decimal Literal */"); }
;
newExpression [TextWriter w]
: #( ne:OBJ_CREATE_EXPR { Print(w, #ne, " "); }
typeSpec[w]
{ Print(w, "("); } elist[w] { Print(w, ")"); }
( { PrintNL(w); indentLevel++; Print(w, "{"); PrintNL(w); indentLevel++; }
objBlock[w]
{ indentLevel--; Print(w, "}"); indentLevel--; PrintNL(w); }
)?
)
| #( na:ARRAY_CREATE_EXPR { Print(w, #na, " "); }
typeSpec[w]
( arrayInitializer[w] //rankSpecifiers[w]!
| { Print(w, "["); } elist[w] {Print(w, "]"); }
rankSpecifiers[w] ( arrayInitializer[w] )?
)
)
;
// newArrayDeclarator [TextWriter w]
// : #( ARRAY_DECLARATOR (newArrayDeclarator[w])? { Print(w, "["); }(expression[w])? { Print(w, "]"); })
// ;

View File

@ -0,0 +1,349 @@
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using T = RusticiSoftware.Translator.CSharpJavaTokenTypes; // We want easy access to the Token mappings
namespace RusticiSoftware.Translator
{
// Generate header specific to the tree-parser CSharp file
using System;
using TreeParser = antlr.TreeParser;
using Token = antlr.Token;
using IToken = antlr.IToken;
using AST = antlr.collections.AST;
using RecognitionException = antlr.RecognitionException;
using ANTLRException = antlr.ANTLRException;
using NoViableAltException = antlr.NoViableAltException;
using MismatchedTokenException = antlr.MismatchedTokenException;
using SemanticException = antlr.SemanticException;
using BitSet = antlr.collections.impl.BitSet;
using ASTPair = antlr.ASTPair;
using ASTFactory = antlr.ASTFactory;
using ASTArray = antlr.collections.impl.ASTArray;
/** Java 1.3 AST Tree Parser Base Class
*
* Author: Kevin Glynn <kevin.glynn@scorm.com>
*
* This contains utility routines for the java parser passes
*
*/
public class JavaTreeParser : antlr.TreeParser
{
protected string ClassInProcess; // Name of Class being processed
/// <summary>
/// Provides the storage for elements in the <c>Set</c>, stored as the key-set
/// of the <c>IDictionary</c> object. Set this object in the constructor
/// if you create your own <c>Set</c> class.
/// </summary>
protected Set<string> imports = null;
private static readonly string[] ScruTypeStrs = new string[] { "System.Int32",
"System.Int64",
"System.Char",
"System.Enum", };
protected void initialize()
{
// Here we can add imports that should always be present
imports = new Set<string>();
}
protected void addImport(string imp)
{
imports.Add(imp);
}
protected void addImport(string[] imps)
{
foreach (string imp in imps)
imports.Add(imp);
}
protected ASTNode GetImports()
{
ASTNode ret = (ASTNode)astFactory.make((AST)(ASTNode)astFactory.create(T.IMPORTS, "IMPORTS"));
String[] sortedImports = imports.AsArray();
Array.Sort(sortedImports);
foreach (string imp in sortedImports)
{
ret.addChild((ASTNode)astFactory.make((AST)(ASTNode)astFactory.create(T.IMPORT, "import"),
(AST)(ASTNode)astFactory.make((AST)(ASTNode)astFactory.create(T.IDENTIFIER, imp))));
}
return ret;
}
protected bool isValidScrutinee(ASTNode e)
{
bool ret = false;
TypeRep stype = e.DotNetType;
foreach (string t in ScruTypeStrs)
{
if (mkType(t).IsA(stype))
{
ret = true;
break;
}
}
return ret;
}
// getClassName, getPackageName assume a compilation unit looks like this:
// #( COMPILATION_UNIT,
// #(PACKAGE_DEF, <namespace>),
// #(USING_DIRECTIVES, (<imports>)*),
// #(class, MODIFIERS, <Class Name>, ....)
// )
public static String getClassName(ASTNode cuAST)
{
if (cuAST.Type == T.COMPILATION_UNIT)
{
AST cla = cuAST.getFirstChild().getNextSibling().getNextSibling().getNextSibling(); ;
return cla.getFirstChild().getNextSibling().getText();
}
else
{
throw new CorruptCompilationUnit(cuAST);
}
}
public static ArrayList getPackageName(ASTNode cuAST)
{
if (cuAST.Type == T.COMPILATION_UNIT)
{
ArrayList nsComps = new ArrayList();
AST ns = cuAST.getFirstChild().getFirstChild();
while (ns != null)
{
if (ns.Type == T.IDENTIFIER)
{
nsComps.Add(ns.getText());
break;
}
else
{ // Its a DOT node
ns = ns.getFirstChild();
nsComps.Add(ns.getText());
ns = ns.getNextSibling();
}
}
return nsComps;
}
else
{
throw new CorruptCompilationUnit(cuAST);
}
}
// Keep track of current use Path
protected Stack usePath = null;
protected string[] CollectUsePath()
{
int count = 0;
foreach (ArrayList l in usePath)
{
count += l.Count;
}
string[] ret = new string[count];
int i = 0;
foreach (ArrayList l in usePath)
{
foreach (string s in l)
{
ret[i] = s;
i++;
}
}
return ret;
}
public String idToString(AST idAST, string sep)
{
String res = "";
while (idAST != null)
{
if (idAST.Type == T.IDENTIFIER)
{
res += idAST.getText();
break;
}
else if (idAST.Type == T.DOT)
{
idAST = (ASTNode)idAST.getFirstChild();
res += idAST.getText() + sep;
idAST = (ASTNode)idAST.getNextSibling();
}
else
{
throw new UnexpectedAST((ASTNode)idAST);
}
}
return res;
}
public String idToString(AST idAST, char sep)
{
return idToString(idAST, sep.ToString());
}
public String idToString(AST idAST)
{
return idToString(idAST, ".");
}
// typeSpec [TextWriter w]
// : #(TYPE
// ( identifier[w]
// | builtInType[w]
// )
// rankSpecifiers[w]
// )
public String typeToString(AST tyAST, bool withQuotes)
{
String res = "";
if (withQuotes)
res = "\"";
if (tyAST != null && tyAST.Type == T.TYPE)
{
tyAST = tyAST.getFirstChild();
if (tyAST.Type == T.DOT)
res += idToString(tyAST);
else
res += tyAST.getText();
// Move to rankspecifiers
tyAST = tyAST.getNextSibling();
for (int i = 0; i < tyAST.getNumberOfChildren(); i++)
res += "[]";
}
else
{
throw new UnexpectedAST((ASTNode)tyAST);
}
if (withQuotes)
res += "\"";
return res;
}
public String typeToString(AST tyAST)
{
return typeToString(tyAST, true);
}
// Remove/Replace troublesome characters
protected String typeNameToId(String tName)
{
return tName.Replace(".", "").Replace("[","_").Replace("]","");
}
protected void prependStringToId(AST idAST, String str)
{
while (idAST.Type == T.DOT)
{
idAST = idAST.getFirstChild().getNextSibling();
}
idAST.setText(str + idAST.getText());
}
private readonly static string[] javaReserved = new string[] { "int", "protected", "package" };
protected void fixBrokenIds(ASTNode id)
{
if (id.Type == T.IDENTIFIER)
{
foreach (string k in javaReserved)
{
if (k == id.getText())
{
id.setText("__" + id.getText());
break;
}
}
}
}
protected string escapeJavaString(string rawStr)
{
StringBuilder buf = new StringBuilder(rawStr.Length * 2);
bool seenDQ = false;
foreach (char ch in rawStr)
{
switch (ch)
{
case '\\':
buf.Append("\\\\");
break;
case '"':
if (seenDQ)
buf.Append("\\\"");
seenDQ = !seenDQ;
break;
case '\'':
buf.Append("\\'");
break;
case '\b':
buf.Append("\\b");
break;
case '\t':
buf.Append("\\t");
break;
case '\n':
buf.Append("\\n");
break;
case '\f':
buf.Append("\\f");
break;
case '\r':
buf.Append("\\r");
break;
default:
buf.Append(ch);
break;
}
if (ch != '"')
seenDQ = false;
}
return buf.ToString();
}
protected Stack uPath = new Stack();
protected TypeRep mkType(string type)
{
return TypeRep.newInstance(type, uPath);
}
public ASTNode stripQualifier(ASTNode eAST)
{
if (eAST.Type == T.IDENTIFIER)
return (ASTNode) astFactory.dupTree(eAST);
else
return stripQualifier((ASTNode)eAST.getFirstChild().getNextSibling());
}
}
}

View File

@ -0,0 +1,590 @@
/*
[The "BSD licence"]
Copyright (c) 2002-2005 Kunle Odutola
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// bug(?) in DotGNU 0.6 - "using antlr" will workaround the problem.
#if __CSCC__
using antlr;
#endif
namespace RusticiSoftware.Translator
{
using System;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;
using FileInfo = System.IO.FileInfo;
using Directory = System.IO.Directory;
using FileStream = System.IO.FileStream;
using FileMode = System.IO.FileMode;
using FileAccess = System.IO.FileAccess;
using Stream = System.IO.Stream;
using StreamReader = System.IO.StreamReader;
using StringWriter = System.IO.StringWriter;
using StreamWriter = System.IO.StreamWriter;
using Path = System.IO.Path;
using DirectoryInfo = System.IO.DirectoryInfo;
using TextWriter = System.IO.TextWriter;
using File = System.IO.File;
using XmlTextWriter = System.Xml.XmlTextWriter;
using BaseAST = antlr.BaseAST;
using CommonAST = antlr.CommonAST;
using ASTFactory = antlr.ASTFactory;
using RecognitionException = antlr.RecognitionException;
using AST = antlr.collections.AST;
using ASTFrame = antlr.debug.misc.ASTFrame;
using IToken = antlr.IToken;
using TokenStream = antlr.TokenStream;
using TokenStreamSelector = antlr.TokenStreamSelector;
using TokenStreamHiddenTokenFilter = antlr.TokenStreamHiddenTokenFilter;
using IEnumerator = System.Collections.IEnumerator;
using System.Reflection;
class AppMain
{
private const string VERSION = "2008.1.0.6617";
public delegate void FileProcessor(string fName, Stream s);
internal static bool showTree = false;
internal static bool showCSharp = false;
internal static bool showJavaSyntax = false;
internal static bool showJava = false;
// keving: We don't use the flex scanner (at least for now) and we don't pretty print CSharp
// internal static bool printTree = false;
// internal static bool useFlexLexer = false;
internal static bool displayTokens = false;
internal static bool dumpXMLs = false;
internal static string outDir = ".";
internal static string cheatDir = "";
internal static ArrayList netRoot = new ArrayList();
internal static ArrayList exNetRoot = new ArrayList();
internal static ArrayList appRoot = new ArrayList();
internal static ArrayList exAppRoot = new ArrayList();
internal static ArrayList exclude = new ArrayList();
internal static DirectoryHT appEnv = new DirectoryHT(null);
internal static XmlTextWriter enumXmlWriter;
internal static string xmldumpDir = Path.Combine(".", "tmpXMLs");
internal static int verbosity = 0;
internal static TokenStreamHiddenTokenFilter filter;
internal static int numFilesSuccessfullyProcessed = 0;
internal static int numFilesProcessed = 0;
private static void showVersion()
{
Console.Out.WriteLine(Path.GetFileNameWithoutExtension(System.Environment.GetCommandLineArgs()[0]) + ": " + VERSION);
}
private static void showUsage()
{
Console.Out.WriteLine("Usage: " + Path.GetFileNameWithoutExtension(System.Environment.GetCommandLineArgs()[0]));
Console.Out.WriteLine(" [-help] (this usage message)");
Console.Out.WriteLine(" [-v] (be [somewhat more] verbose, repeat for more verbosity)");
Console.Out.WriteLine(" [-showtokens] (the lexer prints the tokenized input to the console)");
Console.Out.WriteLine(" [-showtree][-showcsharp] [-showjavasyntax] [-showjava] (show parse tree at various stages of the translation)");
Console.Out.WriteLine(" [-dumpxml] [-xmldir <directory to dump xml database>] (dump the translation repository as xml files)");
Console.Out.WriteLine(" [-dumpenums <enum xml file>] (create an xml file documenting enums)");
Console.Out.WriteLine(" [-odir <root of translated classes>]");
Console.Out.WriteLine(" [-cheatdir <root of translation 'cheat' files>]");
Console.Out.WriteLine(" [-netdir <root of .NET Framework Class Library translations>+] (can be multiple directories, separated by semi-colons)");
Console.Out.WriteLine(" [-exnetdir <directories/files to be excluded from translation repository>+] (can be multiple directories/files, separated by semi-colons)");
Console.Out.WriteLine(" [-appdir <root of C# application>]");
Console.Out.WriteLine(" [-exappdir <directories/files to be excluded from translation repository>+] (can be multiple directories/files, separated by semi-colons)");
Console.Out.WriteLine(" [-exclude <directories/files to be excluded from translation>+] (can be multiple directories/files, separated by semi-colons)");
Console.Out.WriteLine(" <directory or file name to be translated>");
Environment.Exit(0);
}
public static void Main(string[] args)
{
long startTime = DateTime.Now.Ticks;
// Use a try/catch block for parser exceptions
try
{
// if we have at least one command-line argument
if (args.Length > 0)
{
if (verbosity >= 2) Console.Error.WriteLine("Parsing...");
// for each directory/file specified on the command line
for (int i = 0; i < args.Length; i++)
{
if (args[i].ToLower().Equals("-showtree"))
{
showTree = true;
}
else if (args[i].ToLower().Equals("-showcsharp"))
{
showCSharp = true;
}
else if (args[i].ToLower().Equals("-showjava"))
{
showJava = true;
}
else if (args[i].ToLower().Equals("-showjavasyntax"))
{
showJavaSyntax = true;
}
else if (args[i].ToLower().Equals("-tokens"))
{
displayTokens = true;
}
else if (args[i].ToLower().Equals("-dumpxml"))
{
dumpXMLs = true;
}
else if (args[i].ToLower().Equals("-v"))
{
verbosity++;
// in verbose mode, echo back the command line (so if command line is generated by another tool that does not
// echo it, it can still be seen in the logs.
Console.Write(Assembly.GetExecutingAssembly().Location + " ");
foreach (string arg in args)
{
Console.Write(arg + " ");
}
Console.WriteLine(System.Environment.NewLine);
}
else if (args[i].ToLower().Equals("-help"))
{
showUsage();
}
else if (args[i].ToLower().Equals("-version"))
{
showVersion();
}
else if (args[i].ToLower().Equals("-odir") && i < (args.Length - 1))
{
i++;
outDir = args[i];
}
else if (args[i].ToLower().Equals("-dumpenums") && i < (args.Length - 1))
{
i++;
enumXmlWriter = new XmlTextWriter(args[i], System.Text.Encoding.UTF8);
enumXmlWriter.WriteStartElement("enums");
}
else if (args[i].ToLower().Equals("-cheatdir") && i < (args.Length - 1))
{
i++;
cheatDir = args[i];
}
else if (args[i].ToLower().Equals("-netdir") && i < (args.Length - 1))
{
i++;
string[] argDirs = args[i].Split(';');
for (int j = 0; j < argDirs.Length; j++)
argDirs[j] = Path.GetFullPath(argDirs[j]).ToLower();
netRoot.AddRange(argDirs);
}
else if (args[i].ToLower().Equals("-exnetdir") && i < (args.Length - 1))
{
i++;
string[] argDirs = args[i].Split(';');
for (int j = 0; j < argDirs.Length; j++)
argDirs[j] = Path.GetFullPath(argDirs[j]).ToLower();
exNetRoot.AddRange(argDirs);
}
else if (args[i].ToLower().Equals("-appdir") && i < (args.Length - 1))
{
i++;
string[] argDirs = args[i].Split(';');
for (int j = 0; j < argDirs.Length; j++)
argDirs[j] = Path.GetFullPath(argDirs[j]).ToLower();
appRoot.AddRange(argDirs);
}
else if (args[i].ToLower().Equals("-exappdir") && i < (args.Length - 1))
{
i++;
string[] argDirs = args[i].Split(';');
for (int j = 0; j < argDirs.Length; j++)
argDirs[j] = Path.GetFullPath(argDirs[j]).ToLower();
exAppRoot.AddRange(argDirs);
}
else if (args[i].ToLower().Equals("-exclude") && i < (args.Length - 1))
{
i++;
string[] argDirs = args[i].Split(';');
for (int j = 0; j < argDirs.Length; j++)
argDirs[j] = Path.GetFullPath(argDirs[j]).ToLower();
exclude.AddRange(argDirs);
}
else if (args[i].ToLower().Equals("-xmldir") && i < (args.Length - 1))
{
i++;
xmldumpDir = args[i];
}
else
{
// Final argument is translation target
// Load .Net templates
numFilesSuccessfullyProcessed = 0;
numFilesProcessed = 0;
foreach (string r in netRoot)
doFile(new FileInfo(r), ".xml", addNetTranslation, exNetRoot);
Console.Out.WriteLine(String.Format("\nFound {0} .Net template files ({1} processed successfully)\n", numFilesProcessed, numFilesSuccessfullyProcessed));
// Load Application Class Signatures (i.e. generate templates)
if (appRoot.Count == 0)
// By default translation target is application root
appRoot.Add(args[i]);
numFilesSuccessfullyProcessed = 0;
numFilesProcessed = 0;
foreach (string r in appRoot)
doFile(new FileInfo(r), ".cs", addAppSigTranslation, exAppRoot); // parse it
Console.Out.WriteLine(String.Format("\nFound {0} cs files in the application ({1} processed successfully)\n", numFilesProcessed, numFilesSuccessfullyProcessed));
if (dumpXMLs)
{
// Get package name and convert to directory name
foreach (DictionaryEntry de in appEnv)
{
String xmlFName = Path.Combine(xmldumpDir,
((string)de.Key).Replace('.', Path.DirectorySeparatorChar) + ".xml");
String xmlFDir = Path.GetDirectoryName(xmlFName);
if (!Directory.Exists(xmlFDir))
{
Directory.CreateDirectory(xmlFDir);
}
XmlSerializer s = new XmlSerializer(de.Value.GetType());
TextWriter w = new StreamWriter(xmlFName);
s.Serialize(w, de.Value);
w.Close();
}
}
numFilesSuccessfullyProcessed = 0;
numFilesProcessed = 0;
doFile(new FileInfo(args[i]), ".cs", translateFile, exclude); // parse it
if (numFilesProcessed == 0) {
Console.Out.WriteLine("\nWARNING: Did not find any cs files to translate\n");
}
else {
Console.Out.WriteLine(String.Format("\nTranslated {0} cs files ({1} processed somewhat successfully)\n", numFilesProcessed, numFilesSuccessfullyProcessed));
}
if (enumXmlWriter != null)
{
enumXmlWriter.WriteEndElement();
enumXmlWriter.Close();
}
}
}
}
else
{
showUsage();
}
}
catch (System.Exception e)
{
Console.Error.WriteLine("exception: " + e);
Console.Error.WriteLine(e.StackTrace); // so we can get stack trace
}
double elapsedTime = ((DateTime.Now.Ticks - startTime) / TimeSpan.TicksPerMillisecond) / 1000.0;
if (verbosity >= 1)
{
System.Console.Out.WriteLine("");
System.Console.Out.WriteLine("");
System.Console.Out.WriteLine("Total run time was {0} seconds.", elapsedTime);
}
}
// Call processFile on all files below f that have the given extension
public static void doFile(FileInfo f, string ext, FileProcessor processFile, ArrayList excludes)
{
// If this is a directory, walk each file/dir in that directory
if (!excludes.Contains(Path.GetFullPath(f.FullName).ToLower()))
{
if (Directory.Exists(f.FullName))
{
string[] files = Directory.GetFileSystemEntries(f.FullName);
for (int i = 0; i < files.Length; i++)
doFile(new FileInfo(Path.Combine(f.FullName, files[i])), ext, processFile, excludes);
}
else if ((f.Name.Length > ext.Length) && f.Name.Substring(f.Name.Length - ext.Length).Equals(ext))
{
FileStream fs = null;
if (verbosity >= 2) Console.WriteLine(" " + f.FullName);
try
{
fs = new FileStream(f.FullName, FileMode.Open, FileAccess.Read);
processFile(f.FullName, fs);
numFilesSuccessfullyProcessed++;
}
catch (Exception e)
{
Console.Error.WriteLine("\nCannot process file: " + f.FullName);
Console.Error.WriteLine("exception: " + e);
}
finally
{
if (fs != null) fs.Close();
numFilesProcessed++;
}
}
}
}
public static ASTNode parseFile(string f, Stream s)
{
ASTNode ret = null;
try
{
// Define a selector that can switch from the C# codelexer to the C# preprocessor lexer
TokenStreamSelector selector = new TokenStreamSelector();
TokenStream lexer;
CSharpLexer antlrLexer = new CSharpLexer(new StreamReader(s));
antlrLexer.Selector = selector;
antlrLexer.setFilename(f);
CSharpPreprocessorLexer preproLexer = new CSharpPreprocessorLexer(antlrLexer.getInputState());
preproLexer.Selector = selector;
CSharpPreprocessorHooverLexer hooverLexer = new CSharpPreprocessorHooverLexer(antlrLexer.getInputState());
hooverLexer.Selector = selector;
// use the special token object class
antlrLexer.setTokenCreator(new CustomHiddenStreamToken.CustomHiddenStreamTokenCreator());
antlrLexer.setTabSize(1);
preproLexer.setTokenCreator(new CustomHiddenStreamToken.CustomHiddenStreamTokenCreator());
preproLexer.setTabSize(1);
hooverLexer.setTokenCreator(new CustomHiddenStreamToken.CustomHiddenStreamTokenCreator());
hooverLexer.setTabSize(1);
// notify selector about various lexers; name them for convenient reference later
selector.addInputStream(antlrLexer, "codeLexer");
selector.addInputStream(preproLexer, "directivesLexer");
selector.addInputStream(hooverLexer, "hooverLexer");
selector.select("codeLexer"); // start with main the CSharp code lexer
lexer = selector;
// create the stream filter; hide WS and SL_COMMENT
if (displayTokens)
filter = new TokenStreamHiddenTokenFilter(new LoggingTokenStream(lexer));
else
filter = new TokenStreamHiddenTokenFilter(lexer);
filter.hide(CSharpJavaTokenTypes.WHITESPACE);
filter.hide(CSharpJavaTokenTypes.NEWLINE);
filter.hide(CSharpJavaTokenTypes.ML_COMMENT);
filter.hide(CSharpJavaTokenTypes.SL_COMMENT);
// Create a parser that reads from the scanner
CSharpParser parser = new CSharpParser(filter);
// create trees that copy hidden tokens into tree also
parser.setASTNodeClass(typeof(ASTNode).FullName);
parser.setASTFactory(new ASTNodeFactory());
CSharpParser.initializeASTFactory(parser.getASTFactory());
parser.setFilename(f);
//parser.getASTFactory().setASTNodeCreator(new ASTNode.ASTNodeCreator());
// start parsing at the compilationUnit rule
long startTime = DateTime.Now.Ticks;
parser.compilationUnit();
double elapsedTime = ((DateTime.Now.Ticks - startTime) / TimeSpan.TicksPerMillisecond) / 1000.0;
if (verbosity >= 2) System.Console.Out.WriteLine("Parsed {0} in: {1} seconds.", f, elapsedTime);
BaseAST.setVerboseStringConversion(true, parser.getTokenNames());
ret = (ASTNode)parser.getAST();
}
catch (System.Exception e)
{
Console.Error.WriteLine("parser exception: " + e);
Console.Error.WriteLine(e.StackTrace); // so we can get stack trace
}
return ret;
}
// Here's where we do the real work...
public static void addNetTranslation(string fullName, Stream s)
{
TypeRepTemplate t = TypeRepTemplate.newInstance(s);
appEnv[t.TypeName] = t;
}
// Here's where we do the real work...
public static void addAppSigTranslation(string fullName, Stream s)
{
string f = Path.GetFileName(fullName);
ASTNode t = parseFile(f, s);
if (t != null)
{
// A prescan of all files to build an environment mapping qualified name to typereptemplate
CSharpEnvBuilder envBuilder = new CSharpEnvBuilder();
envBuilder.compilationUnit(t, null, appEnv);
}
}
// Here's where we do the real work...
public static void translateFile(string fullName, Stream s)
{
string f = Path.GetFileName(fullName);
ASTNode t = parseFile(f, s);
if (t != null)
{
if (showTree)
{
ASTNode r = (ASTNode)new ASTNodeFactory().create(0, "AST ROOT");
r.setFirstChild(t);
ASTFrame frame = new ASTFrame("C# AST for file [" + f + "]", r);
frame.ShowDialog();
//frame.Visible = true;
// System.out.println(t.toStringList());
}
ASTNode r1 = (ASTNode)new ASTNodeFactory().create(0, "AST ROOT");
r1.setFirstChild(t);
ASTFrame frame1 = new ASTFrame("C# AST for file [" + f + "]", r1);
if (showCSharp)
frame1.ShowDialog();
CSharpTranslator transformer = new CSharpTranslator();
transformer.setASTNodeClass(typeof(ASTNode).FullName);
transformer.setASTFactory(new ASTNodeFactory());
CSharpTranslator.initializeASTFactory(transformer.getASTFactory());
long startTime = DateTime.Now.Ticks;
transformer.compilationUnit(t, null);
//BaseAST.setVerboseStringConversion(true, tokenNames);
ASTNode r2 = (ASTNode)new ASTNodeFactory().create(0, "AST ROOT");
r2.setFirstChild(transformer.getAST());
ASTFrame frame2 = new ASTFrame("Java syntax AST for file [" + f + "]", r2);
if (showJavaSyntax)
frame2.ShowDialog();
// Take each java compilation unit (each class defn) and write it to the appropriate file
IEnumerator enumCU = transformer.getAST().findAllPartial((ASTNode)transformer.getASTFactory().create(CSharpParser.COMPILATION_UNIT));
while (enumCU.MoveNext())
{
ASTNode javaCU = (ASTNode)enumCU.Current;
// Extract class/interface name
String claName = JavaTreeParser.getClassName(javaCU);
// Get package name and convert to directory name
String nsDir = "";
foreach (String nsc in JavaTreeParser.getPackageName(javaCU))
{
nsDir = Path.Combine(nsDir, nsc);
}
// Build destination filename for this class
String fName = Path.Combine(Path.Combine(outDir, nsDir), claName + ".java");
if (cheatDir != "")
{
String cheatFile = Path.Combine(cheatDir, Path.Combine(nsDir, claName + ".java"));
if (File.Exists(cheatFile))
{
// the old switcheroo
File.Copy(cheatFile, fName,true);
continue;
}
String ignoreMarker = Path.Combine(cheatDir, Path.Combine(nsDir, claName + ".none"));
if (File.Exists(ignoreMarker))
{
// Don't generate this class
continue;
}
}
NetTranslator netTx = new NetTranslator();
netTx.setASTNodeClass(typeof(ASTNode).FullName);
netTx.setASTFactory(new ASTNodeFactory());
NetTranslator.initializeASTFactory(netTx.getASTFactory());
netTx.compilationUnit(javaCU, null, appEnv);
//BaseAST.setVerboseStringConversion(true, tokenNames);
ASTNode r3 = (ASTNode)new ASTNodeFactory().create(0, "AST ROOT");
r3.setFirstChild(netTx.getAST());
ASTFrame frame3 = new ASTFrame("Java AST for file [" + f + "]", r3);
if (showJava)
frame3.ShowDialog();
Console.WriteLine(fName);
String fDir = Path.GetDirectoryName(fName);
if (!Directory.Exists(fDir))
{
Directory.CreateDirectory(fDir);
}
FileInfo outF = new FileInfo(fName);
StreamWriter w = new StreamWriter(outF.Create());
JavaPrettyPrinter writer = new JavaPrettyPrinter();
writer.compilationUnit(netTx.getAST(), w, enumXmlWriter, filter);
w.Close();
}
double elapsedTime = ((DateTime.Now.Ticks - startTime) / TimeSpan.TicksPerMillisecond) / 1000.0;
//System.Console.Out.WriteLine(writer.ToString());
System.Console.Out.WriteLine("");
System.Console.Out.WriteLine("");
System.Console.Out.WriteLine("Pretty-printed {0} in: {1} seconds.", f, elapsedTime);
}
}
}
class LoggingTokenStream : TokenStream
{
TokenStream source;
public LoggingTokenStream(TokenStream source)
{
this.source = source;
}
public IToken nextToken()
{
IToken tok = source.nextToken();
if (tok != null)
Console.Out.WriteLine(tok.ToString());
return tok;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,44 @@
using System;
using System.IO;
using System.Collections;
namespace RusticiSoftware.Translator
{
// Generate header specific to the tree-parser CSharp file
/** Net Translator Base Class
* Really these routines are part of the NetTranslator, but they are pure C# and it is easier
* to develop them in a C# class in VS
*
* Author: Kevin Glynn <kevin.glynn@scorm.com>
*
*
*/
public class NetTranslatorBase : JavaTreeParser
{
protected SymbolTable symtab = new SymbolTable();
//protected TypeRep mkType(string type, int rank)
//{
// return TypeRep.newInstance(type, rank, uPath);
//}
public void ExtendSymTabFromNS(string ns)
{
ArrayList EmptyPath = new ArrayList();
DirectoryHT env = (DirectoryHT) TypeRep.TypeEnv[ns];
if (env != null)
{
// Note GetFiles(dir, "*.xml") won't work because of odd search behaviour with 3 letter extensions ....
foreach (string p in env.Leaves.Keys)
{
TypeRep t = TypeRep.newInstance(ns + "." + p, EmptyPath);
symtab.Add(p, t);
}
}
}
}
}

View File

@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Translator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Translator")]
[assembly: AssemblyCopyright("Copyright © 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9fae79e2-bd65-4750-b6fc-cee9b2389420")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,67 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace RusticiSoftware.Translator
{
public class Set<T> : IEnumerable
{
///
/// Provides the storage for elements in the Set, stored as the key-set
/// of a Dictionary object.
///
protected Dictionary<T, object> setD = null;
private readonly static object PlaceholderObject = new object();
public Set()
{
setD = new Dictionary<T,object>();
}
public IEnumerator GetEnumerator()
{
return setD.Keys.GetEnumerator();
}
///
/// The placeholder object used as the value for the Dictionary object.
///
/// There is a single instance of this object globally, used for all Sets.
///
protected object Placeholder
{
get { return PlaceholderObject; }
}
///
/// Adds the specified element to this set if it is not already present.
/// o: The object to add to the set.
/// returns true if the object was added, false if it was already present.
public bool Add(T s)
{
if (setD.ContainsKey(s))
return false;
else
{
//The object we are adding is just a placeholder. The thing we are
//really concerned with is 'o', the key.
setD[s] = PlaceholderObject;
return true;
}
}
public T[] AsArray()
{
ICollection keys = setD.Keys;
T[] retArr = new T[keys.Count];
keys.CopyTo(retArr, 0);
return retArr;
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections;
using System.Text;
// This is just a holder for parts of a type signature that we need to pass
// from production to production
namespace RusticiSoftware.Translator
{
public class SigEnv
{
public SigEnv()
{ }
public ArrayList Properties = new ArrayList();
public ArrayList Methods = new ArrayList();
public ArrayList Constructors = new ArrayList();
public ArrayList Fields = new ArrayList();
public ArrayList Casts = new ArrayList();
}
}

View File

@ -0,0 +1,80 @@
using System;
using System.Collections;
using System.Text;
namespace RusticiSoftware.Translator
{
// Holds our symbol table, a multi-level map from identifiers (string) to their type (string)
public class SymbolTable
{
// A stack of hashtables
private Stack _outer = null;
public SymbolTable()
{
_outer = new Stack();
PushLevel();
}
public void PushLevel()
{
_outer.Push(new Hashtable());
}
public void PopLevel()
{
_outer.Pop();
}
// keving: Can we try to add the same var twice??
public void Add(string v, TypeRep t)
{
((Hashtable)_outer.Peek())[v] = t;
}
public TypeRep Get(string v)
{
//TypeRep unknownType;
foreach (Hashtable d in _outer)
{
if (d.Contains(v))
return (TypeRep) d[v];
}
return null;
}
public TypeRep this[string v]
{
get
{
return Get(v);
}
set
{
Add(v, value);
}
}
public void Dump()
{
string INDENT = "";
Console.WriteLine("symbol Table Dump");
foreach (Hashtable d in _outer)
{
foreach (string v in d.Keys)
{
Console.WriteLine(INDENT + v + ": " + ((TypeRep)d[v]).TypeName);
}
INDENT += " ";
}
Console.WriteLine("");
}
}
}

View File

@ -0,0 +1,424 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace RusticiSoftware.Translator
{
public abstract class TranslationBase
{
protected TranslationBase()
{
}
}
public class ParamRepTemplate : TranslationBase
{
public string Type;
public string Name;
public ParamRepTemplate() : base()
{}
public ParamRepTemplate(string t, string a)
{
Type = t;
Name = a;
}
}
public class ConstructorRepTemplate : TranslationBase
{
[XmlArrayItem("Import")]
public string[] Imports;
[XmlArrayItem("Param")]
public ParamRepTemplate[] Params;
public string Java;
public ConstructorRepTemplate()
: base()
{
Imports = new string[0];
Params = new ParamRepTemplate[0];
}
public ConstructorRepTemplate(ParamRepTemplate[] pars)
: base()
{
Imports = new string[0];
Params = pars;
}
public ConstructorRepTemplate(ParamRepTemplate[] pars, string[] imps, string javaRep)
: base()
{
Imports = imps;
Params = pars;
Java = javaRep;
}
}
public class MethodRepTemplate : ConstructorRepTemplate
{
public string Return;
public string Name;
public MethodRepTemplate()
{ }
public MethodRepTemplate(string retType, string methodName,
ParamRepTemplate[] pars, string[] imps, string javaRep)
: base(pars, imps, javaRep)
{
Return = retType;
Name = methodName;
}
public MethodRepTemplate(string retType, string methodName,
ParamRepTemplate[] pars)
: this(retType, methodName, pars, new string[0], null)
{
}
}
public class CastRepTemplate : TranslationBase
{
[XmlArrayItem("Import")]
public string[] Imports;
public string From;
public string To;
public string Java;
public CastRepTemplate()
: base()
{
Imports = new string[0];
}
public CastRepTemplate(string fType, string tType,
string[] imps, string java)
{
From = fType;
To = tType;
Imports = imps;
Java = java;
}
public CastRepTemplate(string fType, string tType)
:
this(fType, tType, new string[0], null)
{
}
}
public class FieldRepTemplate : TranslationBase
{
[XmlArrayItem("Import")]
public string[] Imports;
public string Type;
public string Name;
public string Get;
public FieldRepTemplate()
: base()
{
Imports = new string[0];
}
public FieldRepTemplate(string fType, string fName,
string[] imps, string javaGet)
{
Type = fType;
Name = fName;
Imports = imps;
Get = javaGet;
}
public FieldRepTemplate(string fType, string fName)
:
this(fType, fName, new string[0], null)
{
}
}
public class PropRepTemplate : FieldRepTemplate
{
public string Set;
public PropRepTemplate()
: base()
{ }
public PropRepTemplate(string fType, string fName,
string[] imps, string javaGet, string javaSet)
: base(fType, fName, imps, javaGet)
{
Set = javaSet;
}
public PropRepTemplate(string fType, string fName) : this(fType, fName, new string[0], null, null)
{
}
}
// Base Template for classes, interfaces, enums, etc.
[Serializable]
public abstract class TypeRepTemplate : TranslationBase
{
// Fully qualified Type Name
[XmlElementAttribute("Name")]
public string TypeName;
// Java equivalent of this type (valid given imports)
public string Java;
// Path to use when resolving types
[XmlArrayItem("Namespace")]
public string[] NamespacePath;
[XmlArrayItem("Type")]
public string[] Inherits;
[XmlArrayItem("Import")]
public string[] Imports;
[XmlArrayItem("Method")]
public MethodRepTemplate[] Methods;
[XmlArrayItem("Property")]
public PropRepTemplate[] Properties;
[XmlArrayItem("Field")]
public FieldRepTemplate[] Fields;
[XmlArrayItem("Cast")]
public CastRepTemplate[] Casts;
public TypeRepTemplate() : base()
{
// If these fields are not specified then these will be zero element arrays (rather than null)
NamespacePath = new string[0];
Inherits = new string[0];
Imports = new string[0];
Methods = new MethodRepTemplate[0];
Properties = new PropRepTemplate[0];
Fields = new FieldRepTemplate[0];
Casts = new CastRepTemplate[0];
}
protected TypeRepTemplate(string typeName)
: this()
{
TypeName = typeName;
}
protected TypeRepTemplate(string tName, string[] usePath, string[] inherits,
MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs,
CastRepTemplate[] cs,
string[] imps, string javaTemplate)
: base()
{
TypeName = tName;
NamespacePath = usePath;
Inherits = inherits;
Methods = ms;
Properties = ps;
Fields = fs;
Imports = imps;
Casts = cs;
Java = javaTemplate;
}
private static object Deserialize(Stream fs, System.Type t)
{
object o = null;
XmlSerializer serializer = new XmlSerializer(t);
o = serializer.Deserialize(fs);
return o;
}
private static TypeRepTemplate Deserialize(Stream s)
{
TypeRepTemplate ret = null;
XmlTextReader reader = new XmlTextReader(s);
string typeType = null; // class, interface, enum, etc.
bool found = false;
try
{
while (reader.Read() && !found)
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.LocalName)
{
case "Class":
typeType = "RusticiSoftware.Translator.ClassRepTemplate";
break;
case "Interface":
typeType = "RusticiSoftware.Translator.InterfaceRepTemplate";
break;
case "Enum":
typeType = "RusticiSoftware.Translator.EnumRepTemplate";
break;
default:
typeType = "UnknownType";
break;
}
found = true;
}
}
s.Seek(0, SeekOrigin.Begin);
ret = (TypeRepTemplate)Deserialize(s, System.Type.GetType(typeType));
}
catch (Exception e)
{
Console.WriteLine("WARNING -- (Deserialize) " + e.Message);
}
return ret;
}
public static TypeRepTemplate newInstance(Stream s)
{
return (TypeRepTemplate)Deserialize(s);
}
// Useful because it builds either an empty ClassRep or InterfaceRep or ...
public abstract TypeRep mkEmptyRep();
}
[XmlType("Class")]
public class ClassRepTemplate : TypeRepTemplate
{
[XmlArrayItem("Constructor")]
public ConstructorRepTemplate[] Constructors = new ConstructorRepTemplate[0];
public ClassRepTemplate()
{
}
public ClassRepTemplate(string typeName) : base(typeName)
{
}
public ClassRepTemplate(string tName, string[] usePath, string[] inherits,
ConstructorRepTemplate[] cs,
MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs,
CastRepTemplate[] cts,
string[] imps, string javaTemplate)
: base(tName, usePath, inherits, ms, ps, fs, cts, imps, javaTemplate)
{
Constructors = cs;
}
public ClassRepTemplate(string tName, string[] usePath, string[] inherits,
ConstructorRepTemplate[] cs,
MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs, CastRepTemplate[] cts)
: base(tName, usePath, inherits, ms, ps, fs, cts, new String[0], null)
{
Constructors = cs;
}
public override TypeRep mkEmptyRep()
{
return new ClassRep();
}
}
[XmlType("Interface")]
public class InterfaceRepTemplate : TypeRepTemplate
{
public InterfaceRepTemplate()
{ }
public InterfaceRepTemplate(string typeName)
: base(typeName)
{
}
public InterfaceRepTemplate(string tName, string[] usePath, string[] inherits,
MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs,
CastRepTemplate[] cts,
string[] imps, string javaTemplate)
: base(tName, usePath, inherits, ms, ps, fs, cts, imps, javaTemplate)
{ }
public override TypeRep mkEmptyRep()
{
return new InterfaceRep();
}
}
[XmlType("Enum")]
public class EnumRepTemplate : TypeRepTemplate
{
public EnumRepTemplate()
{ }
public EnumRepTemplate(string typeName)
: base(typeName)
{
}
public EnumRepTemplate(string tName, string[] usePath, string[] inherits,
MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs,
CastRepTemplate[] cts,
string[] imps, string javaTemplate)
: base(tName, usePath, inherits, ms, ps, fs, cts, imps, javaTemplate)
{ }
public override TypeRep mkEmptyRep()
{
return new EnumRep();
}
}
[XmlType("Struct")]
public class StructRepTemplate : ClassRepTemplate
{
public StructRepTemplate()
{
}
public StructRepTemplate(string typeName) : base(typeName)
{
}
public StructRepTemplate(string tName, string[] usePath, string[] inherits,
ConstructorRepTemplate[] cs,
MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs,
CastRepTemplate[] cts,
string[] imps, string javaTemplate)
: base(tName, usePath, inherits, cs, ms, ps, fs, cts, imps, javaTemplate)
{
}
public StructRepTemplate(string tName, string[] usePath, string[] inherits,
ConstructorRepTemplate[] cs,
MethodRepTemplate[] ms, PropRepTemplate[] ps, FieldRepTemplate[] fs, CastRepTemplate[] cts)
: base(tName, usePath, inherits, cs, ms, ps, fs, cts, new String[0], null)
{
}
public override TypeRep mkEmptyRep()
{
return new StructRep();
}
}
}

View File

@ -0,0 +1,146 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D33074E4-1525-4F22-A1DB-A7F30989D8FE}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RusticiSoftware.Translator</RootNamespace>
<AssemblyName>Translator</AssemblyName>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
</SccLocalPath>
<SccAuxPath>
</SccAuxPath>
<SccProvider>
</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="antlr.astframe, Version=2.7.7.1, Culture=neutral">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dll\antlr.astframe.dll</HintPath>
</Reference>
<Reference Include="antlr.runtime, Version=2.7.7.1, Culture=neutral">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dll\antlr.runtime.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ASTNode.cs" />
<Compile Include="ASTNodeFactory.cs" />
<Compile Include="CodeMaskEnums.cs" />
<Compile Include="CSharpEnvBuilder.cs" />
<Compile Include="DirectoryHT.cs" />
<Compile Include="SigEnv.cs" />
<Compile Include="TranslationTemplate.cs" />
<Compile Include="TypeTable.cs" />
<Compile Include="NetTranslatorBase.cs" />
<Compile Include="CSharpHooverTokenTypes.cs" />
<Compile Include="CSharpJavaTokenTypes.cs" />
<Compile Include="CSharpLexer.cs" />
<Compile Include="CSharpLexerBase.cs" />
<Compile Include="CSharpLexerBaseTokenTypes.cs" />
<Compile Include="CSharpLexerTokenTypes.cs" />
<Compile Include="CSharpParser.cs" />
<Compile Include="CSharpPreprocessorHooverLexer.cs" />
<Compile Include="CSharpPreprocessorLexer.cs" />
<Compile Include="CSharpPreprocessTokenTypes.cs" />
<Compile Include="CustomHiddenStreamToken.cs" />
<Compile Include="CSharpTranslator.cs" />
<Compile Include="Exception.cs" />
<Compile Include="JavaPrettyPrinter.cs" />
<Compile Include="JavaTreeParser.cs" />
<Compile Include="Main.cs" />
<Compile Include="NetTranslator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Set.cs" />
<Compile Include="SymbolTable.cs" />
<Compile Include="TypeRep.cs" />
<Compile Include="UnicodeLexerBase.cs" />
<Compile Include="UnicodeLexerBaseTokenTypes.cs" />
</ItemGroup>
<ItemGroup>
<Antlr Include="UnicodeLexerBase.g">
<OutputFiles>UnicodeLexerBase.cs;UnicodeLexerBaseTokenTypes.cs</OutputFiles>
</Antlr>
<Antlr Include="CSharpLexerBase.g">
<OutputFiles>CSharpLexerBase.cs;CSharpLexerBaseTokenTypes.cs</OutputFiles>
<IncludeFiles>-glib UnicodeLexerBase.g</IncludeFiles>
</Antlr>
<Antlr Include="CSharpLexer.g">
<OutputFiles>CSharpLexer.cs;;CSharpLexerTokenTypes.cs</OutputFiles>
<IncludeFiles>-glib UnicodeLexerBase.g;CSharpLexerBase.g</IncludeFiles>
</Antlr>
<Antlr Include="CSharpPreprocessorLexer.g">
<OutputFiles>CSharpPreprocessorLexer.cs;CSharpPreprocessTokenTypes.cs</OutputFiles>
<IncludeFiles>-glib UnicodeLexerBase.g;CSharpLexerBase.g</IncludeFiles>
</Antlr>
<Antlr Include="CSharpPreprocessorHooverLexer.g">
<OutputFiles>CSharpPreprocessorHooverLexer.cs;CSharpHooverTokenTypes.cs</OutputFiles>
<IncludeFiles>-glib UnicodeLexerBase.g;CSharpLexerBase.g</IncludeFiles>
</Antlr>
<Antlr Include="CSharpParser.g">
<OutputFiles>CSharpParser.cs;CSharpJavaTokenTypes.cs</OutputFiles>
</Antlr>
<Antlr Include="CSharpEnvBuilder.g">
<OutputFiles>CSharpEnvBuilder.cs</OutputFiles>
</Antlr>
<Antlr Include="CSharpTranslator.g">
<OutputFiles>CSharpTranslator.cs</OutputFiles>
</Antlr>
<Antlr Include="NetTranslator.g">
<OutputFiles>NetTranslator.cs</OutputFiles>
</Antlr>
<Antlr Include="JavaPrettyPrinter.g">
<OutputFiles>JavaPrettyPrinter.cs</OutputFiles>
</Antlr>
</ItemGroup>
<ItemGroup>
<Content Include="CSharpParser_LICENSE.TXT" />
<Content Include="CSharpParser_README.TXT" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<Target Name="GenerateAntlrCode" Inputs="@(Antlr)" Outputs="%(Antlr.OutputFiles)">
<Exec Command="java -cp ..\lib\antlr.jar antlr.Tool %(Antlr.IncludeFiles) @(Antlr)" Outputs="%(Antlr.OutputFiles)" />
</Target>
<Target Name="CleanAntlrCode">
<Delete Files="%(Antlr.OutputFiles)" />
</Target>
<PropertyGroup>
<BuildDependsOn>GenerateAntlrCode;$(BuildDependsOn)</BuildDependsOn>
</PropertyGroup>
<PropertyGroup>
<CleanDependsOn>CleanAntlrCode;$(CleanDependsOn)</CleanDependsOn>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,891 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using T = RusticiSoftware.Translator.CSharpJavaTokenTypes; // We want easy access to the Token mappings
namespace RusticiSoftware.Translator
{
public abstract class RepBase
{
protected static DirectoryHT TypeTemplateCache = new DirectoryHT();
//
protected const string TYPEVAR = "${TYPE}";
protected RepBase()
{
}
}
public class ParamRep : RepBase
{
private TypeRep _type;
public TypeRep Type
{
get { return _type; }
set { _type = value; }
}
private string _arg;
public string Name
{
get { return _arg; }
set { _arg = value; }
}
public ParamRep()
{}
public ParamRep(TypeRep t, string a)
{
_type = t;
_arg = a;
}
internal static ParamRep newInstance(ParamRepTemplate pt, ICollection pth)
{
ParamRep ret = new ParamRep();
ret.Name = pt.Name;
ret.Type = TypeRep.newInstance(pt.Type, pth);
return ret;
}
}
public class ConstructorRep : RepBase
{
private string[] _imports;
public string[] Imports
{
get { return _imports; }
set { _imports = value; }
}
private ParamRep[] _params;
public ParamRep[] Params
{
get { return _params; }
set { _params = value; }
}
private string _javaRep;
public string Java
{
get { return _javaRep; }
set { _javaRep = value; }
}
public ConstructorRep() : base()
{
}
public ConstructorRep(ParamRep[] pars, string javaRep) : base()
{
_params = pars;
_javaRep = javaRep;
}
public ConstructorRep(ConstructorRepTemplate ct, ICollection pth)
{
Params = new ParamRep[ct.Params.Length];
for (int i = 0; i < ct.Params.Length; i++)
{
Params[i] = ParamRep.newInstance(ct.Params[i], pth);
}
Imports = new string[ct.Imports.Length];
for (int i = 0; i < ct.Imports.Length; i++)
{
Imports[i] = ct.Imports[i];
}
Java = ct.Java;
}
}
public class MethodRep : ConstructorRep
{
private TypeRep _retType;
public TypeRep Return
{
get { return _retType; }
set { _retType = value; }
}
private string _methodName;
public string Name
{
get { return _methodName; }
set { _methodName = value; }
}
public MethodRep() : base()
{
}
public MethodRep(MethodRepTemplate mt, ICollection pth) : base(mt, pth)
{
Name = mt.Name;
Return = TypeRep.newInstance(mt.Return, pth);
}
}
public class CastRep : RepBase
{
private string[] _imports;
public string[] Imports
{
get { return _imports; }
set { _imports = value; }
}
private TypeRep _fType;
public TypeRep FromType
{
get { return _fType; }
set { _fType = value; }
}
private TypeRep _tType;
public TypeRep ToType
{
get { return _tType; }
set { _tType = value; }
}
private string _javaRep;
public string Java
{
get { return _javaRep; }
set { _javaRep = value; }
}
public CastRep()
: base()
{
}
public CastRep(CastRepTemplate ct, ICollection pth)
{
FromType = TypeRep.newInstance(ct.From, pth);
ToType = TypeRep.newInstance(ct.To, pth);
Java = ct.Java;
Imports = new string[ct.Imports.Length];
for (int i = 0; i < ct.Imports.Length; i++)
{
Imports[i] = ct.Imports[i];
}
}
internal static CastRep newInstance(CastRepTemplate ct, ICollection pth)
{
return new CastRep(ct, pth);
}
}
public class FieldRep : RepBase
{
private string[] _imports;
public string[] Imports
{
get { return _imports; }
set { _imports = value; }
}
private TypeRep _type;
public TypeRep Type
{
get { return _type; }
set { _type = value; }
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private string _javaGetRep;
public string Get
{
get { return _javaGetRep; }
set { _javaGetRep = value; }
}
private string _javaSetRep;
public string Set
{
get { return _javaSetRep; }
set { _javaSetRep = value; }
}
public FieldRep()
: base()
{
}
public FieldRep(FieldRepTemplate ft, ICollection pth)
{
Name = ft.Name;
Type = TypeRep.newInstance(ft.Type, pth);
Get = ft.Get;
Imports = new string[ft.Imports.Length];
for (int i = 0; i < ft.Imports.Length; i++)
{
Imports[i] = ft.Imports[i];
}
}
internal static FieldRep newInstance(FieldRepTemplate ft, ICollection pth)
{
return new FieldRep(ft, pth);
}
}
public class PropRep : FieldRep
{
public PropRep() : base()
{ }
public PropRep(PropRepTemplate pt, ICollection pth) : base(pt, pth)
{
Set = pt.Set;
}
internal static PropRep newInstance(PropRepTemplate pt, ICollection pth)
{
return new PropRep(pt, pth);
}
}
public class TypeRep : RepBase
{
private static Hashtable TypeRepCache = new Hashtable();
public static void Initialize(DirectoryHT e)
{
TypeTemplateCache = e;
}
public static DirectoryHT TypeEnv
{
get { return TypeTemplateCache; }
}
private string _typeName;
private string _java;
private TypeRep _extends;
private TypeRep[] _implements;
public string TypeName
{
get { return _typeName; }
set { _typeName = value; }
}
public string Java
{
get { return _java; }
set { _java = value; }
}
public TypeRep Extends
{
get { return _extends; }
set { _extends = value; }
}
public TypeRep[] Implements
{
get { return _implements; }
set { _implements = value; }
}
private string[] _imports;
public string[] Imports
{
get { return _imports; }
set { _imports = value; }
}
private Hashtable _methodsD = new Hashtable();
public Hashtable MethodsD
{
get { return _methodsD; }
set { _methodsD = value; }
}
private Hashtable _propsD = new Hashtable();
public Hashtable PropertiesD
{
get { return _propsD; }
set { _propsD = value; }
}
private Hashtable _fieldsD = new Hashtable();
public Hashtable FieldsD
{
get { return _fieldsD; }
set { _fieldsD = value; }
}
private CastRep[] _casts;
public CastRep[] Casts
{
get { return _casts; }
set { _casts = value; }
}
public TypeRep()
: base()
{
}
// Dummy Type
protected TypeRep(string name)
: base()
{
TypeName = name;
Extends = null;
Implements = new TypeRep[0];
Imports = new string[0];
MethodsD = new Hashtable();
PropertiesD = new Hashtable();
FieldsD = new Hashtable();
Casts = new CastRep[0];
}
protected TypeRep(TypeRepTemplate template) : this()
{
Build(template);
}
public virtual void Build(TypeRepTemplate template)
{
ICollection uPath = template.NamespacePath;
TypeName = template.TypeName;
Java = template.Java;
Imports = new string[template.Imports.Length];
for (int i = 0; i < template.Imports.Length; i++)
{
Imports[i] = template.Imports[i];
}
//Extends = TypeRep.newInstance(template.Extends, uPath);
//Implements = new TypeRep[template.Implements.Length];
ArrayList TmpImplements = new ArrayList();
Extends = null;
for (int i = 0; i < template.Inherits.Length; i++)
{
TypeRep trep = TypeRep.newInstance(template.Inherits[i], uPath);
if (trep is ClassRep)
{
if (Extends != null)
{
Console.Error.Write("Error -- (TypeRep.Build): " + TypeName + " extends more than one type (");
Console.Error.WriteLine(Extends.TypeName + " and " + trep.TypeName + ")");
}
else
Extends = trep;
}
else
TmpImplements.Add(trep);
}
if (Extends == null && TypeName != "System.Object")
Extends = TypeRep.newInstance("System.Object");
Implements = (TypeRep[]) TmpImplements.ToArray(typeof(TypeRep));
FieldsD = new Hashtable();
foreach (FieldRepTemplate ft in template.Fields)
{
FieldsD.Add(ft.Name, FieldRep.newInstance(ft, uPath));
}
Casts = new CastRep[template.Casts.Length];
for (int i = 0; i < template.Casts.Length; i++)
{
Casts[i] = CastRep.newInstance(template.Casts[i], uPath);
}
PropertiesD = new Hashtable();
foreach (PropRepTemplate pt in template.Properties)
{
PropertiesD.Add(pt.Name, PropRep.newInstance(pt, uPath));
}
MethodsD = new Hashtable();
foreach (MethodRepTemplate mt in template.Methods)
{
ArrayList ms = (ArrayList)MethodsD[mt.Name];
if (ms == null)
ms = new ArrayList();
ms.Add(new MethodRep(mt, uPath));
MethodsD[mt.Name] = ms;
}
}
private static ClassRep newInstance(ClassRepTemplate template)
{
return new ClassRep(template);
}
private static InterfaceRep newInstance(InterfaceRepTemplate template)
{
return new InterfaceRep(template);
}
// While we are constructing a parameterized type (an array), we store
// the base type here. This can probably become a dictionary when we
// need to build instances of generic types.
private static TypeRep __baseType = null;
// Finds a template for typeName by searching the path. typeName must not be an array
// type (i.e. end with [])
private static TypeRepTemplate TemplateSearch(string typeName, ICollection pth)
{
TypeRepTemplate ret = null;
DirectoryHT ns;
foreach (string p in pth)
{
ns = (DirectoryHT)TypeTemplateCache.subDir(p);
ret = (ns == null ? null : ns[typeName] as TypeRepTemplate);
if (ret != null)
break;
}
// Must Search the Global NameSpace too
if (ret == null)
ret = TypeTemplateCache[typeName] as TypeRepTemplate;
// If all else fails create a dummy typerep
if (ret == null)
{
// Oh Dear, shouldn't happen.
Console.WriteLine("WARNING: (TypeRep.TemplateSearch) -- Could not find a template for " + typeName);
ret = new InterfaceRepTemplate(typeName);
}
return ret;
}
public static TypeRep newInstance(string typeName, ICollection pth)
{
string baseName = typeName;
int rank = 0;
string arraySuffix = "";
// Necessary (only) for the parent of System.Object.
if (typeName == null)
return null;
if (typeName == TYPEVAR)
// keving: gross hack, see above comment.
return __baseType;
// Calculate full, qualified type name and array rank
while (baseName.EndsWith("[]"))
{
rank++;
arraySuffix += "[]";
baseName = baseName.Substring(0, baseName.Length - 2);
}
// Find the template (and the type's full name)
TypeRepTemplate template = TemplateSearch(baseName, pth);
if (template == null)
{
// Oh Dear, shouldn't happen.
Console.WriteLine("WARNING: (TypeRep.newInstance) -- Could not find a template for " + baseName);
return null;
}
return newInstance(template.TypeName+arraySuffix, template, rank);
}
private readonly static ArrayList EmptyPath = new ArrayList();
public static TypeRep newInstance(string typeName)
{
return newInstance(typeName, EmptyPath);
}
private static TypeRep newInstance(string fullTypeName, TypeRepTemplate baseTemplate, int rank)
{
TypeRep retRep = null;
if (TypeRepCache[fullTypeName] != null)
// Here is one we made earlier
return (TypeRep)TypeRepCache[fullTypeName];
// Place a dummy typeRep in the cache
if (rank > 0)
{
// Will eventually be the array typerep
retRep = new ClassRep();
TypeRepCache[fullTypeName] = retRep;
TypeRep savedType = __baseType;
__baseType = newInstance(fullTypeName.Substring(0, fullTypeName.Length - 2), baseTemplate, rank-1);
retRep.Build(TemplateSearch("System.Array", new ArrayList()));
retRep.TypeName = fullTypeName;
__baseType = savedType;
}
else
{
retRep = baseTemplate.mkEmptyRep();
// TODO: keving - nicer fix required!
if (fullTypeName != "System.Array") TypeRepCache[fullTypeName] = retRep;
retRep.Build(baseTemplate);
}
return retRep;
}
// Returns true iff child is a subclass of parent.
public bool IsA(ASTNode child)
{
if (child == null)
return false;
// Is Child a manifest NULL constant?
if (child.Type == T.NULL ||
(child.Type == T.EXPR && child.getFirstChild().Type == T.NULL))
return true;
return IsA(child.DotNetType);
}
// Returns true iff child is a subclass of parent.
public bool IsA(TypeRep child)
{
if (child == null)
return false;
if (child.TypeName.EndsWith("[]"))
{
if (TypeName == "System.Array")
return true;
if (TypeName.EndsWith("[]"))
// true if basetypes are parent-child
return Extends.IsA(child.Extends);
return false;
}
// Non-array child
if (TypeName == child.TypeName)
return true;
// Are we any of child's parents, or interfaces
if (IsA(child.Extends))
return true;
foreach (TypeRep t in child.Implements)
{
if (IsA(t))
return true;
}
return false;
}
//
public FieldRep Resolve(string fieldOrProp)
{
FieldRep ret = (FieldRep) PropertiesD[fieldOrProp];
if (ret == null)
ret = (FieldRep) FieldsD[fieldOrProp];
if (ret == null && Extends != null)
return Extends.Resolve(fieldOrProp);
return ret;
}
public MethodRep Resolve(string method, IList ArgVs)
{
MethodRep ret = null;
if (MethodsD.Contains(method))
{
foreach (MethodRep m in (ArrayList) MethodsD[method])
{
if (m.Params.Length == ArgVs.Count)
{
ret = m;
for (int i = 0; i < ArgVs.Count; i++)
{
if (!m.Params[i].Type.IsA((ASTNode)ArgVs[i]))
{
ret = null; // reset to null, this method doesn't match
break;
}
}
}
if (ret != null)
break;
}
}
// If not found, check parents
if (ret == null && Extends != null)
ret = Extends.Resolve(method, ArgVs);
// If still not found check interfaces
if (ret == null)
{
foreach (TypeRep t in Implements)
{
ret = t.Resolve(method, ArgVs);
if (ret != null)
break;
}
}
return ret;
}
private CastRep ResolveCastFrom(TypeRep from, bool onlyAny)
{
CastRep ret = null;
foreach (CastRep c in Casts)
{
if (c.FromType.IsA(from) &&
((onlyAny && c.ToType == null) || (!onlyAny && c.ToType != null && c.ToType.IsA(this))))
{
ret = c;
break;
}
}
if (ret == null)
{
// Check if compatible cast in our parent, but we can only
// have casts that are valid for any descendant
if (Extends != null)
return ((ClassRep)Extends).ResolveCastFrom(from, true);
}
return ret;
}
public CastRep ResolveCastFrom(TypeRep from)
{
return ResolveCastFrom(from, false);
}
public CastRep ResolveCastTo(TypeRep to)
{
CastRep ret = null;
foreach (CastRep c in Casts)
{
if (c.FromType.IsA(this) && (c.ToType == null || c.ToType.IsA(to)))
{
ret = c;
break;
}
}
if (ret == null)
{
// Check if compatible cast in parents
if (Extends != null)
return ((ClassRep)Extends).ResolveCastTo(to);
}
return ret;
}
// c.f. Type.IsAssignableFrom in .Net
//
// Returns true iff c and the current TypeRep represent the same type, or if the current TypeRep is
// in the inheritance hierarchy of c, or if the current TypeRep is an interface that c implements,
// or [if c is a generic type parameter and the current Type represents one of the constraints of c].
// false if none of these conditions are true, or if c is a null reference.
public bool IsAssignableFrom(TypeRep c)
{
return true;
}
public static void Test()
{
}
}
public class ClassRep : TypeRep
{
private ConstructorRep[] _Constructors = new ConstructorRep[0];
public ConstructorRep[] Constructors
{
get { return _Constructors; }
set { _Constructors = value; }
}
public ClassRep()
: base()
{ }
// Dummy type
public ClassRep(string name)
: base(name)
{
}
public ClassRep(ClassRepTemplate template)
: base(template)
{
Constructors = new ConstructorRep[template.Constructors.Length];
for (int i = 0; i < template.Constructors.Length; i++)
{
Constructors[i] = new ConstructorRep(template.Constructors[i], template.NamespacePath);
}
}
public override void Build(TypeRepTemplate template)
{
ClassRepTemplate ctemp = (ClassRepTemplate)template;
Constructors = new ConstructorRep[ctemp.Constructors.Length];
for (int i = 0; i < ctemp.Constructors.Length; i++)
{
Constructors[i] = new ConstructorRep(ctemp.Constructors[i], ctemp.NamespacePath);
}
base.Build(template);
}
public ConstructorRep Resolve(IList ArgVs)
{
ConstructorRep ret = null;
foreach (ConstructorRep c in Constructors)
{
if (c.Params.Length == ArgVs.Count)
{
ret = c;
for (int i = 0; i < ArgVs.Count; i++)
{
if (!c.Params[i].Type.IsA((ASTNode)ArgVs[i]))
{
ret = null; // reset to null, this method doesn't match
break;
}
}
}
if (ret != null)
break;
}
if (ret == null)
{
// Check if compatible constructor in parents
if (Extends != null)
return ((ClassRep)Extends).Resolve(ArgVs);
}
return ret;
}
}
public class InterfaceRep : TypeRep
{
public InterfaceRep()
: base()
{ }
// Dummy Interface
public InterfaceRep(string name)
: base(name)
{
}
public InterfaceRep(InterfaceRepTemplate template)
: base(template)
{
}
public override void Build(TypeRepTemplate template)
{
base.Build(template);
}
}
public class EnumRep : TypeRep
{
// stores the enum constants by value
string[] fieldsA = new string[0];
public EnumRep()
: base()
{ }
// Dummy Enum
public EnumRep(string name)
: base(name)
{
}
public EnumRep(EnumRepTemplate template)
: base(template)
{
int numfields = template.Fields.Length;
fieldsA = new string[numfields];
for (int i = 0; i < numfields; i++)
fieldsA[i] = template.Fields[i].Name;
}
public override void Build(TypeRepTemplate template)
{
int numfields = template.Fields.Length;
fieldsA = new string[numfields];
for (int i = 0; i < numfields; i++)
fieldsA[i] = template.Fields[i].Name;
base.Build(template);
}
public string getField(int v)
{
return fieldsA[v];
}
}
public class StructRep : TypeRep
{
public StructRep()
: base()
{ }
// Dummy Struct
public StructRep(string name)
: base(name)
{
}
public StructRep(StructRepTemplate template)
: base(template)
{
}
public override void Build(TypeRepTemplate template)
{
base.Build(template);
}
}
}

View File

@ -0,0 +1,69 @@
using System;
using System.Collections;
using System.Text;
using System.IO;
using System.Xml.Serialization;
namespace RusticiSoftware.Translator
{
// Holds our symbol table, a multi-level map from identifiers (string) to their type (string)
public class TypeTable
{
private Stack _outer = new Stack();
// _global always points to the bottom of the stack where global types live
private Hashtable _global = null;
public TypeTable()
{
// _global always points to the bottom of the stack where global types live
PushLevel();
_global = (Hashtable) _outer.Peek();
}
public void PushLevel()
{
_outer.Push(new Hashtable());
}
public void PopLevel()
{
_outer.Pop();
}
public void Add(string typeName, TypeRep t)
{
((Hashtable)_outer.Peek())[typeName] = t;
}
public TypeRep Get(string typeName)
{
foreach (Hashtable d in _outer)
{
if (d.Contains(typeName))
return (TypeRep)d[typeName];
}
return null;
}
public TypeRep this[string v]
{
get
{
return Get(v);
}
set
{
Add(v, value);
}
}
override public string ToString()
{
return _outer.ToString();
}
}
}

View File

@ -0,0 +1,691 @@
options
{
language = "CSharp";
namespace = "RusticiSoftware.Translator";
}
/*
[The "BSD licence"]
Copyright (c) 2002-2005 Kunle Odutola
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/// <summary>
/// Library of grammar rules that are useful for building Unicode-aware Lexers.
/// </summary>
///
/// <remarks>
/// <para>
/// The rules contained in this file were extracted from a Lexer for the ECMA C# language
/// and are intended to be re-used within other Lexer grammars via the ANTLR grammar
/// inheritance mechanism.
/// </para>
///
/// <para>
/// History
/// </para>
///
/// <para>
/// 08-Feb-2003 kunle Extracted the unicode rules from CSharpLexer.g<br/>
/// </para>
///
/// </remarks>
*/
class UnicodeLexerBase extends Lexer;
options
{
exportVocab = UnicodeLexerBase;
charVocabulary = '\u0000'..'\uFFFE'; // All UNICODE characters except \uFFFF
k = 1;
}
protected UNICODE_CLASS_Nl // Unicode Category or Class: Nl
: ( '\u16EE'..'\u16F0'
| '\u2160'..'\u2183'
| '\u3007'..'\u3007'
| '\u3021'..'\u3029'
| '\u3038'..'\u303A'
)
;
protected UNICODE_CLASS_Lt // Unicode Category or Class: Lt
: ( '\u01C5' | '\u01C8' | '\u01CB' | '\u01F2'
| '\u1F88'..'\u1F8F'
| '\u1F98'..'\u1F9F'
| '\u1FA8'..'\u1FAF'
| '\u1FBC' | '\u1FCC' | '\u1FFC'
)
;
protected UNICODE_CLASS_Zs // Unicode Category or Class: Zs
: ( '\u0020'
| '\u00A0'
| '\u1680'
| '\u2000'..'\u200B'
| '\u202F'
| '\u205F'
| '\u3000'
)
;
protected UNICODE_CLASS_Ll // Unicode Category or Class: Ll
: ( '\u0061'..'\u007A'
| '\u00AA' | '\u00B5' | '\u00BA'
| '\u00DF'..'\u00F6'
| '\u00F8'..'\u00FF'
| '\u0101' | '\u0103' | '\u0105' | '\u0107' | '\u0109' | '\u010B' | '\u010D' | '\u010F' | '\u0111'
| '\u0113' | '\u0115' | '\u0117' | '\u0119' | '\u011B' | '\u011D' | '\u011F' | '\u0121' | '\u0123'
| '\u0125' | '\u0127' | '\u0129' | '\u012B' | '\u012D' | '\u012F' | '\u0131' | '\u0133' | '\u0135'
| '\u0137'..'\u0138'
| '\u013A' | '\u013C' | '\u013E' | '\u0140' | '\u0142' | '\u0144' | '\u0146'
| '\u0148'..'\u0149'
| '\u014B' | '\u014D' | '\u014F' | '\u0151' | '\u0153' | '\u0155' | '\u0157' | '\u0159' | '\u015B'
| '\u015D' | '\u015F' | '\u0161' | '\u0163' | '\u0165' | '\u0167' | '\u0169' | '\u016B' | '\u016D'
| '\u016F' | '\u0171' | '\u0173' | '\u0175' | '\u0177' | '\u017A' | '\u017C'
| '\u017E'..'\u0180'
| '\u0183' | '\u0185' | '\u0188'
| '\u018C'..'\u018D'
| '\u0192' | '\u0195'
| '\u0199'..'\u019B'
| '\u019E' | '\u01A1' | '\u01A3' | '\u01A5' | '\u01A8'
| '\u01AA'..'\u01AB'
| '\u01AD' | '\u01B0' | '\u01B4' | '\u01B6'
| '\u01B9'..'\u01BA'
| '\u01BD'..'\u01BF'
| '\u01C6' | '\u01C9' | '\u01CC' | '\u01CE' | '\u01D0' | '\u01D2' | '\u01D4' | '\u01D6' | '\u01D8'
| '\u01DA'
| '\u01DC'..'\u01DD'
| '\u01DF' | '\u01E1' | '\u01E3' | '\u01E5' | '\u01E7' | '\u01E9' | '\u01EB' | '\u01ED'
| '\u01EF'..'\u01F0'
| '\u01F3' | '\u01F5' | '\u01F9' | '\u01FB' | '\u01FD' | '\u01FF' | '\u0201' | '\u0203' | '\u0205'
| '\u0207' | '\u0209' | '\u020B' | '\u020D' | '\u020F' | '\u0211' | '\u0213' | '\u0215' | '\u0217'
| '\u0219' | '\u021B' | '\u021D' | '\u021F' | '\u0223' | '\u0225' | '\u0227' | '\u0229' | '\u022B'
| '\u022D' | '\u022F' | '\u0231' | '\u0233'
| '\u0250'..'\u02AD'
| '\u0390'
| '\u03AC'..'\u03CE'
| '\u03D0'..'\u03D1'
| '\u03D5'..'\u03D7'
| '\u03D9' | '\u03DB' | '\u03DD' | '\u03DF' | '\u03E1' | '\u03E3' | '\u03E5' | '\u03E7' | '\u03E9'
| '\u03EB' | '\u03ED'
| '\u03EF'..'\u03F3'
| '\u03F5'
| '\u0430'..'\u045F'
| '\u0461' | '\u0463' | '\u0465' | '\u0467' | '\u0469' | '\u046B' | '\u046D' | '\u046F' | '\u0471'
| '\u0473' | '\u0475' | '\u0477' | '\u0479' | '\u047B' | '\u047D' | '\u047F' | '\u0481' | '\u048B'
| '\u048D' | '\u048F' | '\u0491' | '\u0493' | '\u0495' | '\u0497' | '\u0499' | '\u049B' | '\u049D'
| '\u049F' | '\u04A1' | '\u04A3' | '\u04A5' | '\u04A7' | '\u04A9' | '\u04AB' | '\u04AD' | '\u04AF'
| '\u04B1' | '\u04B3' | '\u04B5' | '\u04B7' | '\u04B9' | '\u04BB' | '\u04BD' | '\u04BF' | '\u04C2'
| '\u04C4' | '\u04C6' | '\u04C8' | '\u04CA' | '\u04CC' | '\u04CE' | '\u04D1' | '\u04D3' | '\u04D5'
| '\u04D7' | '\u04D9' | '\u04DB' | '\u04DD' | '\u04DF' | '\u04E1' | '\u04E3' | '\u04E5' | '\u04E7'
| '\u04E9' | '\u04EB' | '\u04ED' | '\u04EF' | '\u04F1' | '\u04F3' | '\u04F5' | '\u04F9' | '\u0501'
| '\u0503' | '\u0505' | '\u0507' | '\u0509' | '\u050B' | '\u050D' | '\u050F'
| '\u0561'..'\u0587'
| '\u1E01' | '\u1E03' | '\u1E05' | '\u1E07' | '\u1E09' | '\u1E0B' | '\u1E0D' | '\u1E0F' | '\u1E11'
| '\u1E13' | '\u1E15' | '\u1E17' | '\u1E19' | '\u1E1B' | '\u1E1D' | '\u1E1F' | '\u1E21' | '\u1E23'
| '\u1E25' | '\u1E27' | '\u1E29' | '\u1E2B' | '\u1E2D' | '\u1E2F' | '\u1E31' | '\u1E33' | '\u1E35'
| '\u1E37' | '\u1E39' | '\u1E3B' | '\u1E3D' | '\u1E3F' | '\u1E41' | '\u1E43' | '\u1E45' | '\u1E47'
| '\u1E49' | '\u1E4B' | '\u1E4D' | '\u1E4F' | '\u1E51' | '\u1E53' | '\u1E55' | '\u1E57' | '\u1E59'
| '\u1E5B' | '\u1E5D' | '\u1E5F' | '\u1E61' | '\u1E63' | '\u1E65' | '\u1E67' | '\u1E69' | '\u1E6B'
| '\u1E6D' | '\u1E6F' | '\u1E71' | '\u1E73' | '\u1E75' | '\u1E77' | '\u1E79' | '\u1E7B' | '\u1E7D'
| '\u1E7F' | '\u1E81' | '\u1E83' | '\u1E85' | '\u1E87' | '\u1E89' | '\u1E8B' | '\u1E8D' | '\u1E8F'
| '\u1E91' | '\u1E93'
| '\u1E95'..'\u1E9B'
| '\u1EA1' | '\u1EA3' | '\u1EA5' | '\u1EA7' | '\u1EA9' | '\u1EAB' | '\u1EAD' | '\u1EAF' | '\u1EB1'
| '\u1EB3' | '\u1EB5' | '\u1EB7' | '\u1EB9' | '\u1EBB' | '\u1EBD' | '\u1EBF' | '\u1EC1' | '\u1EC3'
| '\u1EC5' | '\u1EC7' | '\u1EC9' | '\u1ECB' | '\u1ECD' | '\u1ECF' | '\u1ED1' | '\u1ED3' | '\u1ED5'
| '\u1ED7' | '\u1ED9' | '\u1EDB' | '\u1EDD' | '\u1EDF' | '\u1EE1' | '\u1EE3' | '\u1EE5' | '\u1EE7'
| '\u1EE9' | '\u1EEB' | '\u1EED' | '\u1EEF' | '\u1EF1' | '\u1EF3' | '\u1EF5' | '\u1EF7' | '\u1EF9'
| '\u1F00'..'\u1F07'
| '\u1F10'..'\u1F15'
| '\u1F20'..'\u1F27'
| '\u1F30'..'\u1F37'
| '\u1F40'..'\u1F45'
| '\u1F50'..'\u1F57'
| '\u1F60'..'\u1F67'
| '\u1F70'..'\u1F7D'
| '\u1F80'..'\u1F87'
| '\u1F90'..'\u1F97'
| '\u1FA0'..'\u1FA7'
| '\u1FB0'..'\u1FB4'
| '\u1FB6'..'\u1FB7'
| '\u1FBE'
| '\u1FC2'..'\u1FC4'
| '\u1FC6'..'\u1FC7'
| '\u1FD0'..'\u1FD3'
| '\u1FD6'..'\u1FD7'
| '\u1FE0'..'\u1FE7'
| '\u1FF2'..'\u1FF4'
| '\u1FF6'..'\u1FF7'
| '\u2071' | '\u207F' | '\u210A'
| '\u210E'..'\u210F'
| '\u2113' | '\u212F' | '\u2134' | '\u2139' | '\u213D'
| '\u2146'..'\u2149'
| '\uFB00'..'\uFB06'
| '\uFB13'..'\uFB17'
| '\uFF41'..'\uFF5A'
)
;
protected UNICODE_CLASS_Lu // Unicode Category or Class: Lu
: ( '\u0041'..'\u005A'
| '\u00C0'..'\u00D6'
| '\u00D8'..'\u00DE'
| '\u0100' | '\u0102' | '\u0104' | '\u0106' | '\u0108' | '\u010A' | '\u010C' | '\u010E' | '\u0110'
| '\u0112' | '\u0114' | '\u0116' | '\u0118' | '\u011A' | '\u011C' | '\u011E' | '\u0120' | '\u0122'
| '\u0124' | '\u0126' | '\u0128' | '\u012A' | '\u012C' | '\u012E' | '\u0130' | '\u0132' | '\u0134'
| '\u0136' | '\u0139' | '\u013B' | '\u013D' | '\u013F' | '\u0141' | '\u0143' | '\u0145' | '\u0147'
| '\u014A' | '\u014C' | '\u014E' | '\u0150' | '\u0152' | '\u0154' | '\u0156' | '\u0158' | '\u015A'
| '\u015C' | '\u015E' | '\u0160' | '\u0162' | '\u0164' | '\u0166' | '\u0168' | '\u016A' | '\u016C'
| '\u016E' | '\u0170' | '\u0172' | '\u0174' | '\u0176'
| '\u0178'..'\u0179'
| '\u017B' | '\u017D'
| '\u0181'..'\u0182'
| '\u0184'
| '\u0186'..'\u0187'
| '\u0189'..'\u018B'
| '\u018E'..'\u0191'
| '\u0193'..'\u0194'
| '\u0196'..'\u0198'
| '\u019C'..'\u019D'
| '\u019F'..'\u01A0'
| '\u01A2' | '\u01A4'
| '\u01A6'..'\u01A7'
| '\u01A9' | '\u01AC'
| '\u01AE'..'\u01AF'
| '\u01B1'..'\u01B3'
| '\u01B5'
| '\u01B7'..'\u01B8'
| '\u01BC' | '\u01C4' | '\u01C7' | '\u01CA' | '\u01CD' | '\u01CF' | '\u01D1' | '\u01D3' | '\u01D5'
| '\u01D7' | '\u01D9' | '\u01DB' | '\u01DE' | '\u01E0' | '\u01E2' | '\u01E4' | '\u01E6' | '\u01E8'
| '\u01EA' | '\u01EC' | '\u01EE' | '\u01F1' | '\u01F4'
| '\u01F6'..'\u01F8'
| '\u01FA' | '\u01FC' | '\u01FE' | '\u0200' | '\u0202' | '\u0204' | '\u0206' | '\u0208' | '\u020A'
| '\u020C' | '\u020E' | '\u0210' | '\u0212' | '\u0214' | '\u0216' | '\u0218' | '\u021A' | '\u021C'
| '\u021E' | '\u0220' | '\u0222' | '\u0224' | '\u0226' | '\u0228' | '\u022A' | '\u022C' | '\u022E'
| '\u0230' | '\u0232' | '\u0386'
| '\u0388'..'\u038A'
| '\u038C'
| '\u038E'..'\u038F'
| '\u0391'..'\u03A1'
| '\u03A3'..'\u03AB'
| '\u03D2'..'\u03D4'
| '\u03D8' | '\u03DA' | '\u03DC' | '\u03DE' | '\u03E0' | '\u03E2' | '\u03E4' | '\u03E6' | '\u03E8'
| '\u03EA' | '\u03EC' | '\u03EE' | '\u03F4'
| '\u0400'..'\u042F'
| '\u0460' | '\u0462' | '\u0464' | '\u0466' | '\u0468' | '\u046A' | '\u046C' | '\u046E' | '\u0470'
| '\u0472' | '\u0474' | '\u0476' | '\u0478' | '\u047A' | '\u047C' | '\u047E' | '\u0480' | '\u048A'
| '\u048C' | '\u048E' | '\u0490' | '\u0492' | '\u0494' | '\u0496' | '\u0498' | '\u049A' | '\u049C'
| '\u049E' | '\u04A0' | '\u04A2' | '\u04A4' | '\u04A6' | '\u04A8' | '\u04AA' | '\u04AC' | '\u04AE'
| '\u04B0' | '\u04B2' | '\u04B4' | '\u04B6' | '\u04B8' | '\u04BA' | '\u04BC' | '\u04BE'
| '\u04C0'..'\u04C1'
| '\u04C3' | '\u04C5' | '\u04C7' | '\u04C9' | '\u04CB' | '\u04CD' | '\u04D0' | '\u04D2' | '\u04D4'
| '\u04D6' | '\u04D8' | '\u04DA' | '\u04DC' | '\u04DE' | '\u04E0' | '\u04E2' | '\u04E4' | '\u04E6'
| '\u04E8' | '\u04EA' | '\u04EC' | '\u04EE' | '\u04F0' | '\u04F2' | '\u04F4' | '\u04F8' | '\u0500'
| '\u0502' | '\u0504' | '\u0506' | '\u0508' | '\u050A' | '\u050C' | '\u050E'
| '\u0531'..'\u0556'
| '\u10A0'..'\u10C5'
| '\u1E00' | '\u1E02' | '\u1E04' | '\u1E06' | '\u1E08' | '\u1E0A' | '\u1E0C' | '\u1E0E' | '\u1E10'
| '\u1E12' | '\u1E14' | '\u1E16' | '\u1E18' | '\u1E1A' | '\u1E1C' | '\u1E1E' | '\u1E20' | '\u1E22'
| '\u1E24' | '\u1E26' | '\u1E28' | '\u1E2A' | '\u1E2C' | '\u1E2E' | '\u1E30' | '\u1E32' | '\u1E34'
| '\u1E36' | '\u1E38' | '\u1E3A' | '\u1E3C' | '\u1E3E' | '\u1E40' | '\u1E42' | '\u1E44' | '\u1E46'
| '\u1E48' | '\u1E4A' | '\u1E4C' | '\u1E4E' | '\u1E50' | '\u1E52' | '\u1E54' | '\u1E56' | '\u1E58'
| '\u1E5A' | '\u1E5C' | '\u1E5E' | '\u1E60' | '\u1E62' | '\u1E64' | '\u1E66' | '\u1E68' | '\u1E6A'
| '\u1E6C' | '\u1E6E' | '\u1E70' | '\u1E72' | '\u1E74' | '\u1E76' | '\u1E78' | '\u1E7A' | '\u1E7C'
| '\u1E7E' | '\u1E80' | '\u1E82' | '\u1E84' | '\u1E86' | '\u1E88' | '\u1E8A' | '\u1E8C' | '\u1E8E'
| '\u1E90' | '\u1E92' | '\u1E94' | '\u1EA0' | '\u1EA2' | '\u1EA4' | '\u1EA6' | '\u1EA8' | '\u1EAA'
| '\u1EAC' | '\u1EAE' | '\u1EB0' | '\u1EB2' | '\u1EB4' | '\u1EB6' | '\u1EB8' | '\u1EBA' | '\u1EBC'
| '\u1EBE' | '\u1EC0' | '\u1EC2' | '\u1EC4' | '\u1EC6' | '\u1EC8' | '\u1ECA' | '\u1ECC' | '\u1ECE'
| '\u1ED0' | '\u1ED2' | '\u1ED4' | '\u1ED6' | '\u1ED8' | '\u1EDA' | '\u1EDC' | '\u1EDE' | '\u1EE0'
| '\u1EE2' | '\u1EE4' | '\u1EE6' | '\u1EE8' | '\u1EEA' | '\u1EEC' | '\u1EEE' | '\u1EF0' | '\u1EF2'
| '\u1EF4' | '\u1EF6' | '\u1EF8'
| '\u1F08'..'\u1F0F'
| '\u1F18'..'\u1F1D'
| '\u1F28'..'\u1F2F'
| '\u1F38'..'\u1F3F'
| '\u1F48'..'\u1F4D'
| '\u1F59' | '\u1F5B' | '\u1F5D' | '\u1F5F'
| '\u1F68'..'\u1F6F'
| '\u1FB8'..'\u1FBB'
| '\u1FC8'..'\u1FCB'
| '\u1FD8'..'\u1FDB'
| '\u1FE8'..'\u1FEC'
| '\u1FF8'..'\u1FFB'
| '\u2102' | '\u2107'
| '\u210B'..'\u210D'
| '\u2110'..'\u2112'
| '\u2115'
| '\u2119'..'\u211D'
| '\u2124' | '\u2126' | '\u2128'
| '\u212A'..'\u212D'
| '\u2130'..'\u2131'
| '\u2133'
| '\u213E'..'\u213F'
| '\u2145'
| '\uFF21'..'\uFF3A'
)
;
protected UNICODE_CLASS_Lo // Unicode Category or Class: XX
: ( '\u01BB'
| '\u01C0'..'\u01C3'
| '\u05D0'..'\u05EA'
| '\u05F0'..'\u05F2'
| '\u0621'..'\u063A'
| '\u0641'..'\u064A'
| '\u066E'..'\u066F'
| '\u0671'..'\u06D3'
| '\u06D5'
| '\u06FA'..'\u06FC'
| '\u0710'
| '\u0712'..'\u072C'
| '\u0780'..'\u07A5'
| '\u07B1'
| '\u0905'..'\u0939'
| '\u093D' | '\u0950'
| '\u0958'..'\u0961'
| '\u0985'..'\u098C'
| '\u098F'..'\u0990'
| '\u0993'..'\u09A8'
| '\u09AA'..'\u09B0'
| '\u09B2'
| '\u09B6'..'\u09B9'
| '\u09DC'..'\u09DD'
| '\u09DF'..'\u09E1'
| '\u09F0'..'\u09F1'
| '\u0A05'..'\u0A0A'
| '\u0A0F'..'\u0A10'
| '\u0A13'..'\u0A28'
| '\u0A2A'..'\u0A30'
| '\u0A32'..'\u0A33'
| '\u0A35'..'\u0A36'
| '\u0A38'..'\u0A39'
| '\u0A59'..'\u0A5C'
| '\u0A5E'
| '\u0A72'..'\u0A74'
| '\u0A85'..'\u0A8B'
| '\u0A8D'
| '\u0A8F'..'\u0A91'
| '\u0A93'..'\u0AA8'
| '\u0AAA'..'\u0AB0'
| '\u0AB2'..'\u0AB3'
| '\u0AB5'..'\u0AB9'
| '\u0ABD' | '\u0AD0' | '\u0AE0'
| '\u0B05'..'\u0B0C'
| '\u0B0F'..'\u0B10'
| '\u0B13'..'\u0B28'
| '\u0B2A'..'\u0B30'
| '\u0B32'..'\u0B33'
| '\u0B36'..'\u0B39'
| '\u0B3D'
| '\u0B5C'..'\u0B5D'
| '\u0B5F'..'\u0B61'
| '\u0B83'
| '\u0B85'..'\u0B8A'
| '\u0B8E'..'\u0B90'
| '\u0B92'..'\u0B95'
| '\u0B99'..'\u0B9A'
| '\u0B9C'
| '\u0B9E'..'\u0B9F'
| '\u0BA3'..'\u0BA4'
| '\u0BA8'..'\u0BAA'
| '\u0BAE'..'\u0BB5'
| '\u0BB7'..'\u0BB9'
| '\u0C05'..'\u0C0C'
| '\u0C0E'..'\u0C10'
| '\u0C12'..'\u0C28'
| '\u0C2A'..'\u0C33'
| '\u0C35'..'\u0C39'
| '\u0C60'..'\u0C61'
| '\u0C85'..'\u0C8C'
| '\u0C8E'..'\u0C90'
| '\u0C92'..'\u0CA8'
| '\u0CAA'..'\u0CB3'
| '\u0CB5'..'\u0CB9'
| '\u0CDE'
| '\u0CE0'..'\u0CE1'
| '\u0D05'..'\u0D0C'
| '\u0D0E'..'\u0D10'
| '\u0D12'..'\u0D28'
| '\u0D2A'..'\u0D39'
| '\u0D60'..'\u0D61'
| '\u0D85'..'\u0D96'
| '\u0D9A'..'\u0DB1'
| '\u0DB3'..'\u0DBB'
| '\u0DBD'
| '\u0DC0'..'\u0DC6'
| '\u0E01'..'\u0E30'
| '\u0E32'..'\u0E33'
| '\u0E40'..'\u0E45'
| '\u0E81'..'\u0E82'
| '\u0E84'
| '\u0E87'..'\u0E88'
| '\u0E8A' | '\u0E8D'
| '\u0E94'..'\u0E97'
| '\u0E99'..'\u0E9F'
| '\u0EA1'..'\u0EA3'
| '\u0EA5' | '\u0EA7'
| '\u0EAA'..'\u0EAB'
| '\u0EAD'..'\u0EB0'
| '\u0EB2'..'\u0EB3'
| '\u0EBD'
| '\u0EC0'..'\u0EC4'
| '\u0EDC'..'\u0EDD'
| '\u0F00'
| '\u0F40'..'\u0F47'
| '\u0F49'..'\u0F6A'
| '\u0F88'..'\u0F8B'
| '\u1000'..'\u1021'
| '\u1023'..'\u1027'
| '\u1029'..'\u102A'
| '\u1050'..'\u1055'
| '\u10D0'..'\u10F8'
| '\u1100'..'\u1159'
| '\u115F'..'\u11A2'
| '\u11A8'..'\u11F9'
| '\u1200'..'\u1206'
| '\u1208'..'\u1246'
| '\u1248'
| '\u124A'..'\u124D'
| '\u1250'..'\u1256'
| '\u1258'
| '\u125A'..'\u125D'
| '\u1260'..'\u1286'
| '\u1288'
| '\u128A'..'\u128D'
| '\u1290'..'\u12AE'
| '\u12B0'
| '\u12B2'..'\u12B5'
| '\u12B8'..'\u12BE'
| '\u12C0'
| '\u12C2'..'\u12C5'
| '\u12C8'..'\u12CE'
| '\u12D0'..'\u12D6'
| '\u12D8'..'\u12EE'
| '\u12F0'..'\u130E'
| '\u1310'
| '\u1312'..'\u1315'
| '\u1318'..'\u131E'
| '\u1320'..'\u1346'
| '\u1348'..'\u135A'
| '\u13A0'..'\u13F4'
| '\u1401'..'\u166C'
| '\u166F'..'\u1676'
| '\u1681'..'\u169A'
| '\u16A0'..'\u16EA'
| '\u1700'..'\u170C'
| '\u170E'..'\u1711'
| '\u1720'..'\u1731'
| '\u1740'..'\u1751'
| '\u1760'..'\u176C'
| '\u176E'..'\u1770'
| '\u1780'..'\u17B3'
| '\u17DC'
| '\u1820'..'\u1842'
| '\u1844'..'\u1877'
| '\u1880'..'\u18A8'
| '\u2135'..'\u2138'
| '\u3006' | '\u303C'
| '\u3041'..'\u3096'
| '\u309F'
| '\u30A1'..'\u30FA'
| '\u30FF'
| '\u3105'..'\u312C'
| '\u3131'..'\u318E'
| '\u31A0'..'\u31B7'
| '\u31F0'..'\u31FF'
| '\u3400' | '\u4DB5' | '\u4E00' | '\u9FA5'
| '\uA000'..'\uA48C'
| '\uAC00' | '\uD7A3'
| '\uF900'..'\uFA2D'
| '\uFA30'..'\uFA6A'
| '\uFB1D'
| '\uFB1F'..'\uFB28'
| '\uFB2A'..'\uFB36'
| '\uFB38'..'\uFB3C'
| '\uFB3E'
| '\uFB40'..'\uFB41'
| '\uFB43'..'\uFB44'
| '\uFB46'..'\uFBB1'
| '\uFBD3'..'\uFD3D'
| '\uFD50'..'\uFD8F'
| '\uFD92'..'\uFDC7'
| '\uFDF0'..'\uFDFB'
| '\uFE70'..'\uFE74'
| '\uFE76'..'\uFEFC'
| '\uFF66'..'\uFF6F'
| '\uFF71'..'\uFF9D'
| '\uFFA0'..'\uFFBE'
| '\uFFC2'..'\uFFC7'
| '\uFFCA'..'\uFFCF'
| '\uFFD2'..'\uFFD7'
| '\uFFDA'..'\uFFDC'
)
;
protected UNICODE_CLASS_Lm // Unicode Category or Class: Lm
: ( '\u02B0'..'\u02B8'
| '\u02BB'..'\u02C1'
| '\u02D0'..'\u02D1'
| '\u02E0'..'\u02E4'
| '\u02EE' | '\u037A' | '\u0559' | '\u0640'
| '\u06E5'..'\u06E6'
| '\u0E46' | '\u0EC6' | '\u17D7' | '\u1843' | '\u3005'
| '\u3031'..'\u3035'
| '\u303B'
| '\u309D'..'\u309E'
| '\u30FC'..'\u30FE'
| '\uFF70'
| '\uFF9E'..'\uFF9F'
)
;
protected UNICODE_CLASS_Mn // Unicode Category or Class: Mn
: ( '\u0300'..'\u034F'
| '\u0360'..'\u036F'
| '\u0483'..'\u0486'
| '\u0591'..'\u05A1'
| '\u05A3'..'\u05B9'
| '\u05BB'..'\u05BD'
| '\u05BF'
| '\u05C1'..'\u05C2'
| '\u05C4'
| '\u064B'..'\u0655'
| '\u0670'
| '\u06D6'..'\u06DC'
| '\u06DF'..'\u06E4'
| '\u06E7'..'\u06E8'
| '\u06EA'..'\u06ED'
| '\u0711'
| '\u0730'..'\u074A'
| '\u07A6'..'\u07B0'
| '\u0901'..'\u0902'
| '\u093C'
| '\u0941'..'\u0948'
| '\u094D'
| '\u0951'..'\u0954'
| '\u0962'..'\u0963'
| '\u0981' | '\u09BC'
| '\u09C1'..'\u09C4'
| '\u09CD'
| '\u09E2'..'\u09E3'
| '\u0A02' | '\u0A3C'
| '\u0A41'..'\u0A42'
| '\u0A47'..'\u0A48'
| '\u0A4B'..'\u0A4D'
| '\u0A70'..'\u0A71'
| '\u0A81'..'\u0A82'
| '\u0ABC'
| '\u0AC1'..'\u0AC5'
| '\u0AC7'..'\u0AC8'
| '\u0ACD' | '\u0B01' | '\u0B3C' | '\u0B3F'
| '\u0B41'..'\u0B43'
| '\u0B4D' | '\u0B56' | '\u0B82' | '\u0BC0' | '\u0BCD'
| '\u0C3E'..'\u0C40'
| '\u0C46'..'\u0C48'
| '\u0C4A'..'\u0C4D'
| '\u0C55'..'\u0C56'
| '\u0CBF' | '\u0CC6'
| '\u0CCC'..'\u0CCD'
| '\u0D41'..'\u0D43'
| '\u0D4D' | '\u0DCA'
| '\u0DD2'..'\u0DD4'
| '\u0DD6' | '\u0E31'
| '\u0E34'..'\u0E3A'
| '\u0E47'..'\u0E4E'
| '\u0EB1'
| '\u0EB4'..'\u0EB9'
| '\u0EBB'..'\u0EBC'
| '\u0EC8'..'\u0ECD'
| '\u0F18'..'\u0F19'
| '\u0F35' | '\u0F37' | '\u0F39'
| '\u0F71'..'\u0F7E'
| '\u0F80'..'\u0F84'
| '\u0F86'..'\u0F87'
| '\u0F90'..'\u0F97'
| '\u0F99'..'\u0FBC'
| '\u0FC6'
| '\u102D'..'\u1030'
| '\u1032'
| '\u1036'..'\u1037'
| '\u1039'
| '\u1058'..'\u1059'
| '\u1712'..'\u1714'
| '\u1732'..'\u1734'
| '\u1752'..'\u1753'
| '\u1772'..'\u1773'
| '\u17B7'..'\u17BD'
| '\u17C6'
| '\u17C9'..'\u17D3'
| '\u180B'..'\u180D'
| '\u18A9'
| '\u20D0'..'\u20DC'
| '\u20E1'
| '\u20E5'..'\u20EA'
| '\u302A'..'\u302F'
| '\u3099'..'\u309A'
| '\uFB1E'
| '\uFE00'..'\uFE0F'
| '\uFE20'..'\uFE23'
)
;
protected UNICODE_CLASS_Mc // Unicode Category or Class: Mc
: ( '\u0903'
| '\u093E'..'\u0940'
| '\u0949'..'\u094C'
| '\u0982'..'\u0983'
| '\u09BE'..'\u09C0'
| '\u09C7'..'\u09C8'
| '\u09CB'..'\u09CC'
| '\u09D7'
| '\u0A3E'..'\u0A40'
| '\u0A83'
| '\u0ABE'..'\u0AC0'
| '\u0AC9'
| '\u0ACB'..'\u0ACC'
| '\u0B02'..'\u0B03'
| '\u0B3E' | '\u0B40'
| '\u0B47'..'\u0B48'
| '\u0B4B'..'\u0B4C'
| '\u0B57'
| '\u0BBE'..'\u0BBF'
| '\u0BC1'..'\u0BC2'
| '\u0BC6'..'\u0BC8'
| '\u0BCA'..'\u0BCC'
| '\u0BD7'
| '\u0C01'..'\u0C03'
| '\u0C41'..'\u0C44'
| '\u0C82'..'\u0C83'
| '\u0CBE'
| '\u0CC0'..'\u0CC4'
| '\u0CC7'..'\u0CC8'
| '\u0CCA'..'\u0CCB'
| '\u0CD5'..'\u0CD6'
| '\u0D02'..'\u0D03'
| '\u0D3E'..'\u0D40'
| '\u0D46'..'\u0D48'
| '\u0D4A'..'\u0D4C'
| '\u0D57'
| '\u0D82'..'\u0D83'
| '\u0DCF'..'\u0DD1'
| '\u0DD8'..'\u0DDF'
| '\u0DF2'..'\u0DF3'
| '\u0F3E'..'\u0F3F'
| '\u0F7F' | '\u102C' | '\u1031' | '\u1038'
| '\u1056'..'\u1057'
| '\u17B4'..'\u17B6'
| '\u17BE'..'\u17C5'
| '\u17C7'..'\u17C8'
)
;
protected UNICODE_CLASS_Nd // Unicode Category or Class: Nd
: ( '\u0030'..'\u0039'
| '\u0660'..'\u0669'
| '\u06F0'..'\u06F9'
| '\u0966'..'\u096F'
| '\u09E6'..'\u09EF'
| '\u0A66'..'\u0A6F'
| '\u0AE6'..'\u0AEF'
| '\u0B66'..'\u0B6F'
| '\u0BE7'..'\u0BEF'
| '\u0C66'..'\u0C6F'
| '\u0CE6'..'\u0CEF'
| '\u0D66'..'\u0D6F'
| '\u0E50'..'\u0E59'
| '\u0ED0'..'\u0ED9'
| '\u0F20'..'\u0F29'
| '\u1040'..'\u1049'
| '\u1369'..'\u1371'
| '\u17E0'..'\u17E9'
| '\u1810'..'\u1819'
| '\uFF10'..'\uFF19'
)
;
protected UNICODE_CLASS_Pc // Unicode Category or Class: Pc
: ( '\u005F'
| '\u203F'..'\u2040'
| '\u30FB'
| '\uFE33'..'\uFE34'
| '\uFE4D'..'\uFE4F'
| '\uFF3F' | '\uFF65'
)
;
protected UNICODE_CLASS_Cf // Unicode Category or Class: Cf
: ( '\u06DD' | '\u070F' | '\u180E'
| '\u200C'..'\u200F'
| '\u202A'..'\u202E'
| '\u2060'..'\u2063'
| '\u206A'..'\u206F'
| '\uFEFF'
| '\uFFF9'..'\uFFFB'
)
;

View File

@ -0,0 +1,56 @@
build.dir=${basedir}/../build
builder.ant.lib=${basedir}/lib
builder.ant.dll=${basedir}/dll
## For Building cs2j
# Location of .Net on this machine (this is standard .Net 2.0 location)
windows.dotnet.release=v2.0.50727
windows.dotnet.dir=C:/WINDOWS/Microsoft.NET/Framework/${windows.dotnet.release}
# Location of antlr dlls on this machine
antlr.dll.dir=${builder.ant.dll}
cs2jtx.src.dir=${basedir}/Translator
cs2jtx.bin.dir=${cs2jtx.src.dir}/bin/Debug
cs2jtx.build.dir=${build.dir}/cs2jtx
## For running cs2j
cs2jtx.exe= ${cs2jtx.bin.dir}/Translator.exe
#cs2jtx.exe= ${basedir}/../bin/Translator.exe
#whichbranch=AmazonBranch
whichbranch=TrunkBranch
# Sources, by default these are sibling directories of this script
#cs2j.dir=${basedir}/../../AmazonBranch/CS2JLibrary
#cheats.dir=${basedir}/../AmazonBranch/Cheats
cs2j.dir=${basedir}/../../${whichbranch}/CS2JLibrary
cheats.dir=${basedir}/../${whichbranch}/Cheats
# Directories to build into, against
cs.app.name=ScormEngineNetTrunk
#cs.app.name=Amazonsimpledb4thed
#cs.app.dir=${user.home}/My Documents/gitrepos/${cs.app.name}/src/app/ScormEngine.Core
cs.app.dir=${user.home}/My Documents/Visual Studio 2005/Projects/${cs.app.name}/src/app/ScormEngine.Core
# Set cs.tx.project if you want to translate a subset of the application
#cs.tx.project=ScormEngine.Core/Logic
cs.tx.project=Logic
cs.tx.dir=${cs.app.dir}/${cs.tx.project}
# Object of the translation, by default in the build area
#java.output.dir=${user.home}/My Documents/AmazonBranch/RusticiSoftware.ScormContentPlayer.Logic/src
java.output.dir=${user.home}/My Documents/${whichbranch}/RusticiSoftware.ScormContentPlayer.Logic/src

175
CSharpTranslator/build.xml Normal file
View File

@ -0,0 +1,175 @@
<?xml-stylesheet type="text/xsl" href="file://C:\ant\etc\antex\antprettybuild\antprettybuild-3.1.1.xsl"?>
<project name="cs2jTranslator" default="" basedir="." xmlns:dn="antlib:org.apache.ant.dotnet">
<description>
This script builds the cs2j translator and translates C# code
</description>
<property file="${user.home}/${ant.project.name}.build.properties" />
<property file="${user.home}/build.properties" />
<property file="build.properties" />
<!-- load the ant-dotnet task, see http://ant.apache.org/antlibs/dotnet/index.html -->
<taskdef uri="antlib:org.apache.ant.dotnet" resource="org/apache/ant/dotnet/antlib.xml" classpath="${builder.ant.lib}/ant-dotnet-1.0.jar" />
<!-- We could have left this in the msbuild script fed to buildTranslator, but it is clearer in Ant :) -->
<target name="antlrTranslator" depends="init">
<antlr target="${cs2jtx.src.dir}/UnicodeLexerBase.g">
<classpath> <pathelement location="${builder.ant.lib}/antlr.jar"/> </classpath>
</antlr>
<antlr target="${cs2jtx.src.dir}/CSharpLexerBase.g" glib="${cs2jtx.src.dir}/UnicodeLexerBase.g">
<classpath> <pathelement location="${builder.ant.lib}/antlr.jar"/> </classpath>
</antlr>
<antlr target="${cs2jtx.src.dir}/CSharpLexer.g" glib="${cs2jtx.src.dir}/UnicodeLexerBase.g;${cs2jtx.src.dir}/CSharpLexerBase.g">
<classpath> <pathelement location="${builder.ant.lib}/antlr.jar"/> </classpath>
</antlr>
<antlr target="${cs2jtx.src.dir}/CSharpPreprocessorLexer.g" glib="${cs2jtx.src.dir}/UnicodeLexerBase.g;${cs2jtx.src.dir}/CSharpLexerBase.g">
<classpath> <pathelement location="${builder.ant.lib}/antlr.jar"/> </classpath>
</antlr>
<antlr target="${cs2jtx.src.dir}/CSharpPreprocessorHooverLexer.g" glib="${cs2jtx.src.dir}/UnicodeLexerBase.g;${cs2jtx.src.dir}/CSharpLexerBase.g">
<classpath> <pathelement location="${builder.ant.lib}/antlr.jar"/> </classpath>
</antlr>
<antlr target="${cs2jtx.src.dir}/CSharpParser.g">
<classpath> <pathelement location="${builder.ant.lib}/antlr.jar"/> </classpath>
</antlr>
<antlr target="${cs2jtx.src.dir}/CSharpEnvBuilder.g">
<classpath> <pathelement location="${builder.ant.lib}/antlr.jar"/> </classpath>
</antlr>
<antlr target="${cs2jtx.src.dir}/CSharpTranslator.g">
<classpath id="antlrjar"> <pathelement location="${builder.ant.lib}/antlr.jar"/> </classpath>
</antlr>
<antlr target="${cs2jtx.src.dir}/NetTranslator.g">
<classpath id="antlrjar"> <pathelement location="${builder.ant.lib}/antlr.jar"/> </classpath>
</antlr>
<antlr target="${cs2jtx.src.dir}/JavaPrettyPrinter.g">
<classpath id="antlrjar"> <pathelement location="${builder.ant.lib}/antlr.jar"/> </classpath>
</antlr>
</target>
<!-- C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /defin
e:DEBUG;TRACE /reference:C:\cygwin\antlr\build\lib\antlr.astframe.dll /reference:C:\cygwin\antlr\build\lib\antlr.runtime
.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framew
ork\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll /reference:C
:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /debug+ /debug:full /optimize- /out:obj\Debug\Translator.exe
/target:exe
-->
<target name="buildTranslator" depends="antlrTranslator" description="Builds CSharp to Java Translator">
<mkdir dir="${cs2jtx.bin.dir}/"/>
<dn:msbuild>
<dn:build>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<!-- I am just mimicing the standard build options used by VS2005 here -->
<Csc Sources="@(Compile)" References="@(Reference)" TargetType="exe"
OutputAssembly="${cs2jtx.bin.dir}/Translator.exe"
Optimize="false"
DebugType="full"
DisabledWarnings="1701,1702"
EmitDebugInformation="true"
ErrorReport="prompt"
NoConfig="true"
Warninglevel="4" />
</Target>
<ItemGroup>
<Reference Include="${antlr.dll.dir}/antlr.astframe.dll" />
<Reference Include="${antlr.dll.dir}/antlr.runtime.dll" />
<Reference Include="${windows.dotnet.dir}/System.dll" />
<Reference Include="${windows.dotnet.dir}/System.Data.dll" />
<Reference Include="${windows.dotnet.dir}/System.Windows.Forms.dll" />
<Reference Include="${windows.dotnet.dir}/System.Xml.dll" />
</ItemGroup>
<ItemGroup>
<Compile Include="${cs2jtx.src.dir}\ASTNode.cs" />
<Compile Include="${cs2jtx.src.dir}\ASTNodeFactory.cs" />
<Compile Include="${cs2jtx.src.dir}\CodeMaskEnums.cs" />
<Compile Include="${cs2jtx.src.dir}\CSharpEnvBuilder.cs" />
<Compile Include="${cs2jtx.src.dir}\DirectoryHT.cs" />
<Compile Include="${cs2jtx.src.dir}\SigEnv.cs" />
<Compile Include="${cs2jtx.src.dir}\TranslationTemplate.cs" />
<Compile Include="${cs2jtx.src.dir}\TypeTable.cs" />
<Compile Include="${cs2jtx.src.dir}\NetTranslatorBase.cs" />
<Compile Include="${cs2jtx.src.dir}\CSharpHooverTokenTypes.cs" />
<Compile Include="${cs2jtx.src.dir}\CSharpJavaTokenTypes.cs" />
<Compile Include="${cs2jtx.src.dir}\CSharpLexer.cs" />
<Compile Include="${cs2jtx.src.dir}\CSharpLexerBase.cs" />
<Compile Include="${cs2jtx.src.dir}\CSharpLexerBaseTokenTypes.cs" />
<Compile Include="${cs2jtx.src.dir}\CSharpLexerTokenTypes.cs" />
<Compile Include="${cs2jtx.src.dir}\CSharpParser.cs" />
<Compile Include="${cs2jtx.src.dir}\CSharpPreprocessorHooverLexer.cs" />
<Compile Include="${cs2jtx.src.dir}\CSharpPreprocessorLexer.cs" />
<Compile Include="${cs2jtx.src.dir}\CSharpPreprocessTokenTypes.cs" />
<Compile Include="${cs2jtx.src.dir}\CustomHiddenStreamToken.cs" />
<Compile Include="${cs2jtx.src.dir}\CSharpTranslator.cs" />
<Compile Include="${cs2jtx.src.dir}\Exception.cs" />
<Compile Include="${cs2jtx.src.dir}\JavaPrettyPrinter.cs" />
<Compile Include="${cs2jtx.src.dir}\JavaTreeParser.cs" />
<Compile Include="${cs2jtx.src.dir}\Main.cs" />
<Compile Include="${cs2jtx.src.dir}\NetTranslator.cs" />
<Compile Include="${cs2jtx.src.dir}\Properties\AssemblyInfo.cs" />
<Compile Include="${cs2jtx.src.dir}\Set.cs" />
<Compile Include="${cs2jtx.src.dir}\SymbolTable.cs" />
<Compile Include="${cs2jtx.src.dir}\TypeRep.cs" />
<Compile Include="${cs2jtx.src.dir}\UnicodeLexerBase.cs" />
<Compile Include="${cs2jtx.src.dir}\UnicodeLexerBaseTokenTypes.cs" />
</ItemGroup>
</Project>
</dn:build>
</dn:msbuild>
<copy file="${antlr.dll.dir}/antlr.astframe.dll" todir="${cs2jtx.bin.dir}"/>
<copy file="${antlr.dll.dir}/antlr.runtime.dll" todir="${cs2jtx.bin.dir}"/>
</target>
<!-- "C:\Documents and Settings\kevin.glynn\My Documents\Visual Studio
2005\Projects\Translator\Translator\bin\Debug\Translator.exe" -dumpxml
-odir "C:\Documents and
Settings\kevin.glynn\eclipsews\RusticiSoftware.ScormUntethered.Logic\src"
-netdir "c:\Documents and Settings\kevin.glynn\eclipsews\CS2JLibrary"
-appdir "c:\docume~1\kevin~1.gly\locals~1\temp\tmpk6_pcn" -cheatdir
"c:\Documents and Settings\kevin.glynn\My Documents\Cheats"
"c:\docume~1\kevin~1.gly\locals~1\temp\tmpk6_pcn\UntetheredLogic" -->
<target name="translateCS2J" depends="init" description="run translator">
<dn:dotnetexec executable="${cs2jtx.exe}">
<arg value="-version"/>
<arg value="-dumpxml"/>
<arg value="-xmldir"/>
<arg file="${cs2jtx.build.dir}/xmls"/>
<arg value="-dumpenums"/>
<arg file="${cs2jtx.build.dir}/enums.xml"/>
<arg value="-cheatdir"/>
<arg file="${cheats.dir}"/>
<arg value="-netdir"/>
<arg file="${cs2j.dir}"/>
<arg value="-exnetdir"/>
<arg file="${cs2j.dir}/build.xml"/>
<arg value="-appdir"/>
<arg file="${cs.app.dir}"/>
<arg value="-odir"/>
<arg file="${java.output.dir}"/>
<arg file="${cs.tx.dir}" />
</dn:dotnetexec>
</target>
<target name="echoTranslateCS2J" depends="" description="echo run translator command line">
<echo>
"${cs2jtx.exe} -dumpxml -odir ${java.output.dir} -netdir ${cs2j.dir} -appdir ${cs.app.dir} -cheatdir ${cheats.dir} ${cs.tx.dir}"
</echo>
</target>
<target name="dumpProperties" description="output all set properties, a useful sanity check">
<echoproperties />
</target>
<target name="init" depends="">
<mkdir dir="${cs2jtx.build.dir}" />
</target>
<target name="clean" depends="" description="clean out build area">
<!-- create dir if it doesn't exist, so delete only fails if there is a real problem -->
<mkdir dir="${cs2jtx.build.dir}"/>
<delete failonerror="true" dir="${cs2jtx.build.dir}" />
</target>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,146 @@
GNU Lesser General Public License
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.]
Preamble
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things.
To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others.
Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs.
When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library.
We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances.
For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system.
Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.
(For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.
In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.
Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.
If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things:
a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.
e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.
7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above.
b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License.
11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS

Binary file not shown.

Binary file not shown.