diff --git a/.bzrignore b/.bzrignore index 68c2c268aa93816fc9b57bbe4d64e5bd9c8ab87f..4a1becb484b6458853ddc2d1d6dcb947ebaaab77 100644 --- a/.bzrignore +++ b/.bzrignore @@ -21,3 +21,5 @@ Parser.java PrettyPrint.java xdf.ast xdf.jjt +examples/actors/xdf/xdfAST +examples/actors/xlim/xlimAST diff --git a/examples/xdf/build.xml b/examples/actors/xdf/build.xml similarity index 93% rename from examples/xdf/build.xml rename to examples/actors/xdf/build.xml index 41249901045fa39ccb2c2c6139bca52246ff9977..21d3502ddeb45198d9cd603635b7e285775a88cd 100644 --- a/examples/xdf/build.xml +++ b/examples/actors/xdf/build.xml @@ -9,12 +9,12 @@ <project name="XDF compiler" default="build" basedir="."> <!-- "package" is the directory where generated files will be stored --> - <property name="package" value="AST"/> + <property name="package" value="xdfAST"/> <!-- "tools" is the directory where generators and libraries are located. --> - <property name="tools" value="../../tools"/> + <property name="tools" value="../../../tools"/> - <property name="javacc.home" value="../../tools/javacc-4.0"/> + <property name="javacc.home" value="${tools}/javacc-4.0"/> <property name="parser.name" value="XmlParser"/> @@ -23,7 +23,7 @@ <!-- "beaver" is an ant task class for the parser generator in beaver.jar --> <!-- <taskdef name="beaver" classname="beaver.comp.run.AntTask" classpath="tools/beaver.jar"/> --> <!-- "jastadd" is an ant task class in jastadd2.jar --> - <taskdef name="jastadd" classname="jastadd.JastAddTask" classpath="../../tools/jastadd2.jar"/> + <taskdef name="jastadd" classname="jastadd.JastAddTask" classpath="${tools}/jastadd2.jar"/> <!-- compile sources --> <target name="build" depends="gen"> diff --git a/examples/xdf/sdftest.xdf b/examples/actors/xdf/sdftest.xdf similarity index 100% rename from examples/xdf/sdftest.xdf rename to examples/actors/xdf/sdftest.xdf diff --git a/examples/xdf/xdf.xsd b/examples/actors/xdf/xdf.xsd similarity index 100% rename from examples/xdf/xdf.xsd rename to examples/actors/xdf/xdf.xsd diff --git a/examples/actors/xlim/build.xml b/examples/actors/xlim/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..e8c77ad63cccb27f000d94a30088b3373d780557 --- /dev/null +++ b/examples/actors/xlim/build.xml @@ -0,0 +1,113 @@ +<!-- + Targets for working from terminal window: + build (default) - generates java files and compiles them + clean - removes all generated files and class files + Targets for working from Eclipse: + gen - generates java files + genClean - removes all generated files and their class files + --> +<project name="XLIM compiler" default="build" basedir="."> + + <!-- "package" is the directory where generated files will be stored --> + <property name="package" value="xlimAST"/> + + <!-- "tools" is the directory where generators and libraries are located. --> + <property name="tools" value="../../../tools"/> + + <property name="javacc.home" value="${tools}/javacc-4.0"/> + + <property name="parser.name" value="XmlParser"/> + + <!-- "jflex" is an ant task class for the scanner generator in JFlex.jar --> +<!-- <taskdef name="jflex" classname="JFlex.anttask.JFlexTask" classpath="tools/JFlex.jar"/> --> + <!-- "beaver" is an ant task class for the parser generator in beaver.jar --> +<!-- <taskdef name="beaver" classname="beaver.comp.run.AntTask" classpath="tools/beaver.jar"/> --> + <!-- "jastadd" is an ant task class in jastadd2.jar --> + <taskdef name="jastadd" classname="jastadd.JastAddTask" classpath="${tools}/jastadd2.jar"/> + + <!-- compile sources --> + <target name="build" depends="gen"> + <javac debug="true" nowarn="true" srcdir="." includes="**/*.java" excludes="tools/**" classpath=".:${tools}/beaver-rt.jar:${tools}/junit.jar"/> + </target> + + <!-- generate compiler source files --> + <target name="gen" description="Generate compiler source files"> + <!-- create AST node types and weave aspect modules --> + <echo message = "Running JastAdd"/> +<!-- <jastadd package="${package}" rewrite="true" beaver="true" novisitcheck="true"> --> + <jastadd package="${package}" grammar="${parser.name}" rewrite="true" jjtree="true"> + <fileset dir="."> + <include name="*.ast"/> + <include name="*.jrag"/> + <include name="*.jadd"/> + </fileset> + </jastadd> + <jjtree + target="xlim.jjt" + outputdirectory="${package}" + javacchome="${javacc.home}" + buildnodefiles="true" + static="false" + multi="true" + visitor="true" + nodedefaultvoid="true" + nodeprefix='""' + nodepackage="${package}" + /> + <javacc + target="${package}/xlim.jj" + outputdirectory="${package}" + javacchome="${javacc.home}" + buildparser="true" + buildtokenmanager="true" + static="false" + /> + + <!-- generate the scanner --> +<!-- <echo message = "Running jflex"/> --> +<!-- <jflex file="parser/java14.flex" outdir="parser" nobak="yes"/> --> + <!-- generate the scanner --> +<!-- <jflex file="parser/unicode.flex" outdir="parser" nobak="yes"/> --> + <!-- generate the parser phase 1, create a full .lalr specification from fragments--> +<!-- <echo message = "Running parser phase 1"/> --> +<!-- <concat destfile="parser/JavaParser.all" binary="true"> --> +<!-- <fileset dir="."> --> +<!-- <include name="parser/java14.parser"/> --> +<!-- </fileset> --> +<!-- </concat> --> + <!-- generate the parser phase 2, translating .lalr to .beaver --> +<!-- <java classpath="${tools}/proj.jar:${tools}/beaver-rt.jar" classname="Main"> --> +<!-- <arg line="parser/JavaParser.all parser/JavaParser.beaver"/> --> +<!-- </java> --> + <!-- generate the parser phase 3, translating .beaver to .java --> +<!-- <beaver file="parser/JavaParser.beaver" terminalNames="yes" compress="no" useSwitch="yes"/> --> + </target> + +<!-- <target name="test" depends="build"> --> +<!-- <java classname="GenCompiler" classpath="."> --> +<!-- <arg value="GripperOntology_experimental3.owl" /> --> +<!-- </java> --> +<!-- </target> --> + + <!-- remove generated source files and .class files --> + <target name="clean" depends="cleanGen"> + <!-- delete all .class files recursively --> + <delete> + <fileset dir="." includes="**/*.class" excludes="beaver/*.class"/> + </delete> + </target> + +<!-- <target name="jar" depends="build"> --> +<!-- <jar destfile="X3DCompiler.jar" basedir="." includes="**/*.class" excludes="test/**"> --> +<!-- <manifest> --> +<!-- <attribute name="Main-Class" value="GenOntology"/> --> +<!-- </manifest> --> +<!-- </jar> --> +<!-- </target> --> + + <!-- remove generated source files and their .class files --> + <target name="cleanGen"> + <delete dir="${package}"/> + </target> +</project> + diff --git a/examples/actors/xlim/xlim.ast b/examples/actors/xlim/xlim.ast new file mode 100644 index 0000000000000000000000000000000000000000..71561e87ef6c59d748d47866a8a95faf01d35f5c --- /dev/null +++ b/examples/actors/xlim/xlim.ast @@ -0,0 +1,47 @@ +// -*-Java-*- + +// Automatically generated JastAdd abstract grammar file +// Predefined types +Start ::= Specification; +Specification ::= XmlHeader [DocType] Element*; +XmlHeader ::= Attribute*; +DocType ::= <STRING>; +abstract Thing : ComplexElement ::=; +abstract Element; +ComplexElement : Element ::= Attribute* Element*; +ValueElement : ComplexElement; +abstract SimpleElement : Element; +StringElement : SimpleElement ::= <LITERAL>; +IntElement : SimpleElement ::= <LITERAL>; +FloatElement : SimpleElement ::= <LITERAL>; +Attribute ::= AttrValue; +AttrValue ::= <LITERAL>; +Encoding : Attribute ::=; +Version : Attribute ::=; +XmlnsXsi : Attribute ::=; +XsiNoNamespaceSchemaLocation : Attribute ::=; + +// Generated types +portName : Attribute ::= ; +module : ComplexElement ::= ; +sourceName : Attribute ::= ; +PHI : ComplexElement ::= ; +kind : Attribute ::= ; +initValue : ComplexElement ::= ; +typeName : Attribute ::= ; +port : ComplexElement ::= ; +decision : Attribute ::= ; +operation : ComplexElement ::= ; +design : ComplexElement ::= ; +stateVar : ComplexElement ::= ; +size : Attribute ::= ; +dir : Attribute ::= ; +source : Attribute ::= ; +value : Attribute ::= ; +actor_port : ComplexElement ::= ; +qualifier : Attribute ::= ; +style : Attribute ::= ; +removable : Attribute ::= ; +autostart : Attribute ::= ; +target : Attribute ::= ; +name : Attribute ::= ; diff --git a/examples/actors/xlim/xlim.jjt b/examples/actors/xlim/xlim.jjt new file mode 100644 index 0000000000000000000000000000000000000000..ca10b33d09d6759b017a3a51d29ba209526a77d1 --- /dev/null +++ b/examples/actors/xlim/xlim.jjt @@ -0,0 +1,445 @@ +/* -*-Java-*- */ + +options { + MULTI = true; + VISITOR = true; + NODE_DEFAULT_VOID = true; + NODE_SCOPE_HOOK = false; + NODE_PREFIX = ""; + JAVA_UNICODE_ESCAPE = true; + STATIC = false; +} + +PARSER_BEGIN(XmlParser) + package xlimAST; + public class XmlParser { +} +PARSER_END(XmlParser) + +//----------------------------------------------// +// LEXICAL TOKENS // +//----------------------------------------------// +<DEFAULT,BOUNDS> SPECIAL_TOKEN : /* WHITE SPACE */ +{ + " " + | + "\t" + | + "\n" + | + "\r" + | + "\f" +}// WHITE SPACE + +<DEFAULT,BOUNDS> SPECIAL_TOKEN : /* COMMENTS */ +{ + < "<!--" ( ~["-"] | ( "-" ~["-"] ) )* "-->"> +}// COMMENTS + +<DEFAULT> TOKEN : /* Reserved Words */ +{ + <XML : "xml"> + | <DOCTYPE : "DOCTYPE"> + | <PUBLIC : "PUBLIC"> + | <encoding : "encoding"> + | <version : "version"> + | <XsiNoNamespaceSchemaLocation : "xsi:noNamespaceSchemaLocation"> + | <XmlnsXsi : "xmlns:xsi"> + | <portName : "portName" > + | <module : "module" > + | <sourceName : "sourceName" > + | <PHI : "PHI" > + | <kind : "kind" > + | <initValue : "initValue" > + | <typeName : "typeName" > + | <port : "port" > + | <decision : "decision" > + | <operation : "operation" > + | <design : "design" > + | <stateVar : "stateVar" > + | <size : "size" > + | <dir : "dir" > + | <source : "source" > + | <value : "value" > + | <actor_port : "actor-port" > + | <qualifier : "qualifier" > + | <style : "style" > + | <removable : "removable" > + | <autostart : "autostart" > + | <target : "target" > + | <name : "name" > +}// Reserved Words + +<DEFAULT, BOUNDS> TOKEN : /* LITERALS */ +{ + < INTEGER_LITERAL: + <DECIMAL_LITERAL> (["l","L"])? + | + <HEX_LITERAL> (["l","L"])? + | + <OCTAL_LITERAL> (["l","L"])? + > + | + < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > + | + < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > + | + < #OCTAL_LITERAL: "0" (["0"-"7"])* > + | + < FLOAT_LITERAL: + (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])? + | + "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])? + | + (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])? + | + (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"] + > + | + < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > + | + < CHARACTER_LITERAL: + "'" + ( (~["'","\\","\n","\r"]) + | + ("\\" + ( ["n","t","b","r","f","\\","'","\""] + | + ["0"-"7"] ( ["0"-"7"] )? + | + ["0"-"3"] ["0"-"7"] ["0"-"7"] + ) + ) + ) + "'" + > + | + < STRING_LITERAL: + ("\"" + ( (~["\"","\n","\r"]) + )* + "\"") + | ("\'" + ( (~["\'","\n","\r"]) + )* + "\'") + > +}// LITERALS +<DEFAULT, BOUNDS> TOKEN : /* IDENTIFIERS */ +{ + < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>|"-")* > + | + < #LETTER: + [ + "\u0024", + "\u0041"-"\u005a", + "\u005f", + "\u0061"-"\u007a", + "\u00c0"-"\u00d6", + "\u00d8"-"\u00f6", + "\u00f8"-"\u00ff", + "\u0100"-"\u1fff", + "\u3040"-"\u318f", + "\u3300"-"\u337f", + "\u3400"-"\u3d2d", + "\u4e00"-"\u9fff", + "\uf900"-"\ufaff" + ] + > + | + < #DIGIT: + [ + "\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", + "\u1040"-"\u1049" + ] + > +}// IDENTIFIERS +<DEFAULT,BOUNDS> TOKEN : /* SEPARATORS */ +{ + < LBRACE : "{" > + | < RBRACE : "}" > + | < LBRACKET : "[" > + | < RBRACKET : "]" > + | < SEMICOLON : ";" > + | < LTSLASH : "</" > : DEFAULT + | < LTBANG : "<!" > : DEFAULT + | < LT : "<" > : DEFAULT + | < LTQ : "<?" > : DEFAULT + | < GT : ">" > : BOUNDS + | < QGT : "?>" > : BOUNDS +}// SEPARATORS +<DEFAULT,BOUNDS> TOKEN : /* OPERATORS */ +{ + < ASSIGN : "=" > +}// OPERATORS +Start Start() #Start : {} +{ + Specification() + { return jjtThis; } +} + +void Specification() #Specification : {} +{ + XmlHeader() + ( [DocType()] ) #Opt(true) + ElementList() +} + +void DocType() #DocType : {String s;} +{ + <LTBANG> + { + s = new String(); + if (getToken(1).kind != GT ) { + s += getData(); + } + } + {jjtThis.setSTRING(s);} +} + +JAVACODE +String getData() { + StringBuffer s = new StringBuffer(); +// jjtThis.someData = true; + while ((getToken(1)).kind != LT && (getToken(1)).kind != LTSLASH) { + Token t = getNextToken(); + if (t.specialToken != null) { + Token tmp_t = t.specialToken; + while (tmp_t.specialToken != null) { + tmp_t = tmp_t.specialToken; + } + while (tmp_t != null) { + s.append(tmp_t.image); + tmp_t = tmp_t.next; + } + } + s.append(t.image); + s.append(" "); + } + return s.toString(); +} + +void XmlHeader() #XmlHeader : {} +{ + <LTQ> <XML> AttributeList() <QGT> +} + +void ElementList() #List : {} +{ + (Element())* +} + +void AttributeList() #List : {} +{ + (Attribute())* +} + +void AttrValue() #AttrValue : { Token t; } +{ + t = <STRING_LITERAL> + {jjtThis.setLITERAL(t.image);} +} + +void Encoding() #Encoding : {} +{ + <encoding> "=" AttrValue() +} + +void Version() #Version : {} +{ + <version> "=" AttrValue() +} + +void XsiNoNamespaceSchemaLocation() #XsiNoNamespaceSchemaLocation : {} +{ + <XsiNoNamespaceSchemaLocation> "=" AttrValue() +} + +void XmlnsXsi() #XmlnsXsi : {} +{ + <XmlnsXsi> "=" AttrValue() +} + +void Element() : {} +{ + ( <LT> ( + port() + | operation() + | actor_port() + | PHI() + | design() + | module() + | initValue() + | stateVar() + )) + | SimpleElement() +} + +void SimpleElement() : {} +{ + IntElement() + | FloatElement() + | StringElement() +} + +void IntElement() #IntElement : { Token t; } +{ + t = <INTEGER_LITERAL> + {jjtThis.setLITERAL(t.image);} +} + +void FloatElement() #FloatElement : { Token t; } +{ + t = <FLOAT_LITERAL> + {jjtThis.setLITERAL(t.image);} +} + +void StringElement() #StringElement : { Token t;String s; } +{ + t = <IDENTIFIER> + { + s = t.image; + if (getToken(1).kind != GT ) { + s += getData(); + } + } + {jjtThis.setLITERAL(s);} +} +void Attribute() : {} +{ + Encoding() + | Version() + | XsiNoNamespaceSchemaLocation() + | XmlnsXsi() + | source() + | style() + | name() + | removable() + | sourceName() + | dir() + | kind() + | portName() + | decision() + | target() + | qualifier() + | typeName() + | value() + | autostart() + | size() + +} + +void portName() #portName : {} +{ + <portName> "=" AttrValue() +} +void module() #module : {} +{ + <module> AttributeList() + ( <GT> ElementList() "</" <module> ">" | ElementList() "/>" ) +} +void sourceName() #sourceName : {} +{ + <sourceName> "=" AttrValue() +} +void PHI() #PHI : {} +{ + <PHI> AttributeList() + ( <GT> ElementList() "</" <PHI> ">" | ElementList() "/>" ) +} +void kind() #kind : {} +{ + <kind> "=" AttrValue() +} +void initValue() #initValue : {} +{ + <initValue> AttributeList() + ( <GT> ElementList() "</" <initValue> ">" | ElementList() "/>" ) +} +void typeName() #typeName : {} +{ + <typeName> "=" AttrValue() +} +void port() #port : {} +{ + <port> AttributeList() + ( <GT> ElementList() "</" <port> ">" | ElementList() "/>" ) +} +void decision() #decision : {} +{ + <decision> "=" AttrValue() +} +void operation() #operation : {} +{ + <operation> AttributeList() + ( <GT> ElementList() "</" <operation> ">" | ElementList() "/>" ) +} +void design() #design : {} +{ + <design> AttributeList() + ( <GT> ElementList() "</" <design> ">" | ElementList() "/>" ) +} +void stateVar() #stateVar : {} +{ + <stateVar> AttributeList() + ( <GT> ElementList() "</" <stateVar> ">" | ElementList() "/>" ) +} +void size() #size : {} +{ + <size> "=" AttrValue() +} +void dir() #dir : {} +{ + <dir> "=" AttrValue() +} +void source() #source : {} +{ + <source> "=" AttrValue() +} +void value() #value : {} +{ + <value> "=" AttrValue() +} +void actor_port() #actor_port : {} +{ + <actor_port> AttributeList() + ( <GT> ElementList() "</" <actor_port> ">" | ElementList() "/>" ) +} +void qualifier() #qualifier : {} +{ + <qualifier> "=" AttrValue() +} +void style() #style : {} +{ + <style> "=" AttrValue() +} +void removable() #removable : {} +{ + <removable> "=" AttrValue() +} +void autostart() #autostart : {} +{ + <autostart> "=" AttrValue() +} +void target() #target : {} +{ + <target> "=" AttrValue() +} +void name() #name : {} +{ + <name> "=" AttrValue() +} diff --git a/examples/xlim.xsd b/examples/xlim.xsd new file mode 100644 index 0000000000000000000000000000000000000000..5d126c8e2ee8a354a87d2ccb4f91141035712d62 --- /dev/null +++ b/examples/xlim.xsd @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> + <xs:element name="design"> + <xs:complexType> + <xs:sequence> + <xs:element maxOccurs="unbounded" ref="actor-port"/> + <xs:choice maxOccurs="unbounded"> + <xs:element ref="module"/> + <xs:element ref="stateVar"/> + </xs:choice> + </xs:sequence> + <xs:attribute name="name" use="required" type="xs:NCName"/> + </xs:complexType> + </xs:element> + <xs:element name="actor-port"> + <xs:complexType> + <xs:attribute name="dir" use="required" type="xs:NCName"/> + <xs:attribute name="name" use="required" type="xs:NCName"/> + <xs:attribute name="size" use="required" type="xs:integer"/> + <xs:attribute name="typeName" use="required" type="xs:NCName"/> + </xs:complexType> + </xs:element> + <xs:element name="stateVar"> + <xs:complexType> + <xs:sequence> + <xs:element ref="initValue"/> + </xs:sequence> + <xs:attribute name="name" use="required"/> + <xs:attribute name="sourceName" type="xs:NCName"/> + </xs:complexType> + </xs:element> + <xs:element name="initValue"> + <xs:complexType> + <xs:sequence> + <xs:element minOccurs="0" ref="initValue"/> + </xs:sequence> + <xs:attribute name="size" type="xs:integer"/> + <xs:attribute name="typeName" use="required" type="xs:NCName"/> + <xs:attribute name="value" type="xs:integer"/> + </xs:complexType> + </xs:element> + <xs:element name="module"> + <xs:complexType> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element ref="module"/> + <xs:element ref="operation"/> + </xs:choice> + <xs:attribute name="autostart" type="xs:boolean"/> + <xs:attribute name="decision"/> + <xs:attribute name="kind" use="required" type="xs:NCName"/> + <xs:attribute name="name" type="xs:NCName"/> + <xs:attribute name="sourceName" type="xs:NCName"/> + </xs:complexType> + </xs:element> + <xs:element name="operation"> + <xs:complexType> + <xs:sequence> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="port"/> + </xs:sequence> + <xs:attribute name="kind" use="required"/> + <xs:attribute name="name"/> + <xs:attribute name="portName" type="xs:NCName"/> + <xs:attribute name="removable" type="xs:NCName"/> + <xs:attribute name="style" type="xs:NCName"/> + <xs:attribute name="target"/> + <xs:attribute name="value" type="xs:integer"/> + </xs:complexType> + </xs:element> + <xs:element name="port"> + <xs:complexType> + <xs:attribute name="dir" use="required" type="xs:NCName"/> + <xs:attribute name="size" type="xs:integer"/> + <xs:attribute name="source" use="required"/> + <xs:attribute name="typeName" type="xs:NCName"/> + <xs:attribute name="qualifier" type="xs:NCName"/> + </xs:complexType> + </xs:element> +<!-- Manually added declarations below --> + <xs:element name="PHI"> + <xs:complexType> + <xs:sequence> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="port"/> + </xs:sequence> + </xs:complexType> + </xs:element> +</xs:schema>