handle no-main program
This commit is contained in:
parent
3e0bfe973e
commit
ceaafba460
2 changed files with 10 additions and 4 deletions
11
semantics.ml
11
semantics.ml
|
@ -98,11 +98,14 @@ let analyze_func env ua = function
|
|||
env )
|
||||
;;
|
||||
|
||||
let rec analyze_prog env ua = function
|
||||
| [] -> []
|
||||
let rec analyze_prog env ua b default = function
|
||||
| [] ->
|
||||
if b
|
||||
then []
|
||||
else raise (SemanticsError ("No " ^ default ^ " function", Lexing.dummy_pos))
|
||||
| fn :: suite ->
|
||||
let fn, new_env = analyze_func env ua fn in
|
||||
fn :: analyze_prog new_env ua suite
|
||||
fn :: analyze_prog new_env ua (if b then b else Env.mem default new_env) default suite
|
||||
;;
|
||||
|
||||
let analyze parsed = analyze_prog _types_ [] parsed
|
||||
let analyze parsed = analyze_prog _types_ [] false "main" parsed
|
||||
|
|
3
tests/13_err-no-main.test
Normal file
3
tests/13_err-no-main.test
Normal file
|
@ -0,0 +1,3 @@
|
|||
void test () {
|
||||
bool a = false;
|
||||
}
|
Reference in a new issue