-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.fs
44 lines (40 loc) · 898 Bytes
/
main.fs
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
//
// F# program to parse simple C programs.
//
#light
//##################################################################################
//
// main
//
// Compiles the simple C program given as command-line argument, e.g.
//
// dotnet run main.c
//
[<EntryPoint>]
let main argv =
if argv.Length = 0 then
printfn "Usage: dotnet run file.c"
0
else
let filename = argv.[0]
printfn "compiling %s..." filename
//
// Run the lexer to get the tokens, and then
// pass these tokens to the parser to see if
// the input program is legal:
//
let tokens = compiler.lexer.analyze filename
let (valid, msg, program) = compiler.parser.parse tokens
//
if valid then
printfn "%s" msg
else
printfn "syntax error: %s" msg
//
printfn ""
printfn "%A" tokens
printfn ""
printfn "%A" program
printfn ""
//
0