<commit_before>open Symbol_table;;
open Utils;;
open Semantics;;

let file_name = Array.get Sys.argv 1 in
let file_string = Utils.file_name_to_string file_name in
print_endline "Started compiler";
try Semantics.analyze (Parse.parse (Lex.lex file_string))
with x -> match x with
    |  Lex.UnrecognizedTokenError (token, lineno, charno) ->
            let file_by_lines = Str.split (Str.regexp "\n") file_string in
            let our_line = List.nth file_by_lines lineno in
            let karet_at = String.concat "" [String.make charno ' '; "^"] in
            print_endline "--------------------------";
            print_endline ("Unrecognized character " ^ (token) ^ " located on line " ^ (string_of_int lineno));
            print_endline our_line;
            print_endline karet_at;
            print_endline "--------------------------";
            raise x
    | Symbol_table.Already_Exists_In_table (symbol1, symbol2) ->
            let line = symbol2.pos.lineno in
            let charno = symbol2.pos.charno in
            let file_by_lines = Str.split (Str.regexp "\n") file_string in
            let our_line = List.nth file_by_lines line in
            let karet_at = String.concat "" [String.make charno ' '; "^"] in
            print_endline "--------------------------";
            print_endline ("Redeclared variable " ^  "in same scope. located on line " ^ (string_of_int line));
            print_endline our_line;
            print_endline karet_at;
            print_endline "--------------------------";
            raise x
    | Symbol_table.Does_Not_Exist_In_Table symbol ->
            let line = symbol.pos.lineno in
            let charno = symbol.pos.charno in
            let file_by_lines = Str.split (Str.regexp "\n") file_string in
            let our_line = List.nth file_by_lines line in
            let karet_at = String.concat "" [String.make charno ' '; "^"] in
            print_endline "--------------------------";
            print_endline ("Undeclared variable " ^ "located on line " ^ (string_of_int line));
            print_endline our_line;
            print_endline karet_at;
            print_endline "--------------------------";
            raise x
    | Semantics.Type_Error (obj1, operator, obj2)->
            let line = operator.pos.lineno in
            let charno = operator.pos.charno in
            let file_by_lines = Str.split (Str.regexp "\n") file_string in
            let our_line = List.nth file_by_lines line in
            let karet_at = String.concat "" [String.make charno ' '; "^"] in
            print_endline "--------------------------";
            print_endline ("Trying to " ^ (operator.str) ^ " on incompatible types " ^ " on line " ^ (string_of_int line));
            print_endline our_line;
            print_endline karet_at;
            print_endline "--------------------------";
            raise x
    | x ->
        print_newline ();
        print_string "Cannot recover.  Exitting";
        print_newline ();
        raise x
;;
print_endline "Ended compiler";
<commit_msg>Printed ast at end of compiler<commit_after>open Symbol_table;;
open Utils;;
open Semantics;;

let log_info = Log.log_info_func "compiler";;

let file_name = Array.get Sys.argv 1 in
let file_string = Utils.file_name_to_string file_name in
print_endline "Started compiler";
try
    let tokens = Lex.lex file_string in
    let cst = Parse.parse tokens in
    let ast = Semantics.analyze cst in
    let ast_string = Ast.string_of_ast ast in
    log_info ast_string
with x -> match x with
    |  Lex.UnrecognizedTokenError (token, lineno, charno) ->
            let file_by_lines = Str.split (Str.regexp "\n") file_string in
            let our_line = List.nth file_by_lines lineno in
            let karet_at = String.concat "" [String.make charno ' '; "^"] in
            print_endline "--------------------------";
            print_endline ("Unrecognized character " ^ (token) ^ " located on line " ^ (string_of_int lineno));
            print_endline our_line;
            print_endline karet_at;
            print_endline "--------------------------";
            raise x
    | Symbol_table.Already_Exists_In_table (symbol1, symbol2) ->
            let line = symbol2.pos.lineno in
            let charno = symbol2.pos.charno in
            let file_by_lines = Str.split (Str.regexp "\n") file_string in
            let our_line = List.nth file_by_lines line in
            let karet_at = String.concat "" [String.make charno ' '; "^"] in
            print_endline "--------------------------";
            print_endline ("Redeclared variable " ^  "in same scope. located on line " ^ (string_of_int line));
            print_endline our_line;
            print_endline karet_at;
            print_endline "--------------------------";
            raise x
    | Symbol_table.Does_Not_Exist_In_Table symbol ->
            let line = symbol.pos.lineno in
            let charno = symbol.pos.charno in
            let file_by_lines = Str.split (Str.regexp "\n") file_string in
            let our_line = List.nth file_by_lines line in
            let karet_at = String.concat "" [String.make charno ' '; "^"] in
            print_endline "--------------------------";
            print_endline ("Undeclared variable " ^ "located on line " ^ (string_of_int line));
            print_endline our_line;
            print_endline karet_at;
            print_endline "--------------------------";
            raise x
    | Semantics.Type_Error (obj1, operator, obj2)->
            let line = operator.pos.lineno in
            let charno = operator.pos.charno in
            let file_by_lines = Str.split (Str.regexp "\n") file_string in
            let our_line = List.nth file_by_lines line in
            let karet_at = String.concat "" [String.make charno ' '; "^"] in
            print_endline "--------------------------";
            print_endline ("Trying to " ^ (operator.str) ^ " on incompatible types " ^ " on line " ^ (string_of_int line));
            print_endline our_line;
            print_endline karet_at;
            print_endline "--------------------------";
            raise x
    | x ->
        print_newline ();
        print_string "Cannot recover.  Exitting";
        print_newline ();
        raise x
;;
print_endline "Ended compiler";

{'fraction_non_alphanumeric': 0.15171650055370986, 'fraction_numerical': 0.0022148394241417496, 'mean_word_length': 1.732065687121867, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1111959', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1783, 'n_words': 481}