summaryrefslogtreecommitdiff
path: root/Jennisys/Jennisys.fs
blob: d0a47fe19fe0b76d1772dcac60d501a6a7a125b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// This project type requires the F# PowerPack at http://fsharppowerpack.codeplex.com/releases
// Learn more about F# at http://fsharp.net
// Original project template by Jomo Fisher based on work of Brian McNamara, Don Syme and Matt Valerio
// This posting is provided "AS IS" with no warranties, and confers no rights.
module Main

open System
open System.IO
open Microsoft.FSharp.Text.Lexing

open Ast
open Lexer
open Options
open Parser
open Printer
open TypeChecker
open Analyzer

let readAndProcess (filename: string) =
    printfn "// Jennisys, Copyright (c) 2011, Microsoft."
    // lex
    let f = if filename = null then Console.In else new StreamReader(filename) :> TextReader
    let lexbuf = LexBuffer<char>.FromTextReader(f)
    lexbuf.EndPos <- { pos_bol = 0;
                       pos_fname=if filename = null then "stdin" else filename; 
                       pos_cnum=0;
                       pos_lnum=1 }
//    try
      // parse
    let sprog = Parser.start Lexer.tokenize lexbuf
    match TypeCheck sprog with
    | None -> ()  // errors have already been reported
    | Some(prog) ->
        Analyze prog filename
//    with
//      | ex ->
//          let pos = lexbuf.EndPos
//          printfn "%s(%d,%d): %s" pos.FileName pos.Line pos.Column ex.Message
//          printfn "%O" ex.StackTrace

try 
  let args = Environment.GetCommandLineArgs()
  ParseCmdLineArgs (List.ofArray args)
  readAndProcess CONFIG.inputFilename
with
  | InvalidCmdLineOption(msg) as ex -> printfn "%s" msg; printfn "%s" ex.StackTrace