2 * Translator from Modelica 2.x to flat Modelica
4 * Copyright (C) 2005 - 2007 Imagine S.A.
5 * For more information or commercial use please contact us at www.amesim.com
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 (** Modelica language lexer. *)
25 (** Implementation based on {i Modelica language specification 2.0 } *)
29 (** Modelica lexer. *)
31 (** Implementation based on {i Modelica language specification 2.0 } *)
35 let check_reserved = function
36 | "algorithm" -> ALGORITHM
38 | "annotation" -> ANNOTATION
42 | "connect" -> CONNECT
43 | "connector" -> CONNECTOR
44 | "constant" -> CONSTANT
45 | "discrete" -> DISCRETE
49 | "elsewhen" -> ELSEWHEN
50 | "encapsulated" -> ENCAPSULATED
51 | "enumeration" -> ENUMERATION
53 | "equation" -> EQUATION
54 | "expandable" -> EXPANDABLE
55 | "extends" -> EXTENDS
56 | "external" -> EXTERNAL
61 | "function" -> FUNCTION
69 | "noEvent" -> NOEVENT
74 | "package" -> PACKAGE
75 | "parameter" -> PARAMETER
76 | "partial" -> PARTIAL
77 | "protected" -> PROTECTED
80 | "redeclare" -> REDECLARE
81 | "replaceable" -> REPLACEABLE
82 | "restricts" -> RESTRICTS
94 let blank = [' ' '\t' '\r']
96 let nondigit = ['_' 'A'-'Z' 'a'-'z']
97 let qchar = [^'`' '\\']
98 let schar = [^'\"' '\\']
99 let sescape = "\\\'" | "\\\"" | "\\?" | "\\\\" | "\\a" | "\\b" | "\\f" |
100 "\\n" | "\\r" | "\\t" | "\\v"
102 let comment = "/*" ( [^ '*'] | '*'+ [^ '*' '/'] )* '*'+ '/'
103 let line_comment = "//" [^ '\n']* '\n'
105 let separators = (blank | ['\n'] | comment | line_comment)+
107 let qident = '`' (qchar | sescape)+ '`'
109 let ident = nondigit (nondigit | digit)* | qident
111 let unsigned_integer = digit+
113 let fractional_constant = unsigned_integer? '.' unsigned_integer | unsigned_integer '.'
115 let exponent_part = ('e' | 'E') ('+' | '-')? unsigned_integer
117 let unsigned_real = fractional_constant exponent_part? | unsigned_integer exponent_part
134 | unsigned_integer as lxm
135 { UNSIGNED_INTEGER lxm }
137 | unsigned_real as lxm
138 { UNSIGNED_REAL lxm }
140 | "initial" separators "algorithm"
141 { INITIAL_ALGORITHM }
143 | "initial" separators "equation"
146 | "end" separators "for"
149 | "end" separators "if"
152 | "end" separators "when"
155 | "end" separators "while"
158 | "end" separators (ident as lxm)
162 { check_reserved lxm }
164 | '\"' ((schar | sescape)* as lxm) '\"'
197 | _ { raise (SyntacticError
198 {err_msg = ["_IllegalCharacter"];
201 {location = {start = Lexing.lexeme_start lexbuf;
202 enddd = Lexing.lexeme_end lexbuf;
203 filename = !inputfile}}}) }