123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190(****************************************************************************)(* *)(* This file is part of MOPSA, a Modular Open Platform for Static Analysis. *)(* *)(* Copyright (C) 2019 The MOPSA Project. *)(* *)(* This program is free software: you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License as published *)(* by the Free Software Foundation, either version 3 of the License, or *)(* (at your option) any later version. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this program. If not, see <http://www.gnu.org/licenses/>. *)(* *)(****************************************************************************)(**
Definition of the abstract syntax trees output by the parser.
*)openMopsa_utilsopenLexing(* extents are ranges *)typeextent=Location.range(* Many parts of the syntax are tagged with an extent indicating which
part of the parser-file corresponds to the sub-tree.
This is very useful for interesting error reporting!
*)type'aext='a*extent(* variable identifiers, just strings *)(* local variables and scoping would require using UNIQUE IDENTIFIERS
to handle the case where several variables have the same name
*)typevar=string(* types *)typetyp=AST_INT|AST_REAL|AST_ARRAYoftyp|AST_STRING|AST_CHAR(* unary expression operators *)typeunary_op=|AST_UNARY_PLUS(* +e *)|AST_UNARY_MINUS(* -e *)|AST_NOT(* !e logical negation *)|AST_ROUND(* round *)(* binary expression operators *)typebinary_op=|AST_PLUS(* e + e *)|AST_MINUS(* e - e *)|AST_MULTIPLY(* e * e *)|AST_DIVIDE(* e / e *)|AST_EQUAL(* e == e *)|AST_NOT_EQUAL(* e != e *)|AST_LESS(* e < e *)|AST_LESS_EQUAL(* e <= e *)|AST_GREATER(* e > e *)|AST_GREATER_EQUAL(* e >= e *)|AST_AND(* e && e *)|AST_OR(* e || e *)|AST_CONCAT(* e @ e *)(* expressions *)andexpr=(* unary operation *)|AST_unaryofunary_op*(exprext)(* length of an array or a string *)|AST_lenof(exprext)(* binary operation *)|AST_binaryofbinary_op*(exprext)*(exprext)(* variable use *)|AST_identifierofvarext(* integer constants (integers are still in their string representation) *)|AST_int_constofstringext(* unit constant *)|AST_unit_const(* boolean constants *)|AST_bool_constofboolext(* real constants (reals are still in their string representation) *)|AST_real_constofstringext(* string constants *)|AST_string_constofstringext(* char constants *)|AST_char_constofcharext(* array construction *)|AST_array_constof(exprext)arrayext(* non-deterministic choice between two integers *)|AST_randof(stringext)(* lower bound *)*(stringext)(* upper bound *)(* non-deterministic choice between two floats *)|AST_randfof(stringext)(* lower bound *)*(stringext)(* upper bound *)(* non-deterministic string *)|AST_rand_string(* array accesses *)|AST_array_accessof(exprext*exprext)(* function call *)|AST_fun_callofvarext*exprextlisttypetyped_var=(typ*var)exttypedeclaration=(typed_var*exprextoption)(* statements *)typestat=|AST_blockof(statext)list(* assignment of integer expression: e1 = e2 *)|AST_assignof(exprext)*(exprext)(* if-then-else, with boolean condition;
the else branch is optional
*)|AST_ifof(exprext)(* condition *)*(statext)(* then branch *)*(statextoption)(* optional else *)(* while loop, with boolean condition *)|AST_whileof(exprext)(* condition *)*(statext)(* body *)|AST_forof(varext*exprext*exprext*statext)|AST_returnof(exprext)option|AST_break|AST_continue(* assertion: exit if the boolean expression does not hold *)|AST_assertofexprext(* assume: assume the boolean expression holds in the rest of the program *)|AST_assumeofexprext(* evaluates expression (useful for function calls) *)|AST_exprofexprext|AST_printtypefundec={funname:var;parameters:typed_varlist;body:statext;locvars:declarationextlist;return_type:typoption;range:extent;}(* a program is a list of statements preceded by function declaration *)typeprog={gvars:declarationextlist;funs:fundecextlist;main:statext}