[parser] functions other that main → args required

This commit is contained in:
dsac 2022-12-15 22:14:59 +01:00
parent 0d5e045671
commit 74f8a3c3e1
3 changed files with 19 additions and 13 deletions

View File

@ -2,3 +2,4 @@
* This corresponds to the sum of the number of local, input and output * This corresponds to the sum of the number of local, input and output
* variables. *) * variables. *)
let maxvar = 100 let maxvar = 100

View File

@ -36,7 +36,6 @@ let _ =
let nopopt = ref false in let nopopt = ref false in
let simopt = ref false in let simopt = ref false in
let passes = ref [] in let passes = ref [] in
let main_fn = ref "main" in
let source_file = ref "" in let source_file = ref "" in
let testopt = ref false in let testopt = ref false in
let output_file = ref "out.c" in let output_file = ref "out.c" in
@ -53,8 +52,6 @@ let _ =
("-p", Arg.String (fun s -> passes := s :: !passes), ("-p", Arg.String (fun s -> passes := s :: !passes),
"Add a pass to the compilation process"); "Add a pass to the compilation process");
("-sim", Arg.Set simopt, "Simulate the main node"); ("-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])"); ("-o", Arg.Set_string output_file, "Output file (defaults to [out.c])");
] in ] in
Arg.parse speclist anon_fun usage_msg ; Arg.parse speclist anon_fun usage_msg ;
@ -62,7 +59,7 @@ let _ =
if !passes = [] then passes := default_passes; if !passes = [] then passes := default_passes;
let print_verbose = print_verbose !verbose in let print_verbose = print_verbose !verbose in
let print_debug = print_debug !debug in let print_debug = print_debug !debug in
let main_fn = !main_fn in let main_fn = "main" in
(** Definition of the passes table *) (** Definition of the passes table *)
let passes_table = Hashtbl.create 100 in let passes_table = Hashtbl.create 100 in

View File

@ -199,18 +199,26 @@ node_content:
n_local_vars = $10; n_local_vars = $10;
n_equations = eqs; n_equations = eqs;
n_automata = aut; } in 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 then raise (MyParsingError
(Format.asprintf "The node %s is already defined." (Format.asprintf "The node %s should have arguments."
node_name, node_name,
current_location())) current_location()))
else else
if vars_distinct e_in e_out (snd $10) begin
then (Hashtbl.add defined_nodes node_name n; n) if Hashtbl.find_opt defined_nodes node_name <> None
else raise (MyParsingError then raise (MyParsingError
("There is a conflict between the names of local, input \ (Format.asprintf "The node %s is already defined."
or output variables.", node_name,
current_location())) }; 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: node_body:
| /* empty */ { ([], []) } | /* empty */ { ([], []) }