diff --git a/.bzrignore b/.bzrignore index 5abcec0f98fa1bde1d50a5733178e6bfb3df1fa6..ee56d8e3e3242e1cc21141f328dae3709eb32b82 100644 --- a/.bzrignore +++ b/.bzrignore @@ -157,3 +157,4 @@ examples/actors/xdfAST/XmlParserVisitor.java examples/actors/xdfAST/XsiNoNamespaceSchemaLocation.java examples/actors/xdfAST/xdf.jj examples/actors/xlimAST/xlim.jj +examples/scxml/scxml.jjt diff --git a/CompilerGeneration.jrag b/CompilerGeneration.jrag index 30dc7d0689ed567e9f057bc150557a3268010ac8..73cd76c148cc21d6ac31dca84d8af7676a53edb7 100644 --- a/CompilerGeneration.jrag +++ b/CompilerGeneration.jrag @@ -39,11 +39,13 @@ aspect AbsGrammarGeneration { pStream.println("abstract Element;"); pStream.println("ComplexElement : Element ::= Attribute* Element*;"); pStream.println("ValueElement : ComplexElement;"); + pStream.println("__DefaultElement__ : ComplexElement ::= <TAG>;"); pStream.println("abstract SimpleElement : Element;"); pStream.println("StringElement : SimpleElement ::= <LITERAL>;"); pStream.println("IntElement : SimpleElement ::= <LITERAL>;"); pStream.println("FloatElement : SimpleElement ::= <LITERAL>;"); pStream.println("Attribute ::= AttrValue;"); + pStream.println("__DefaultAttribute__ : Attribute ::= <NAME>;"); pStream.println("AttrValue ::= <LITERAL>;"); pStream.println("Encoding : Attribute ::=;"); pStream.println("Version : Attribute ::=;"); @@ -154,7 +156,7 @@ aspect GenJavaCC { pStream.println(); pStream.println("void AttributeList() #List : {}"); pStream.println("{"); - pStream.println(" (Attribute())*"); + pStream.println(" (LOOKAHEAD(2) Attribute())*"); pStream.println("}"); pStream.println(); pStream.println("void AttrValue() #AttrValue : { Token t; }"); @@ -193,6 +195,7 @@ aspect GenJavaCC { while (iter.hasNext()) { pStream.println(" | "+fixName(((XsElement) iter.next()).name())+"()"); } + pStream.println(" | __DefaultElement__() "); pStream.println(" )) "); pStream.println(" | SimpleElement()"); pStream.println("}"); @@ -227,6 +230,18 @@ aspect GenJavaCC { pStream.println(" }"); pStream.println(" {jjtThis.setLITERAL(s);}"); pStream.println("}"); + pStream.println("void __DefaultElement__() #__DefaultElement__ : { Token t;String s; }"); + pStream.println("{"); + pStream.println(" t = <IDENTIFIER> AttributeList()"); + pStream.println(" (\">\" ElementList() \"</\" <IDENTIFIER> \">\" | ElementList() \"/>\")"); + pStream.println(" {"); + pStream.println(" s = t.image;"); + pStream.println(" if (getToken(1).kind != GT ) {"); + pStream.println(" s += getData();"); + pStream.println(" }"); + pStream.println(" }"); + pStream.println(" {jjtThis.setTAG(s);}"); + pStream.println("}"); pStream.println("void Attribute() : {}"); pStream.println("{"); pStream.println(" Encoding()"); @@ -237,10 +252,17 @@ aspect GenJavaCC { while (iter.hasNext()) { pStream.println(" | "+fixName(((XsAttribute) iter.next()).name())+"()"); } + pStream.println(" | __DefaultAttribute__() "); pStream.println(" "); pStream.println("}"); pStream.println(); + pStream.println("void __DefaultAttribute__() # __DefaultAttribute__ : {Token t;}"); + pStream.println("{"); + pStream.println(" t=<IDENTIFIER> \"=\" AttrValue()"); + pStream.println(" {jjtThis.setNAME(t.image);}"); + pStream.println("}"); + // This is somewhat of a hack, but seems to work work as an // easy way to eliminate duplicate attribute // declarations. Anders Nilsson 070808. @@ -383,6 +405,9 @@ aspect Misc { } static final String[] ASTNode.forbiddenNames = {"Attribute", + "else", + "final", + "if", "to"}; static String ASTNode.fixName(String s) { diff --git a/examples/scxml/Fixes.jrag b/examples/scxml/Fixes.jrag new file mode 100644 index 0000000000000000000000000000000000000000..233072e5718c675ac7b83985322a9853218ae0fe --- /dev/null +++ b/examples/scxml/Fixes.jrag @@ -0,0 +1,16 @@ +/* -*-Java-*- */ + +/* + * Copyright (C) 2009 Anders Nilsson <anders.nilsson@cs.lth.se> + * + * This file is part of ScXml compiler. + */ + + + +aspect Fixes { + int ASTNode.numChildren; + int ASTNode.numChildren() {return jjtGetNumChildren();} + int List.getNumNoTransformChild() {return getNumChildNoTransform();} + int Opt.getNumChildNoTransfrom() {return getNumChildNoTransform();} +} \ No newline at end of file diff --git a/examples/scxml/build.xml b/examples/scxml/build.xml new file mode 100644 index 0000000000000000000000000000000000000000..3475fb35cd056bc0d3dca4ff1e68c268fa8a3b02 --- /dev/null +++ b/examples/scxml/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="xmlCompiler" default="build" basedir="."> + + <!-- "package" is the directory where generated files will be stored --> + <property name="package" value="AST"/> + + <!-- "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/** siaras/**" 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="scxml.jjt" + outputdirectory="${package}" + javacchome="${javacc.home}" + buildnodefiles="true" + static="false" + multi="true" + visitor="true" + nodedefaultvoid="true" + nodeprefix='""' + nodepackage="${package}" + /> + <javacc + target="${package}/scxml.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/scxml/scxml.ast b/examples/scxml/scxml.ast index 5dea732709c6cfa8ec91b7cc277e5ff51f0c6730..b72543688883136f9834abd055484454bd1afeb8 100644 --- a/examples/scxml/scxml.ast +++ b/examples/scxml/scxml.ast @@ -10,11 +10,13 @@ abstract Thing : ComplexElement ::=; abstract Element; ComplexElement : Element ::= Attribute* Element*; ValueElement : ComplexElement; +__DefaultElement__ : ComplexElement ::= <TAG>; abstract SimpleElement : Element; StringElement : SimpleElement ::= <LITERAL>; IntElement : SimpleElement ::= <LITERAL>; FloatElement : SimpleElement ::= <LITERAL>; Attribute ::= AttrValue; +__DefaultAttribute__ : Attribute ::= <NAME>; AttrValue ::= <LITERAL>; Encoding : Attribute ::=; Version : Attribute ::=; @@ -22,32 +24,39 @@ XmlnsXsi : Attribute ::=; XsiNoNamespaceSchemaLocation : Attribute ::=; // Generated types -level : Attribute ::= ; -initial : Attribute ::= ; -expr : Attribute ::= ; -final : ComplexElement ::= ; -profile : Attribute ::= ; -type : Attribute ::= ; +target : Attribute ::= ; +initialstate : Attribute ::= ; +parallel : ComplexElement ::= ; +exit : ComplexElement ::= ; +next : Attribute ::= ; +log : ComplexElement ::= ; +transition : ComplexElement ::= ; +join : ComplexElement ::= ; +bound : Attribute ::= ; +sync : ComplexElement ::= ; onexit : ComplexElement ::= ; -state : ComplexElement ::= ; +history : ComplexElement ::= ; +name : Attribute ::= ; +_else : ComplexElement ::= ; src : Attribute ::= ; -anchor : Attribute ::= ; -log : ComplexElement ::= ; -label : Attribute ::= ; -maxstale : Attribute ::= ; +var : ComplexElement ::= ; +scxml : ComplexElement ::= ; +send : ComplexElement ::= ; +delay : Attribute ::= ; +_if : ComplexElement ::= ; onentry : ComplexElement ::= ; -cond : Attribute ::= ; -history : ComplexElement ::= ; -elseif : ComplexElement ::= ; -if : ComplexElement ::= ; -Fetchtimeout : Attribute ::= ; +_final : Attribute ::= ; id : Attribute ::= ; -maxage : Attribute ::= ; +elseif : ComplexElement ::= ; +label : Attribute ::= ; +expr : Attribute ::= ; +hints : Attribute ::= ; +cond : Attribute ::= ; +assign : ComplexElement ::= ; +namelist : Attribute ::= ; +initial : ComplexElement ::= ; +sendid : Attribute ::= ; +targettype : Attribute ::= ; event : Attribute ::= ; -else : ComplexElement ::= ; -transition : ComplexElement ::= ; -scxml : ComplexElement ::= ; -exmode : Attribute ::= ; -parallel : ComplexElement ::= ; -target : Attribute ::= ; -name : Attribute ::= ; +state : ComplexElement ::= ; +type : Attribute ::= ;