From 74f8a3c3e16c252d798a4d611ba42b0b9c11fdf8 Mon Sep 17 00:00:00 2001 From: dsac Date: Thu, 15 Dec 2022 22:14:59 +0100 Subject: [PATCH] =?UTF-8?q?[parser]=20functions=20other=20that=20main=20?= =?UTF-8?q?=E2=86=92=20args=20required?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.ml | 1 + src/main.ml | 5 +---- src/parser.mly | 26 +++++++++++++++++--------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/config.ml b/src/config.ml index 6046dee..3255356 100644 --- a/src/config.ml +++ b/src/config.ml @@ -2,3 +2,4 @@ * This corresponds to the sum of the number of local, input and output * variables. *) let maxvar = 100 + diff --git a/src/main.ml b/src/main.ml index c1334ea..450e81d 100644 --- a/src/main.ml +++ b/src/main.ml @@ -36,7 +36,6 @@ let _ = let nopopt = ref false in let simopt = ref false in let passes = ref [] in - let main_fn = ref "main" in let source_file = ref "" in let testopt = ref false in let output_file = ref "out.c" in @@ -53,8 +52,6 @@ let _ = ("-p", Arg.String (fun s -> passes := s :: !passes), "Add a pass to the compilation process"); ("-sim", Arg.Set simopt, "Simulate the main node"); - ("-m", Arg.String (fun s -> main_fn := s), - "Defines what the main function is (defaults to main)."); ("-o", Arg.Set_string output_file, "Output file (defaults to [out.c])"); ] in Arg.parse speclist anon_fun usage_msg ; @@ -62,7 +59,7 @@ let _ = if !passes = [] then passes := default_passes; let print_verbose = print_verbose !verbose in let print_debug = print_debug !debug in - let main_fn = !main_fn in + let main_fn = "main" in (** Definition of the passes table *) let passes_table = Hashtbl.create 100 in diff --git a/src/parser.mly b/src/parser.mly index f8660d5..c6a1305 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -199,18 +199,26 @@ node_content: n_local_vars = $10; n_equations = eqs; n_automata = aut; } in - if Hashtbl.find_opt defined_nodes node_name <> None + if List.length (snd $10) = 0 && node_name <> "main" then raise (MyParsingError - (Format.asprintf "The node %s is already defined." - node_name, + (Format.asprintf "The node %s should have arguments." + node_name, current_location())) 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())) }; + begin + if Hashtbl.find_opt defined_nodes node_name <> None + then raise (MyParsingError + (Format.asprintf "The node %s is already defined." + node_name, + current_location())) + 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())) + end}; node_body: | /* empty */ { ([], []) }