From 97c602041438e9cf1bf4e6dad72af517fa7e0614 Mon Sep 17 00:00:00 2001 From: dsac Date: Thu, 15 Dec 2022 21:42:21 +0100 Subject: [PATCH] [parser] avoid conflicts between local, input and output variables --- src/parser.mly | 8 +++++++- src/utils.ml | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/parser.mly b/src/parser.mly index 4722140..7cd039a 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -204,7 +204,13 @@ node_content: (Format.asprintf "The node %s is already defined." node_name, current_location())) - else Hashtbl.add defined_nodes node_name n; n }; + else + if vars_distinct e_in e_out (snd $10) + then (Hashtbl.add defined_nodes node_name n; n) + else raise (MyParsingError + ("There is a conflict between the names of local, input \ + or output variables.", + current_location())) }; node_body: | /* empty */ { ([], []) } diff --git a/src/utils.ml b/src/utils.ml index fa769a1..ae46399 100644 --- a/src/utils.ml +++ b/src/utils.ml @@ -22,6 +22,18 @@ let rec list_chk v = function | [] -> false | h :: t -> if h = v then true else list_chk v t +let rec vars_distinct lv lv' lv'' = + match lv, lv', lv'' with + | [], [], _ -> true + | [], h :: t , l'' -> + if List.mem h l'' + then false + else vars_distinct [] t l'' + | h :: t, l', l'' -> + if List.mem h l' || List.mem h l'' + then false + else vars_distinct t l' l'' + exception MyParsingError of (string * location) let type_const = function