blob: ca1ab1ad4580b1cb20348202b3b668e81b7ebab4 (
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
47
48
49
50
51
|
// 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) =
try
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 "%s" (ex.StackTrace.ToString())
with
| ex ->
printfn "Unhandled Exception: %s" ex.Message
printfn "%s" (ex.StackTrace.ToString())
try
let args = Environment.GetCommandLineArgs()
ParseCmdLineArgs (List.ofArray args)
readAndProcess CONFIG.inputFilename
with
| InvalidCmdLineOption(msg) as ex -> printfn "%s" msg; printfn "%s" ex.StackTrace
|