<?xml version="1.0"?>

<st-source>
<!-- 
Name: CADSM-Modelica
HideSource: false
PackageName: CADSM-Modelica
Parcel: #('cadsmmodelica')
SaveSource: true
Date: 9:16:36 am June 5, 2007
 -->
<time-stamp>From VisualWorks®, 7.5 of April 16, 2007 on June 5, 2007 at 9:16:36 am</time-stamp>


<do-it>(Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned.  Choose terminate or close.']</do-it>

<class>
<name>Item</name>
<environment>CADSM.Modelica</environment>
<super>Core.Object</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars></inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>CADSM-Modelica</category>
<attributes>
<package>CADSM-Modelica</package>
</attributes>
</class>

<class>
<name>Package</name>
<environment>CADSM.Modelica</environment>
<super>CADSM.Modelica.Item</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars></inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>CADSM-Modelica</category>
<attributes>
<package>CADSM-Modelica</package>
</attributes>
</class>

<class>
<name>Connector</name>
<environment>CADSM.Modelica</environment>
<super>CADSM.Modelica.Item</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars></inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>CADSM-Modelica</category>
<attributes>
<package>CADSM-Modelica</package>
</attributes>
</class>

<class>
<name>Modelica</name>
<environment>CADSM.Modelica</environment>
<super>CADSM.Modelica.Item</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>cModel aTime hasChanged aSolver </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>CADSM-Modelica</category>
<attributes>
<package>CADSM-Modelica</package>
</attributes>
</class>

<class>
<name>Parser</name>
<environment>CADSM.Modelica</environment>
<super>Kernel.ExternalLanguageParser</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars></inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>CADSM-Modelica</category>
<attributes>
<package>CADSM-Modelica</package>
</attributes>
</class>

<class>
<name>AnyClass</name>
<environment>CADSM.Modelica</environment>
<super>CADSM.Modelica.Item</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars></inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>CADSM-Modelica</category>
<attributes>
<package>CADSM-Modelica</package>
</attributes>
</class>

<class>
<name>Model</name>
<environment>CADSM.Modelica</environment>
<super>CADSM.Modelica.AnyClass</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars></inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>CADSM-Modelica</category>
<attributes>
<package>CADSM-Modelica</package>
</attributes>
</class>

<class>
<name>Class</name>
<environment>CADSM.Modelica</environment>
<super>CADSM.Modelica.AnyClass</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars></inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>CADSM-Modelica</category>
<attributes>
<package>CADSM-Modelica</package>
</attributes>
</class>

<methods>
<class-id>CADSM.Modelica.Parser</class-id> <category>accessing</category>

<body package="CADSM-Modelica" selector="modelica">modelica =
	stored_definition</body>
</methods>

<methods>
<class-id>CADSM.Modelica.Parser</class-id> <category>BNF</category>

<body package="CADSM-Modelica" selector="add_op">add_op =
	$+
	| $-</body>

<body package="CADSM-Modelica" selector="algorithm">algorithm =
	(@ component_reference ($: $= expression | function_call) 
	| @ $( output_expression_list $) $: $= component_reference function_call
	| break
	| return
	| conditional_equation_a
	| for_clause_a
	| while_clause
	| when_clause_a)
	comment</body>

<body package="CADSM-Modelica" selector="algorithm_clause">algorithm_clause =
	(#initial |) #algorithm (algorithm $; | annotation $;)*</body>

<body package="CADSM-Modelica" selector="annotation">annotation =
	#annotation class_modification</body>

<body package="CADSM-Modelica" selector="argument">argument =
	element_modification_or_replaceable | element_redeclaration</body>

<body package="CADSM-Modelica" selector="argument_list">argument_list =
	argument ($, argument)*</body>

<body package="CADSM-Modelica" selector="arithmetic_expression">arithmetic_expression =
	(add_op |) term (add_op term)*</body>

<body package="CADSM-Modelica" selector="array_subscripts">array_subscripts =
	$[ subscript ($, subscript)* $]</body>

<body package="CADSM-Modelica" selector="base_prefix">base_prefix =
	type_prefix</body>

<body package="CADSM-Modelica" selector="class_definition">class_definition =
	(#encapsulated |)
	(#partial |)
	(#class
	| #model [self halt].
	| #record
	| #block
	| @ (#expandable |) #connector
	| #type
	| #package
	| #function)
	class_specifier</body>

<body package="CADSM-Modelica" selector="class_modification">class_modification =
	$( (argument_list |) $)</body>

<body package="CADSM-Modelica" selector="class_specifier">class_specifier =
	@ IDENT string_comment composition #end IDENT
	| @ IDENT $= base_prefix name (array_subscripts |) (class_modification |) comment
	| @ IDENT $= #enumeration $( ((enum_list |) | $:) $) comment
	| @ IDENT $= #der $( name $, IDENT ($, IDENT)* $) comment
	| #extends IDENT (class_modification |) string_comment composition #end IDENT</body>

<body package="CADSM-Modelica" selector="comment">comment =
	string_comment (annotation |)</body>

<body package="CADSM-Modelica" selector="component_clause">component_clause =
	type_prefix type_specifier (array_subscripts |) component_list</body>

<body package="CADSM-Modelica" selector="component_clause1">component_clause1 =
	type_prefix type_specifier component_declaration1</body>

<body package="CADSM-Modelica" selector="component_declaration">component_declaration =
	declaration (conditional_attribute |) comment</body>

<body package="CADSM-Modelica" selector="component_declaration1">component_declaration1 =
	declaration comment</body>

<body package="CADSM-Modelica" selector="component_list">component_list =
	component_declaration ($, component_declaration)*</body>

<body package="CADSM-Modelica" selector="component_reference">component_reference =
	IDENT (array_subscripts |) ($. component_reference |)</body>

<body package="CADSM-Modelica" selector="composition">composition =
	element_list
	(#public element_list | #protected element_list | equation_clause | algorithm_clause)*
	(#external (language_specification |) (external_function_call |) (annotation $; |) (annotation $; |) |)</body>

<body package="CADSM-Modelica" selector="conditional_attribute">conditional_attribute =
	#if expression</body>

<body package="CADSM-Modelica" selector="conditional_equation_a">conditional_equation_a =
	#if expression #then
		(algorithm $;)*
	(#elseif expression then
		(algorithm $;)*
	)*
	(#else
		(algorithm $;)*
	|)
	#end #if</body>

<body package="CADSM-Modelica" selector="conditional_equation_e">conditional_equation_e =
	#if expression #then
		(equation $;)*
	(#elseif expression #then
		(equation $;)*
	)*
	(@ #else
		(equation $;)*
	|)
	#end #if</body>

<body package="CADSM-Modelica" selector="connect_clause">connect_clause =
	#connect $( component_reference $, component_reference $)</body>

<body package="CADSM-Modelica" selector="constraining_clause">constraining_clause =
	#extends name (class_modification |)</body>

<body package="CADSM-Modelica" selector="declaration">declaration =
	IDENT (array_subscripts |) (modification |)</body>

<body package="CADSM-Modelica" selector="element">element =
	import_clause | extends_clause 
	| (#redeclare |) (#final |) (#inner |) (#outer |) 
		((class_definition | component_clause) 
			| #replaceable (class_definition | component_clause) (constraining_clause comment |))</body>

<body package="CADSM-Modelica" selector="element_list">element_list =
	(@ element $; | annotation $;)*</body>

<body package="CADSM-Modelica" selector="element_modification">element_modification =
	component_reference (modification |) string_comment</body>

<body package="CADSM-Modelica" selector="element_modification_or_replaceable">element_modification_or_replaceable =
	(#each |) (#final |) (element_modification | element_replaceable)</body>

<body package="CADSM-Modelica" selector="element_redeclaration">element_redeclaration =
	redeclare (each |) (final |)
	((class_definition | component_clause1) | element_replaceable)</body>

<body package="CADSM-Modelica" selector="element_replaceable">element_replaceable =
	replaceable (class_definition | component_clause1)
	(constraining_clause |)</body>

<body package="CADSM-Modelica" selector="enumeration_literal">enumeration_literal = 
	IDENT comment</body>

<body package="CADSM-Modelica" selector="enum_list">enum_list =
	enumeration_literal ($, enumeration_literal)*</body>

<body package="CADSM-Modelica" selector="equation">equation =
	(@ simple_expression $= expression
	| conditional_equation_e
	| for_clause_e
	| connect_clause
	| when_clause_e
	| IDENT function_call)
	comment</body>

<body package="CADSM-Modelica" selector="equation_clause">equation_clause =
	(#initial |) #equation (equation $; | annotation $;)*</body>

<body package="CADSM-Modelica" selector="expression">expression =
	simple_expression
	| #if expression #then expression 
		(#elseif expression #then expression)* 
		#else expression</body>

<body package="CADSM-Modelica" selector="expression_list">expression_list =
	expression ($, expression)*</body>

<body package="CADSM-Modelica" selector="extends_clause">extends_clause =
	#extends name (class_modification |) (annotation |)</body>

<body package="CADSM-Modelica" selector="external_function_call">external_function_call =
	(@ component_reference $= |)
	IDENT $( (expression ($, expression)* |) $)</body>

<body package="CADSM-Modelica" selector="factor">factor =
	primary ($^ primary |)</body>

<body package="CADSM-Modelica" selector="for_clause_a">for_clause_a =
	#for for_indices loop
		(algorithm $;)*
	#end #for</body>

<body package="CADSM-Modelica" selector="for_clause_e">for_clause_e =
	#for for_indices loop
		(equation $;)*
	#end #for</body>

<body package="CADSM-Modelica" selector="for_index">for_index =
	IDENT (#in expression |)</body>

<body package="CADSM-Modelica" selector="for_indices">for_indices =
	for_index ($, for_index)*</body>

<body package="CADSM-Modelica" selector="function_arguments">function_arguments =
	expression ($, function_arguments | for for_indices |)
	| named_arguments</body>

<body package="CADSM-Modelica" selector="function_call">function_call =
	$( (function_arguments |) $)</body>

<body package="CADSM-Modelica" selector="IDENT">IDENT
	^(tokenType == #word and: [token isString]) 
		ifTrue: 
			[self scanToken.
			true]
		ifFalse: [false]</body>

<body package="CADSM-Modelica" selector="import_clause">import_clause =
	#import (@ IDENT $= name | name ($. $* |) ) comment</body>

<body package="CADSM-Modelica" selector="language_specification">language_specification =
	STRING</body>

<body package="CADSM-Modelica" selector="logical_expression">logical_expression =
	logical_term (#or logical_term)*</body>

<body package="CADSM-Modelica" selector="logical_factor">logical_factor =
	(#not |) relation</body>

<body package="CADSM-Modelica" selector="logical_term">logical_term =
	logical_factor (#and logical_factor)*</body>

<body package="CADSM-Modelica" selector="modification">modification =
	@ class_modification ($= expression |)
	| @ $= expression
	| $: $= expression</body>

<body package="CADSM-Modelica" selector="mul_op">mul_op =
	$*
	| $/</body>

<body package="CADSM-Modelica" selector="name">name =
	IDENT ($. name |)</body>

<body package="CADSM-Modelica" selector="named_argument">named_argument = 
	IDENT $= expression</body>

<body package="CADSM-Modelica" selector="named_arguments">named_arguments =
	named_argument ($, named_arguments |)</body>

<body package="CADSM-Modelica" selector="output_expression_list">output_expression_list =
	(expression |) ($, (expression |))*</body>

<body package="CADSM-Modelica" selector="primary">primary =
	UNSIGNED_NUMBER
	| STRING
	| #false
	| #true
	| #der [self halt]. $( name ($, IDENT)* $)
	| component_reference (function_call |)
	| $( output_expression_list $)
	| $[ expression_list ($; expression_list)* $]
	| ${ function_arguments $}
	| #end</body>

<body package="CADSM-Modelica" selector="relation">relation =
	arithmetic_expression (rel_op arithmetic_expression |)</body>

<body package="CADSM-Modelica" selector="rel_op">rel_op =
	$&lt; 
	| @ $&lt; $= 
	| $&gt; 
	| @ $&gt; $= 
	| @ $= $= 
	| $&lt; $&gt;</body>

<body package="CADSM-Modelica" selector="simple_expression">simple_expression =
	logical_expression ($: logical_expression ($: logical_expression |) |)</body>

<body package="CADSM-Modelica" selector="stored_definition">stored_definition =
	(#within (name |) $; |)
	((#final |) class_definition $;) *</body>

<body package="CADSM-Modelica" selector="STRING">STRING
	"Taken care by default action."

	^false</body>

<body package="CADSM-Modelica" selector="string_comment">string_comment =
	(STRING ($+ STRING)* |)</body>

<body package="CADSM-Modelica" selector="subscript">subscript =
	$: | expression</body>

<body package="CADSM-Modelica" selector="term">term =
	factor (mul_op factor)*</body>

<body package="CADSM-Modelica" selector="type_prefix">type_prefix =
	(#flow |) 
	(#discrete | #parameter [self halt]. | #constant |) 
	(#input | #output |)</body>

<body package="CADSM-Modelica" selector="type_specifier">type_specifier =
	name</body>

<body package="CADSM-Modelica" selector="UNSIGNED_NUMBER">UNSIGNED_NUMBER
	^(tokenType == #number and: [token isReal]) 
		ifTrue: 
			[self scanToken.
			true]
		ifFalse: [false]</body>

<body package="CADSM-Modelica" selector="when_clause_a">when_clause_a =
	#when expression #then
		(algorithm $;)*
	(#elsewhen expression #then
		(algorithm $;)*
	)*
	#end #when</body>

<body package="CADSM-Modelica" selector="when_clause_e">when_clause_e =
	#when expression #then
		(equation $;)*
	(#elsewhen expression #then
		(equation $;)*
	)*
	#end #when</body>

<body package="CADSM-Modelica" selector="while_clause">while_clause =
	#while expression #loop
		(algorithm $;)*
	#end #while</body>

<body package="CADSM-Modelica" selector="xSlash">xSlash
	"Check for comment with // and /* */."

	| cr |
	cr := Character cr.
	source peek = $/ 
		ifTrue: [source skipThrough: cr]
		ifFalse: [source peek = $* ifTrue: [source skipThrough: $/]].
	hereChar := source next.
	self scanToken</body>
</methods>

<methods>
<class-id>CADSM.Modelica.Parser class</class-id> <category>examples</category>

<body package="CADSM-Modelica" selector="example1">example1
	"self example1."

	| filepath readStream stack |
	filepath := (Filename fromComponents: #('Modelica_2_2' 'Examples')) 
				construct: 'VanDerPol.mo'.
	readStream := filepath readStream.
	
	[stack := CADSM.Modelica.Parser 
				parse: readStream contents cleanSourceFromSelf
				as: #stored_definition.
	stack last inspect] 
			valueNowOrOnUnwindDo: [readStream close]</body>
</methods>

<methods>
<class-id>CADSM.Modelica.Parser class</class-id> <category>private</category>

<body package="CADSM-Modelica" selector="computeTables">computeTables
	"self computeTables."

	super computeTables.
	typeTable at: $/ asInteger put: #xSlash</body>
</methods>

<do-it>"Imported Classes:"</do-it>

<do-it>self error: 'Attempting to file-in parcel imports.  Choose terminate or close'</do-it>

<class>
<name>Object</name>
<environment>Core</environment>
<super></super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars></inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>Kernel-Objects</category>
<attributes>
<package>Kernel-Objects</package>
</attributes>
</class>

<class>
<name>ExternalLanguageParser</name>
<environment>Kernel</environment>
<super>Kernel.GeneralParser</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars></inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>AT-ParserCompiler</category>
<attributes>
<package>AT Parser Compiler</package>
</attributes>
</class>

</st-source>
