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
23 (** Modelica language lexer. *)
\r
25 (** Implementation based on {i Modelica language specification 2.0 } *)
\r
29 (** Modelica lexer. *)
\r
31 (** Implementation based on {i Modelica language specification 2.0 } *)
\r
35 let check_reserved = function
\r
36 | "algorithm" -> ALGORITHM
\r
38 | "annotation" -> ANNOTATION
\r
42 | "connect" -> CONNECT
\r
43 | "connector" -> CONNECTOR
\r
44 | "constant" -> CONSTANT
\r
45 | "discrete" -> DISCRETE
\r
48 | "elseif" -> ELSEIF
\r
49 | "elsewhen" -> ELSEWHEN
\r
50 | "encapsulated" -> ENCAPSULATED
\r
51 | "enumeration" -> ENUMERATION
\r
53 | "equation" -> EQUATION
\r
54 | "expandable" -> EXPANDABLE
\r
55 | "extends" -> EXTENDS
\r
56 | "external" -> EXTERNAL
\r
61 | "function" -> FUNCTION
\r
63 | "import" -> IMPORT
\r
69 | "noEvent" -> NOEVENT
\r
73 | "output" -> OUTPUT
\r
74 | "package" -> PACKAGE
\r
75 | "parameter" -> PARAMETER
\r
76 | "partial" -> PARTIAL
\r
77 | "protected" -> PROTECTED
\r
78 | "public" -> PUBLIC
\r
79 | "record" -> RECORD
\r
80 | "redeclare" -> REDECLARE
\r
81 | "replaceable" -> REPLACEABLE
\r
82 | "restricts" -> RESTRICTS
\r
83 | "return" -> RETURN
\r
89 | "within" -> WITHIN
\r
94 let blank = [' ' '\t' '\r']
\r
95 let digit = ['0'-'9']
\r
96 let nondigit = ['_' 'A'-'Z' 'a'-'z']
\r
97 let qchar = [^'`' '\\']
\r
98 let schar = [^'\"' '\\']
\r
99 let sescape = "\\\'" | "\\\"" | "\\?" | "\\\\" | "\\a" | "\\b" | "\\f" |
\r
100 "\\n" | "\\r" | "\\t" | "\\v"
\r
102 let comment = "/*" ( [^ '*'] | '*'+ [^ '*' '/'] )* '*'+ '/'
\r
103 let line_comment = "//" [^ '\n']* '\n'
\r
105 let separators = (blank | ['\n'] | comment | line_comment)+
\r
107 let qident = '`' (qchar | sescape)+ '`'
\r
109 let ident = nondigit (nondigit | digit)* | qident
\r
111 let unsigned_integer = digit+
\r
113 let fractional_constant = unsigned_integer? '.' unsigned_integer | unsigned_integer '.'
\r
115 let exponent_part = ('e' | 'E') ('+' | '-')? unsigned_integer
\r
117 let unsigned_real = fractional_constant exponent_part? | unsigned_integer exponent_part
\r
134 | unsigned_integer as lxm
\r
135 { UNSIGNED_INTEGER lxm }
\r
137 | unsigned_real as lxm
\r
138 { UNSIGNED_REAL lxm }
\r
140 | "initial" separators "algorithm"
\r
141 { INITIAL_ALGORITHM }
\r
143 | "initial" separators "equation"
\r
144 { INITIAL_EQUATION }
\r
146 | "end" separators "for"
\r
149 | "end" separators "if"
\r
152 | "end" separators "when"
\r
155 | "end" separators "while"
\r
158 | "end" separators (ident as lxm)
\r
162 { check_reserved lxm }
\r
164 | '\"' ((schar | sescape)* as lxm) '\"'
\r
197 | _ { raise (SyntacticError
\r
198 {err_msg = ["_IllegalCharacter"];
\r
201 {location = {start = Lexing.lexeme_start lexbuf;
\r
202 enddd = Lexing.lexeme_end lexbuf;
\r
203 filename = !inputfile}}}) }
\r