/* 19 Feb 2008 Copied on this date from C:\Dad\XSugar\SimileProlo_SimileML.xsg NEED TO CHECK that this is indeed for SimileXMLv3 25 Feb 2008 Note the use of a MathML namespace prefix for , and then a no-prefix MathML namespace declaration for all child elements. This is as per http://www.w3.org/TR/2001/REC-MathML2-20010221/chapter7.html#interf_embed section 7.1.1 */ xmlns:m = "http://www.w3.org/1998/Math/MathML" /* xmlns = "http://www.simile.com/" */ /* This namespace declaration left out, since I get an error when I include it and a corresponding targetNamespace in the Schema. */ NodeID = "node"[0-9]{5} ArcID = "arc"[0-9]{5} Name = [a-zA-Z]+(\ [a-zA-Z]+|[0-9])* Nodetype = compartment|variable|cloud|function Arctype = flow|influence|role NL = \r\n|\r|\n TrueFalse = true|false Number = "-"[0-9]+"."[0-9]+|"+"[0-9]+"."[0-9]+|[0-9]+"."[0-9]+|[0-9]+|"-"[0-9]+ Coord = "-"[0-9]+"."[0-9]+|"+"[0-9]+"."[0-9]+|[0-9]+"."[0-9]+|[0-9]+|"-"[0-9]+ Descript = * GenericString = * Version = evaluation|standard|enterprise Text = [\ a-zA-Z0-9,\-.\*()\+<>=\/\[\]]* /* ----------------------------------------- MathML declarations ------------------- */ /* Name = [a-zA-Z]+(\ [a-zA-Z]+|[0-9])* Number = "-"[0-9]+"."[0-9]+|"+"[0-9]+"."[0-9]+|[0-9]+"."[0-9]+|[0-9]+|"-"[0-9]+ */ /* This needs to be changed so that standard MathML operators are used (eq, lt, etc) */ RelationalOperator = "=="|"!="|"<="|">="|"<"|">" /* These Boolean operators not currently used */ Booland = and|And|AND Boolor = or|Or|OR Boolxor = xor|Xor|XOR Boolnot = not|Not|NOT Fabs = abs|Abs|ABS Fall = all|All|ALL Fany = any|Any|ANY If = IF|If|if Then = THEN|Then|then Else = ELSE|Else|else Elseif = ELSEIF|Elseif|elseif /* --------------------------------------- End of MathML declarations --------------- */ file : [source S] [NL] [roots Rs] [NL] [properties Ps] [NL] [elements Es] [NL] = [source S] [roots Rs] [properties Ps] [elements Es] /* file : [source S] [NL] [roots Rs] [NL] [properties Ps] [NL] [nodes Ns] [NL] [arcs As] = [source S] [roots Rs] [properties Ps] [nodes Ns] [arcs As] */ /* SOURCE ---------------------------------------------------------------------------*/ /* source(program='AME',version= 8.8,edition=standard,date='Tue May 01 13:32:32 GMT 2007'). */ /* The following works text-->XML, but not in reverse. It complains at the start of the last source_part (even if you remove the fourth one, it complains about the third) source : "source(" [source_parts SPs] ")." = [source_parts SPs] [NL] source_parts : [source_part SP] "," [source_parts SPs] = [source_part SP] [source_parts SPs] source_parts : [source_part SP] = [source_part SP] source_part : "program='AME'" = "AME" source_part : "version=" _ [Number N] = [Number N] source_part : "edition=" [Version V] = [Version V] source_part : "date='" [GenericString D] "'" = [GenericString D] */ source : "source(" [source_program SP] "," [source_version SV] "," [source_edition SE] "," [source_date SD]")." = [source_program SP] [source_version SV] [source_edition SE] [source_date SD] source_program : "program='AME'" = "AME" source_version : "version=" _ [Number N] = [Number N] source_edition : "edition=" [Version V] = [Version V] source_date : "date='" [GenericString D] "'" = [GenericString D] /* ROOTS ------------------------------------------------------------------------------*/ /* roots([node00085,node00086,node00087,node00088,node00089,node00090,node00091,node00092]). */ roots : "roots([" [rootlist Rlist] "])." = [rootlist Rlist] rootlist : [root R] "," [rootlist Rlist] = [root R] [rootlist Rlist] rootlist : [root R] = [root R] root : [NodeID ID] = [NodeID ID] /* PROPERTIES -------------------------------------------------------------------------*/ /* properties([complete-true,name-'LINTUL_RM_interp']). */ properties : "properties([" [propertylist Plist] "])." = [propertylist Plist] propertylist : [property P] "," [propertylist Plist] = [property P ] [propertylist Plist] propertylist : [property P] = [property P] property : "complete-" [TrueFalse TF] = [TrueFalse TF] property : "name-'" [GenericString GS] "'" = [GenericString GS] /* ELEMENTS --------------------------------------------------------------------------*/ elements: [node N] [NL] [elements Es] = [node N] [elements Es] elements: [arc A] [NL] [elements Es] = [arc A] [elements Es] elements: = /* NODES ------------------------------------------------------------------------------*/ /* node(node00110,function,[],[complete=true,description='Rate of increase of the temperature sum, degreeC',name=fn57,spec='DTEFF*EMERG',units=1,value='DTEFF'*'EMERG'],[]). */ node : "node(" [NodeID ID] "," [Nodetype nodetype] ",[]," "[" [nodeAVs nodeAVs] "],[" [nodegraphicAVs nodegraphicAVs] "])." = [nodeAVs nodeAVs] [nodegraphicAVs nodegraphicAVs] /* NODE ATTRIBUTES --------------------------------------------------------------------*/ nodeAVs : [nodeAV nodeAV] "," [nodeAVs nodeAVs] = [nodeAV nodeAV] [nodeAVs nodeAVs] : [nodeAV nodeAV] = [nodeAV nodeAV] : = nodeAV : "comment=" "'" [Text comment] "'" = [Text comment] nodeAV : "complete=" [TrueFalse value] = [TrueFalse value] nodeAV : "description=" "'" [Text descript] "'" = [Text descript] nodeAV : "name=" "'" [Name value] "'" = [Name value] nodeAV : "name=" [Name value] = [Name value] /* This is the link through to the MathML bit. Original (non-MathML) rule is here as a safeguard: nodeAV : "spec='" [Text S] "'" = [Text S] Kept in, as a temporary measure, to catch cases not currently handled by the MathML parser. */ nodeAV : "spec='" [equation Eq] "'" = [equation Eq] nodeAV : "spec='" [Text S] "'" = [Text S] nodeAV : "table_data=[" [GenericString S] "]" = [GenericString S] nodeAV : "units=" [Text U] = [Text U] /* NODE GRAPHICAL ATTRIBUTES ----------------------------------------------------------*/ nodegraphicAVs : [nodegraphicAV nodegraphicAV] "," [nodegraphicAVs nodegraphicAVs] = [nodegraphicAV nodegraphicAV] [nodegraphicAVs nodegraphicAVs] : [nodegraphicAV nodegraphicAV] = [nodegraphicAV nodegraphicAV] : = nodegraphicAV : "bounding_box=" [coords4 coords4] = [coords4 coords4] nodegraphicAV : "caption_offset=" [coords2 coords2] = [coords2 coords2] /* ARCS ------------------------------------------------------------------------------*/ arc : "arc(" [ArcID ID] "," [NodeID FromID] "," [NodeID ToID] "," [Arctype Arctype] ",[" [arcAVs arcAVs] "],[" [arcgraphicAVs arcgraphicAVs] "])." = [arcAVs arcAVs] [arcgraphicAVs arcgraphicAVs] arc : "arc(" [ArcID ID] "," [NodeID FromID] "," [ArcID ToID] "," [Arctype Arctype] ",[" [arcAVs arcAVs] "],[" [arcgraphicAVs arcgraphicAVs] "])." = [arcAVs arcAVs] [arcgraphicAVs arcgraphicAVs] arc : "arc(" [ArcID ID] "," [ArcID FromID] "," [NodeID ToID] "," [Arctype Arctype] ",[" [arcAVs arcAVs] "],[" [arcgraphicAVs arcgraphicAVs] "])." = [arcAVs arcAVs] [arcgraphicAVs arcgraphicAVs] /* arc ATTRIBUTES --------------------------------------------------------------------*/ arcAVs : [arcAV arcAV] "," [arcAVs arcAVs] = [arcAV arcAV] [arcAVs arcAVs] : [arcAV arcAV] = [arcAV arcAV] : = arcAV : "complete=" [TrueFalse value] = [TrueFalse value] arcAV : "name=" "'" [Name value] "'" = [Name value] arcAV : "name=" [Name value] = [Name value] arcAV : "description=" "'" [Descript descript] "'" = [Descript descript] arcAV : "role=[" [uselist Ulist] "]" = [uselist Ulist] /* Example: use(none,in_hierarchy,'GTOTAL',1) */ uselist : [use U] "," [uselist Us] = [use U] [uselist Us] uselist : [use U] = [use U] uselist : = use : "use(none,in_hierarchy,'" [Name Na] "'," [Text Nu] ")" = "none" "in_hierarchy" [Name Na] [Text Nu] /* arc GRAPHICAL ATTRIBUTES ----------------------------------------------------------*/ arcgraphicAVs : [arcgraphicAV arcgraphicAV] "," [arcgraphicAVs arcgraphicAVs] = [arcgraphicAV arcgraphicAV] [arcgraphicAVs arcgraphicAVs] : [arcgraphicAV arcgraphicAV] = [arcgraphicAV arcgraphicAV] : = arcgraphicAV : "course=[" [coords2 coords2] "," [coords2 coords2] "]" = [coords2 coords2] [coords2 coords2] arcgraphicAV : "course=[" [coords2 coords2] "," [coords2 coords2] "," [coords2 coords2] "]" = [coords2 coords2] [coords2 coords2] [coords2 coords2] arcgraphicAV : "caption_offset=" [coords2 coords2] = [coords2 coords2] arcgraphicAV : "bowtie=" [coords4 coords4] = [coords4 coords4] /* COORDS -----------------------------------------------------------------------------*/ coords2 : "[" _ [Coord x1] "," _ [Coord y1] "]" = [Coord x1] [Coord y1] coords4 : "[" _ [Coord x1] "," _ [Coord y1] "," _ [Coord x2] "," _ [Coord y2] "]" = [Coord x1] [Coord y1] [Coord x2] [Coord y2] /* ====================================================================================== ====================================================================================== MathML ====================================================================================== ====================================================================================== */ /* Robert Muetzelfeldt, June 2007 */ /* The original grammar for this maths handler is taken from the Virtual Cell site, http://www.nrcam.uchc.edu/technology/VCML_Grammar.html Integer ::= Expression ::= LogicalORExpression ";" LogicalORExpression ::= ( LogicalANDExpression ( "||" LogicalANDExpression )* ) LogicalANDExpression ::= RelationalExpression ( "&&" RelationalExpression )* RelationalExpression ::= AdditiveExpression ( AdditiveExpression )? AdditiveExpression ::= MultiplicativeExpression ( ( "+" MultiplicativeExpression ) | MinusTerm )* MinusTerm ::= "-" MultiplicativeExpression MultiplicativeExpression ::= UnaryExpression ( ( "*" UnaryExpression ) | DivTerm )* DivTerm ::= "/" UnaryExpression UnaryExpression ::= "+" UnaryExpression | ( "-" UnaryExpression ) | PrimaryExpression PrimaryExpression ::= Function | Name | Float | "(" LogicalORExpression ")" Function ::= Arguments Arguments ::= "(" ( ArgumentList )? ")" ArgumentList ::= LogicalORExpression ( "," LogicalORExpression )* Float ::= | Name ::= */ /* Notes 20 Feb 2008: Changed (incorrect spelling of deprecated ) and deprecated to with , as per MathMl2.0 spec http://www.w3.org/TR/2003/REC-MathML2-20031021/chapter4.html#contm.reln http://www.w3.org/TR/2003/REC-MathML2-20031021/chapter4.html#contm.fn In any case, was filing to validate against the MathML 2.0 Schema. 20 Feb 2008 Using the following Schema spec: 25 Feb 2008: I had tried to extend the explicit list of functions to include all Simile functions. (This involved two entries: a regular expression for the function token, e.g. Fsin = sin|Sin|SIN and the production rule, e.g. functionName : [Fsin fsin] = [Fsin fsin] ) For some undetermined reason, some of the token expressions caused the whole of the MathML parser to fail, for *all* expressions, not just those using that function. This resulted in the output having the fall-back markup, i.e. ... So, I decided notto include explicit function names (since we can assume that the correctness of the model spec is checked elsewhere). *However*, I then found that I needed to include 3 function tokens - no idea why, very strange. */ /* xmlns:m = "http://www.w3.org/1998/Math/MathML" */ /* This is the original top-level element for the MathML bit: file : [expression E] [NL] = [expression E] Now replaced with 'equation'. */ equation : [expression E] = [expression E] expression : [logicalORExpression LORE] _ ":" _ [assignments As] = "where" [logicalORExpression LORE] [assignments As] expression : [logicalORExpression LORE] = [logicalORExpression LORE] assignments : [Name N] _ "=" _ [logicalORExpression LORE] _ "," _ [assignments As] = [Name N] [logicalORExpression LORE] [assignments As] assignments : [Name N] _ "=" _ [logicalORExpression LORE] = [Name N] [logicalORExpression LORE] logicalORExpression : [logicalANDExpression LANDE] __ [Boolor] __ [logicalORExpression LORE] = [logicalANDExpression LANDE] [logicalORExpression LORE] logicalORExpression : [logicalANDExpression LANDE] [Boolxor] [logicalORExpression LORE] = [logicalANDExpression LANDE] [logicalORExpression LORE] logicalORExpression : [logicalANDExpression LANDE] = [logicalANDExpression LANDE] logicalANDExpression : [relationalExpression RE] __ [Booland] __ [logicalANDExpression LANDE] = [relationalExpression RE] [logicalANDExpression LANDE] logicalANDExpression : [relationalExpression RE] = [relationalExpression RE] relationalExpression : [additiveExpression AE1] _ [RelationalOperator RO] _ [additiveExpression AE2] = [RelationalOperator RO] [additiveExpression AE1] [additiveExpression AE2] relationalExpression : [additiveExpression AE] = [additiveExpression AE] additiveExpression : [multiplicativeExpression ME1] _ "+" _ [additiveExpression ME2] = [multiplicativeExpression ME1] [additiveExpression ME2] additiveExpression : [multiplicativeExpression ME1] _ "-" _ [additiveExpression ME2] = [multiplicativeExpression ME1] [additiveExpression ME2] additiveExpression : [multiplicativeExpression ME1] = [multiplicativeExpression ME1] multiplicativeExpression : [powerExpression UE1] _ "*" _ [multiplicativeExpression UE2] = [powerExpression UE1] [multiplicativeExpression UE2] multiplicativeExpression : [powerExpression UE1] _ "/" _ [multiplicativeExpression UE2] = [powerExpression UE1] [multiplicativeExpression UE2] multiplicativeExpression : [powerExpression UE1] = [powerExpression UE1] powerExpression : [unaryExpression UE1] "^" [powerExpression UE2] = [unaryExpression UE1] [powerExpression UE2] powerExpression : [unaryExpression UE1] = [unaryExpression UE1] unaryExpression : "+" [primaryExpression PE] = [primaryExpression PE] unaryExpression : "-" [primaryExpression PE] = [primaryExpression PE] unaryExpression : [primaryExpression PE] = [primaryExpression PE] primaryExpression : [function F] = [function F] primaryExpression : [Name N] = [Name N] primaryExpression : [Number N] = [Number N] primaryExpression : [If] __ [logicalORExpression LOREif] __ [Then] __ [logicalORExpression LOREvalue] [elseExpression EE] = [logicalORExpression LOREvalue] [logicalORExpression LOREif] [elseExpression EE] primaryExpression : _ "(" _ [logicalORExpression LORE] _ ")" _ = [logicalORExpression LORE] /* Comment: The above form of primaryExpression for a bracketted subexpression produces a warning about infinite parse trees for some productions. The form below doesn't, but it adds in an extraneous ... element, which makers it non-valid MathML, and results in failure of MathPlayer to render it properly. primaryExpression : "(" [logicalORExpression LORE] ")" = [logicalORExpression LORE] */ elseExpression : __ [Elseif] __ [logicalORExpression LOREif] __ [Then] __ [logicalORExpression LOREvalue] [elseExpression EE] = [logicalORExpression LOREvalue] [logicalORExpression LOREif] [elseExpression EE] elseExpression : __ [Else] __ [logicalORExpression LOREvalue] = [logicalORExpression LOREvalue] elseExpression : = /* Cut out, due to weird problem with defining function tokens function : [functionName FN] "(" [arguments As] ")" = [functionName FN] [arguments As] */ function : [Name FN] "(" [arguments As] ")" = [Name FN] [arguments As] arguments : [logicalORExpression LORE] = [logicalORExpression LORE] arguments : "[" [array A] "]" = [array A] arguments : [logicalORExpression LORE] "," [arguments As] = [logicalORExpression LORE] [arguments As] arguments : "[" [array A] "]" "," [arguments As] = [array A] [arguments As] array : [logicalORExpression LORE] = [logicalORExpression LORE] array : "[" [array A] "]" = [array A] array : [logicalORExpression LORE] "," [array A] = [logicalORExpression LORE] [array A]