2 * Translator from Modelica 2.x to flat Modelica
\r
4 * Copyright (C) 2005 - 2007 Imagine S.A.
\r
5 * For more information or commercial use please contact us at www.amesim.com
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 2
\r
10 * of the License, or (at your option) any later version.
\r
12 * This program is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 * GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with this program; if not, write to the Free Software
\r
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
25 * Grammar for the Modelica language v2.2
\r
32 (** Modelica parser. *)
\r
34 (** Implementation based on {i Modelica language specification 2.0 } *)
\r
38 exception Unclosed of int * string * int * string
\r
39 exception Invalid_matrix of int * int
\r
40 exception Invalid_array of int * int
\r
41 exception End_of_file
\r
45 start: int; (* offset in the parsed stream *)
\r
46 enddd: int; (* offset in the parsed stream *)
\r
51 | LibraryFile of string
\r
54 type error_description =
\r
56 err_msg: string list;
\r
57 err_info: (string * string) list;
\r
66 exception SyntacticError of error_description
\r
68 let inputfile = ref CommandLine
\r
73 info = { start = Parsing.symbol_start ();
\r
74 enddd = Parsing.symbol_end ();
\r
75 filename = !inputfile }
\r
78 let rhs_nodes n n' nature =
\r
81 info = { start = Parsing.rhs_start n;
\r
82 enddd = Parsing.rhs_end n';
\r
83 filename = !inputfile }
\r
86 let unclosed opening_symbol opening_pos closing_symbol closing_pos =
\r
87 let offset = Parsing.rhs_start opening_pos
\r
88 and offset' = Parsing.rhs_start closing_pos in
\r
89 raise (Unclosed (offset, opening_symbol, offset', closing_symbol))
\r
91 let invalid_matrix_construction opening_pos error_pos =
\r
92 raise (Invalid_matrix (
\r
93 Parsing.rhs_start opening_pos, Parsing.rhs_start error_pos))
\r
95 let invalid_literal_array_construction opening_pos error_pos =
\r
96 raise (Invalid_array (
\r
97 Parsing.rhs_start opening_pos, Parsing.rhs_start error_pos))
\r
102 %token <string> IDENT END_IDENT
\r
105 %token <string> UNSIGNED_INTEGER UNSIGNED_REAL STRING
\r
108 %token ALGORITHM AND ANNOTATION BLOCK BREAK CLASS CONNECT CONNECTOR CONSTANT
\r
109 %token DISCRETE EACH ELSE ELSEIF ELSEWHEN ENCAPSULATED END
\r
110 %token END_IF END_FOR END_WHEN END_WHILE
\r
111 %token ENUMERATION EQUATION EXPANDABLE
\r
112 %token EXTENDS EXTERNAL FALSE FINAL FLOW FOR FUNCTION IF IMPORT IN
\r
113 %token INITIAL_ALGORITHM INITIAL_EQUATION
\r
114 %token INNER INPUT LOOP MODEL NOT NOEVENT OR OUTER OUTPUT
\r
115 %token PACKAGE PARAMETER PARTIAL
\r
116 %token PROTECTED PUBLIC RECORD REDECLARE REPLACEABLE RESTRICTS RETURN
\r
117 %token THEN TRUE TYPE WHEN WHILE WITHIN
\r
120 %token LP RP LSB RSB LCB RCB /* ( ) [ ] { } */
\r
121 %token DOT CM SC CL /* . , ; : */
\r
122 %token PLUS MINUS STAR SLASH EXP /* + - * / ^ */
\r
123 %token EQ COLEQ /* = := */
\r
124 %token LT GT LE GE EE NE /* < > <= >= == <> */
\r
129 %type <(location Syntax.toplevel_element_desc, location) Syntax.node> definition
\r
137 : class_definitions
\r
138 { node (ClassDefinitions (List.rev $1)) }
\r
139 | toplevel_expression SC
\r
142 { node (Within []) }
\r
143 | WITHIN within_name SC
\r
144 { node (Within (List.rev $2)) }
\r
146 { node (Import $1) }
\r
148 { raise End_of_file }
\r
152 : FINAL class_definition SC
\r
153 { [node (ClassDefinition (Some Final, $2))] }
\r
154 | class_definition SC
\r
155 { [node (ClassDefinition (None, $1))] }
\r
156 | class_definitions FINAL class_definition SC
\r
157 { node (ClassDefinition (Some Final, $3)) :: $1 }
\r
158 | class_definitions class_definition SC
\r
159 { node (ClassDefinition (None, $2)) :: $1 }
\r
161 toplevel_expression
\r
163 { node (Expression $1) }
\r
164 | component_reference component_list
\r
165 { match $1.nature with
\r
166 | IndexedAccess (type_spec_node, subscripts_node) ->
\r
167 node (VariablesDefinitions (type_spec_node, Some subscripts_node, (List.rev $2)))
\r
169 node (VariablesDefinitions (rhs_nodes 1 1 type_spec, None, (List.rev $2))) }
\r
170 | component_reference COLEQ expression
\r
171 { node (Command (node (Assign ($1, $3)))) }
\r
172 | LP expression_list RP COLEQ component_reference LP RP
\r
173 { node (Command (node (MultipleAssign ($2, $5, None)))) }
\r
174 | LP expression_list RP COLEQ component_reference LP function_arguments RP
\r
175 { node (Command (node (MultipleAssign ($2, $5, Some $7)))) }
\r
176 | LP expression_list RP COLEQ component_reference LP function_arguments
\r
178 { unclosed "(" 6 ")" 8 }
\r
179 | LP expression_list RP COLEQ component_reference LP error
\r
180 { unclosed "(" 6 ")" 7 }
\r
182 { node (Command (node Break)) }
\r
184 { node (Command (node Return)) }
\r
185 | conditional_equation_a
\r
186 { node (Command (node $1)) }
\r
188 { node (Command (node $1)) }
\r
190 { node (Command (node $1)) }
\r
192 { node (Command (node $1)) }
\r
198 | within_name DOT IDENT
\r
204 : encapsulated_option partial_option class_type class_specifier
\r
205 { node (Definition ($1, $2, $3, $4)) }
\r
217 | EXPANDABLE CONNECTOR
\r
218 { ExpandableConnector }
\r
229 encapsulated_option
\r
233 { Some Encapsulated }
\r
244 : IDENT string_comment composition END_IDENT
\r
245 { if $1 <> $4 then unclosed $1 1 $1 4
\r
246 else node (LongSpecifier ($1, $2, $3)) }
\r
247 | IDENT EQ base_prefix name array_subscripts_option class_modification_option
\r
249 { node (ShortSpecifier ($1, $3, $4, $5, $6, $7)) }
\r
250 | IDENT EQ ENUMERATION LP enum_composition_option RP comment
\r
251 { node (EnumerationSpecifier ($1, rhs_nodes 5 5 $5, $7)) }
\r
252 | IDENT EQ ENUMERATION LP enum_composition_option error
\r
253 { unclosed "(" 4 ")" 6 }
\r
254 | EXTENDS IDENT class_modification_option string_comment composition END_IDENT
\r
255 { if $2 <> $6 then unclosed $2 2 $2 6
\r
256 else node (ExtensionSpecifier ($2, $3, $4, $5)) }
\r
264 enum_composition_option
\r
273 { EnumList (Some (List.rev $1)) }
\r
279 : enumeration_literal
\r
281 | enum_list CM enumeration_literal
\r
285 enumeration_literal
\r
287 { node (EnumerationLiteral ($1, $2)) }
\r
291 : other_lists external_option
\r
292 { node (Composition ([], List.rev $1, $2)) }
\r
293 | element_list other_lists external_option
\r
294 { node (Composition (List.rev $1, List.rev $2, $3)) }
\r
300 | other_lists PUBLIC element_list
\r
301 { rhs_nodes 2 3 (Public (List.rev $3)) :: $1 }
\r
302 | other_lists PROTECTED element_list
\r
303 { rhs_nodes 2 3 (Protected (List.rev $3)) :: $1 }
\r
304 | other_lists equation_clause
\r
305 { rhs_nodes 2 2 $2 :: $1 }
\r
306 | other_lists algorithm_clause
\r
307 { rhs_nodes 2 2 $2 :: $1 }
\r
313 | EXTERNAL language_specification_option
\r
314 external_function_call_option SC
\r
315 annotation_sc_option
\r
316 { Some (node (External ($2, $3, None, $5))) }
\r
317 | EXTERNAL language_specification_option
\r
318 external_function_call_option annotation SC
\r
319 annotation_sc_option
\r
320 { Some (node (External ($2, $3, Some $4, $6))) }
\r
330 annotation_sc_option
\r
337 language_specification_option
\r
344 external_function_call_option
\r
348 { Some (node (ExternalFunctionCall (None, $1, []))) }
\r
349 | IDENT LP expressions RP
\r
350 { Some (node (ExternalFunctionCall (None, $1, $3))) }
\r
351 | IDENT LP expressions error
\r
352 { unclosed "(" 2 ")" 4 }
\r
354 { unclosed "(" 2 ")" 3 }
\r
355 | component_reference EQ IDENT LP RP
\r
356 { Some (node (ExternalFunctionCall (Some $1, $3, []))) }
\r
357 | component_reference EQ IDENT LP expressions RP
\r
358 { Some (node (ExternalFunctionCall (Some $1, $3, $5))) }
\r
359 | component_reference EQ IDENT LP expressions error
\r
360 { unclosed "(" 4 ")" 6 }
\r
361 | component_reference EQ IDENT LP error
\r
362 { unclosed "(" 4 ")" 5 }
\r
368 | expression CM expressions
\r
372 array_subscripts_option
\r
379 class_modification_option
\r
382 | class_modification
\r
388 { [node (ClassAnnotation $1)] }
\r
389 | import_clause SC annotation_sc_option
\r
390 { [node (ImportClause ($1, $3))] }
\r
391 | extends_clause SC annotation_sc_option
\r
392 { [node (ExtendsClause ($1, $3))] }
\r
393 | redeclare_option final_option dynamic_scope_option
\r
394 element_definition SC annotation_sc_option
\r
395 { [node (ElementDefinition ($1, $2, $3, $4, $6))] }
\r
396 | element_list import_clause SC annotation_sc_option
\r
397 { rhs_nodes 2 3 (ImportClause ($2, $4)) :: $1 }
\r
398 | element_list extends_clause SC annotation_sc_option
\r
399 { rhs_nodes 2 3 (ExtendsClause ($2, $4)) :: $1 }
\r
400 | element_list redeclare_option final_option dynamic_scope_option
\r
401 element_definition SC annotation_sc_option
\r
402 { rhs_nodes 2 5 (ElementDefinition ($2, $3, $4, $5, $7)) :: $1 }
\r
407 { node (ClassDefinitionElement (None, $1, [])) }
\r
409 { node (ComponentClauseElement (None, $1, [])) }
\r
410 | REPLACEABLE class_definition
\r
411 { node (ClassDefinitionElement (Some Replaceable, $2, [])) }
\r
412 | REPLACEABLE class_definition constraining_clauses
\r
413 { node (ClassDefinitionElement (Some Replaceable, $2, List.rev $3)) }
\r
414 | REPLACEABLE component_clause
\r
415 { node (ComponentClauseElement (Some Replaceable, $2, [])) }
\r
416 | REPLACEABLE component_clause constraining_clauses
\r
417 { node (ComponentClauseElement (Some Replaceable, $2, List.rev $3)) }
\r
434 dynamic_scope_option
\r
442 { Some InnerOuter }
\r
446 : IMPORT IDENT EQ name comment
\r
447 { node (NewIdentifier ($2, $4, $5)) }
\r
448 | IMPORT name comment
\r
449 { node (OldIdentifier ($2, $3)) }
\r
450 | IMPORT name DOT STAR comment
\r
451 { node (AllIdentifiers ($2, $5)) }
\r
454 constraining_clauses
\r
455 : constraining_clause
\r
457 | constraining_clauses constraining_clause
\r
463 : EXTENDS name class_modification_option annotation_option
\r
464 { node (Extends ($2, $3, $4)) }
\r
467 constraining_clause
\r
468 : EXTENDS name class_modification_option comment
\r
469 { node (Constraint (Extension, $2, $3, $4)) }
\r
470 | RESTRICTS name class_modification_option comment
\r
471 { node (Constraint (Restriction, $2, $3, $4)) }
\r
476 : type_prefix type_specifier array_subscripts_option component_list
\r
477 { node (ComponentClause ($1, $2, $3, List.rev $4)) }
\r
481 : flow_option variability_option inout_option
\r
482 { node (TypePrefix ($1, $2, $3)) }
\r
518 : component_declaration
\r
520 | component_list CM component_declaration
\r
524 component_declaration
\r
525 : declaration comment
\r
526 { node (ComponentDeclaration ($1, $2)) }
\r
530 : IDENT array_subscripts_option modification_option
\r
531 { node (Declaration ($1, $2, $3)) }
\r
534 modification_option
\r
543 : class_modification EQ expression
\r
544 { node (Modification ($1, Some $3)) }
\r
545 | class_modification
\r
546 { node (Modification ($1, None)) }
\r
550 { node (ColEq $2) }
\r
555 { node (ClassModification []) }
\r
556 | LP argument_list RP
\r
557 { node (ClassModification (List.rev $2)) }
\r
558 | LP argument_list error
\r
559 { unclosed "(" 1 ")" 3 }
\r
561 { unclosed "(" 1 ")" 2 }
\r
567 | argument CM argument_list
\r
572 : element_modification
\r
574 | element_redeclaration
\r
578 element_modification
\r
579 : each_option final_option component_reference modification_option
\r
581 { node (ElementModification ($1, $2, $3, $4, $5)) }
\r
591 element_redeclaration
\r
592 : REDECLARE each_option final_option class_definition_or_component_clause1
\r
593 { node (ElementRedeclaration ($2, $3, $4)) }
\r
596 class_definition_or_component_clause1
\r
598 { node (ClassDefinitionElement (None, $1, [])) }
\r
599 | type_prefix type_specifier component_declaration
\r
600 { let cpnt = node (ComponentClause ($1, $2, None, [$3])) in
\r
601 node (ComponentClauseElement (None, cpnt, [])) }
\r
602 | REPLACEABLE class_definition
\r
603 { node (ClassDefinitionElement (Some Replaceable, $2, [])) }
\r
604 | REPLACEABLE class_definition constraining_clauses
\r
605 { node (ClassDefinitionElement (Some Replaceable, $2, List.rev $3)) }
\r
606 | REPLACEABLE type_prefix type_specifier
\r
607 component_declaration
\r
608 { let cpnt = node (ComponentClause ($2, $3, None, [$4])) in
\r
609 node (ComponentClauseElement (Some Replaceable, cpnt, [])) }
\r
610 | REPLACEABLE type_prefix type_specifier
\r
611 component_declaration constraining_clauses
\r
612 { let cpnt = node (ComponentClause ($2, $3, None, [$4])) in
\r
613 node (ComponentClauseElement (Some Replaceable, cpnt, List.rev $5)) }
\r
619 { EquationClause (Some Initial, []) }
\r
620 | INITIAL_EQUATION equations
\r
621 { EquationClause (Some Initial, List.rev $2) }
\r
623 { EquationClause (None, []) }
\r
624 | EQUATION equations
\r
625 { EquationClause (None, List.rev $2) } ;
\r
628 : equation comment SC annotation_sc_option
\r
629 { [node (Equation (rhs_nodes 1 3 $1, $2, $4))] }
\r
630 | equations equation comment SC annotation_sc_option
\r
631 { rhs_nodes 2 5 (Equation (rhs_nodes 2 4 $2, $3, $5)) :: $1 }
\r
635 : INITIAL_ALGORITHM
\r
636 { AlgorithmClause (Some Initial, []) }
\r
637 | INITIAL_ALGORITHM algorithms
\r
638 { AlgorithmClause (Some Initial, List.rev $2) }
\r
640 { AlgorithmClause (None, []) }
\r
641 | ALGORITHM algorithms
\r
642 { AlgorithmClause (None, List.rev $2) }
\r
646 : algorithm comment SC annotation_sc_option
\r
647 { [node (Algorithm (rhs_nodes 1 3 $1, $2, $4))] }
\r
648 | algorithms algorithm comment SC annotation_sc_option
\r
649 { rhs_nodes 2 5 (Algorithm (rhs_nodes 2 4 $2, $3, $5)) :: $1 }
\r
653 : simple_expression EQ expression
\r
655 | conditional_equation_e
\r
663 | component_reference LP RP
\r
664 { FunctionCallE ($1, None) }
\r
665 | component_reference LP function_arguments RP
\r
666 { FunctionCallE ($1, Some $3) }
\r
667 | component_reference LP function_arguments error
\r
668 { unclosed "(" 2 ")" 4 }
\r
669 | component_reference LP error
\r
670 { unclosed "(" 2 ")" 3 }
\r
674 : component_reference COLEQ expression
\r
675 { Assign ($1, $3) }
\r
676 | component_reference LP RP
\r
677 { FunctionCallA ($1, None) }
\r
678 | component_reference LP function_arguments RP
\r
679 { FunctionCallA ($1, Some $3) }
\r
680 | component_reference LP function_arguments error
\r
681 { unclosed "(" 2 ")" 4 }
\r
682 | component_reference LP error
\r
683 { unclosed "(" 2 ")" 3 }
\r
684 | LP expression_list RP COLEQ component_reference LP RP
\r
685 { MultipleAssign ($2, $5, None) }
\r
686 | LP RP COLEQ component_reference LP RP
\r
687 { MultipleAssign ([], $4, None) }
\r
688 | LP expression_list RP COLEQ component_reference LP function_arguments RP
\r
689 { MultipleAssign ($2, $5, Some $7) }
\r
690 | LP RP COLEQ component_reference LP function_arguments RP
\r
691 { MultipleAssign ([], $4, Some $6) }
\r
692 | LP expression_list RP COLEQ component_reference LP function_arguments
\r
694 { unclosed "(" 6 ")" 8 }
\r
695 | LP RP COLEQ component_reference LP function_arguments error
\r
696 { unclosed "(" 5 ")" 7 }
\r
697 | LP expression_list RP COLEQ component_reference LP error
\r
698 { unclosed "(" 6 ")" 7 }
\r
699 | LP RP COLEQ component_reference LP error
\r
700 { unclosed "(" 5 ")" 6 }
\r
701 | LP expression_list error
\r
702 { unclosed "(" 1 ")" 3 }
\r
704 { unclosed "(" 1 ")" 2 }
\r
709 | conditional_equation_a
\r
719 conditional_equation_e
\r
720 : IF expression THEN
\r
722 else_if_expressions_e
\r
725 { ConditionalEquationE (($2, List.rev $4) :: $5, $6) }
\r
728 else_if_expressions_e
\r
731 | ELSEIF expression THEN
\r
733 else_if_expressions_e
\r
734 { ($2, List.rev $4) :: $5 }
\r
741 { Some (List.rev $2) }
\r
747 | equations_e equation SC
\r
748 { rhs_nodes 2 3 $2 :: $1 }
\r
751 conditional_equation_a
\r
752 : IF expression THEN
\r
754 else_if_expressions_a
\r
757 { ConditionalEquationA (($2, List.rev $4) :: $5, $6) }
\r
760 else_if_expressions_a
\r
763 | ELSEIF expression THEN
\r
765 else_if_expressions_a
\r
766 { ($2, List.rev $4) :: $5 }
\r
772 | ELSE algorithms_a
\r
773 { Some (List.rev $2) }
\r
779 | algorithms_a algorithm SC
\r
780 { rhs_nodes 2 3 $2 :: $1 }
\r
784 : FOR for_indices LOOP
\r
787 { ForClauseE ($2, List.rev $4) }
\r
791 : FOR for_indices LOOP
\r
794 { ForClauseA ($2, List.rev $4) }
\r
800 | for_index CM for_indices
\r
807 | IDENT IN expression
\r
812 : WHILE expression LOOP
\r
815 { WhileClause ($2, List.rev $4) }
\r
819 : WHEN expression THEN
\r
821 else_when_expressions_e
\r
823 { WhenClauseE (($2, List.rev $4) :: $5) }
\r
827 : WHEN expression THEN
\r
829 else_when_expressions_a
\r
831 { WhenClauseA (($2, List.rev $4) :: $5) }
\r
834 else_when_expressions_e
\r
837 | ELSEWHEN expression THEN
\r
839 else_when_expressions_e
\r
840 { ($2, List.rev $4) :: $5 }
\r
843 else_when_expressions_a
\r
846 | ELSEWHEN expression THEN
\r
848 else_when_expressions_a
\r
849 { ($2, List.rev $4) :: $5 }
\r
853 : CONNECT LP component_reference CM component_reference RP
\r
854 { ConnectClause ($3, $5) }
\r
855 | CONNECT LP component_reference CM component_reference error
\r
856 { unclosed "(" 2 ")" 6 }
\r
861 : simple_expression
\r
863 | IF expression THEN expression
\r
866 { node (If (($2, $4) :: $5, $7)) }
\r
872 | ELSEIF expression THEN expression
\r
878 : logical_expression
\r
880 | logical_expression CL logical_expression
\r
881 { node (Range ($1, None, $3)) }
\r
882 | logical_expression CL logical_expression CL logical_expression
\r
883 { node (Range ($1, Some $3, $5)) }
\r
889 | logical_expression OR logical_term
\r
890 { node (BinaryOperation (rhs_nodes 2 2 Or, $1, $3)) }
\r
896 | logical_term AND logical_factor
\r
897 { node (BinaryOperation (rhs_nodes 2 2 And, $1, $3)) }
\r
904 { node (UnaryOperation (rhs_nodes 1 1 Not, $2)) }
\r
908 : arithmetic_expression
\r
910 | arithmetic_expression LT arithmetic_expression
\r
911 { node (BinaryOperation (rhs_nodes 2 2 Less, $1, $3)) }
\r
912 | arithmetic_expression GT arithmetic_expression
\r
913 { node (BinaryOperation (rhs_nodes 2 2 Greater, $1, $3)) }
\r
914 | arithmetic_expression LE arithmetic_expression
\r
915 { node (BinaryOperation (rhs_nodes 2 2 LessEqual, $1, $3)) }
\r
916 | arithmetic_expression GE arithmetic_expression
\r
917 { node (BinaryOperation (rhs_nodes 2 2 GreaterEqual, $1, $3)) }
\r
918 | arithmetic_expression EE arithmetic_expression
\r
919 { node (BinaryOperation (rhs_nodes 2 2 EqualEqual, $1, $3)) }
\r
920 | arithmetic_expression NE arithmetic_expression
\r
921 { node (BinaryOperation (rhs_nodes 2 2 NotEqual, $1, $3)) }
\r
924 arithmetic_expression
\r
927 | arithmetic_expression PLUS term
\r
928 { node (BinaryOperation (rhs_nodes 2 2 Plus, $1, $3)) }
\r
929 | arithmetic_expression MINUS term
\r
930 { node (BinaryOperation (rhs_nodes 2 2 Minus, $1, $3)) }
\r
936 | term STAR unary_factor
\r
937 { node (BinaryOperation (rhs_nodes 2 2 Times, $1, $3)) }
\r
938 | term SLASH unary_factor
\r
939 { node (BinaryOperation (rhs_nodes 2 2 Divide, $1, $3)) }
\r
945 | PLUS unary_factor
\r
946 { node (UnaryOperation (rhs_nodes 1 1 UnaryPlus, $2)) }
\r
947 | MINUS unary_factor
\r
948 { node (UnaryOperation (rhs_nodes 1 1 UnaryMinus, $2)) }
\r
953 | factor EXP primary
\r
954 { node (BinaryOperation (rhs_nodes 2 2 Power, $1, $3)) }
\r
959 { node (Integer $1) }
\r
963 { node (String $1) }
\r
968 | NOEVENT LP expression RP
\r
969 { node (NoEvent $3) }
\r
970 | component_reference
\r
972 | component_reference LP RP
\r
973 { node (FunctionCall ($1, None)) }
\r
974 | component_reference LP function_arguments RP
\r
975 { node (FunctionCall ($1, Some $3)) }
\r
976 | component_reference LP function_arguments error
\r
977 { unclosed "(" 2 ")" 4 }
\r
978 | component_reference LP error
\r
979 { unclosed "(" 2 ")" 3 }
\r
980 | LP expression_list RP
\r
982 | [expr] -> node expr.Syntax.nature
\r
983 | _ -> node (Tuple $2) }
\r
984 | LP expression_list error
\r
985 { unclosed "(" 1 ")" 3 }
\r
986 | LSB expression_lists RSB
\r
987 { node (MatrixConstruction $2) }
\r
989 { invalid_matrix_construction 1 2 }
\r
990 | LCB vector_elements RCB
\r
991 { node (Vector $2) }
\r
993 { invalid_literal_array_construction 1 2 }
\r
1001 | expression_list SC expression_lists
\r
1006 : expression FOR for_indices
\r
1007 { node (VectorReduction ($1, $3)) }
\r
1009 { node (VectorElements $1) }
\r
1014 { node (Identifier $1) }
\r
1016 { node (FieldAccess ($1, $3)) }
\r
1019 component_reference
\r
1021 { node (Identifier $1) }
\r
1022 | IDENT array_subscripts
\r
1023 { node (IndexedAccess (rhs_nodes 1 1 (Identifier $1), $2)) }
\r
1024 | component_reference DOT IDENT
\r
1025 { node (FieldAccess ($1, $3)) }
\r
1026 | component_reference DOT IDENT array_subscripts
\r
1027 { node (IndexedAccess (rhs_nodes 1 3 (FieldAccess ($1, $3)), $4)) }
\r
1030 function_arguments
\r
1031 : function_arguments_elements
\r
1032 { node (ArgumentList (List.rev $1)) }
\r
1033 | expression FOR for_indices
\r
1034 { node (Reduction ($1, $3)) }
\r
1037 function_arguments_elements
\r
1039 { [node (Argument $1)] }
\r
1042 | function_arguments_elements CM expression
\r
1043 { node (Argument $3) :: $1 }
\r
1044 | function_arguments_elements CM named_argument
\r
1049 : IDENT EQ expression
\r
1050 { node (NamedArgument ($1, $3)) }
\r
1052 { failwith "Not yet implemented" }
\r
1053 | FUNCTION IDENT LP RP
\r
1054 { failwith "Not yet implemented" }
\r
1055 | FUNCTION IDENT LP function_arguments RP
\r
1056 { failwith "Not yet implemented" }
\r
1057 | FUNCTION IDENT LP function_arguments error
\r
1058 { unclosed "(" 3 ")" 5 }
\r
1059 | FUNCTION IDENT LP error
\r
1060 { unclosed "(" 3 ")" 4 }
\r
1066 | expression CM expression_list
\r
1071 : LSB subscripts RSB
\r
1072 { node (Subscripts $2) }
\r
1078 | subscript CM subscripts
\r
1086 { node (Subscript $1) }
\r
1090 : string_comment annotation_option
\r
1091 { node (Comment ($1, $2)) }
\r
1104 | strings PLUS STRING
\r
1109 : ANNOTATION class_modification
\r
1110 { node (Annotation $2) }
\r
1115 let parse filename token_fun lexbuf =
\r
1116 inputfile := filename;
\r
1118 definition token_fun lexbuf
\r
1120 | Unclosed (pos, symbol, pos', symbol') ->
\r
1121 raise (SyntacticError
\r
1122 {err_msg = ["_Unclosed"; symbol];
\r
1125 {location = {start = pos;
\r
1127 filename = filename}}})
\r
1128 | Invalid_matrix (pos, pos') ->
\r
1129 raise (SyntacticError
\r
1130 {err_msg = ["_InvalidMatrixConstruct"];
\r
1133 {location = {start = pos;
\r
1135 filename = filename}}})
\r
1136 | Invalid_array (pos, pos') ->
\r
1137 raise (SyntacticError
\r
1138 {err_msg = ["_InvalidArrayConstruct"];
\r
1141 {location = {start = pos;
\r
1143 filename = filename}}})
\r
1144 | Parsing.Parse_error ->
\r
1145 raise (SyntacticError
\r
1146 {err_msg = ["_SyntaxError"];
\r
1149 {location = {start = Lexing.lexeme_start lexbuf;
\r
1150 enddd = Lexing.lexeme_end lexbuf;
\r
1151 filename = filename}}})
\r