From: Mike D. Lowis Date: Fri, 20 Jul 2012 17:10:10 +0000 (-0400) Subject: Added code to main for parsing input from a file X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=eee167180360cb6b13ac29148409eeb1b2f9d606;p=archive%2Fdlang-scm.git Added code to main for parsing input from a file --- diff --git a/example.dl b/example.dl index e082830..5d5766d 100644 --- a/example.dl +++ b/example.dl @@ -1,4 +1,4 @@ -# Literals +## Literals "foo" 'a' 1.0 @@ -19,12 +19,14 @@ foo(1, 2, 3) # Definition and assignment def foo 5 ; -set foo 6 ; +set! foo 6 ; def foo 5 end -set foo 6 end +set! foo 6 end -# Special function definition shorthand -def max(a, b) if (a > b) a else b ;; +# Special function definition shorthand (not yet supported) +#def max(a, b) +# if (a > b) a b; +#end # If statement if conditional @@ -54,20 +56,17 @@ func (a) foo(a) ; func (a, b) foo(a, b) ; func (a, b, c) foo(a, b, c) ; -# Macro expressions -macro () ; -macro (a) ; -macro (a, b) ; -macro (a, b, c) ; -macro () foo(a) ; -macro (a) foo(a) ; -macro (a, b) foo(a, b) ; -macro (a, b, c) foo(a, b, c) ; - -# Quoting Expressions -#quote( (1 + 1) ) +## Macro expressions (not yet supported) +#macro () ; +#macro (a) ; +#macro (a, b) ; +#macro (a, b, c) ; +#macro () foo(a) ; +#macro (a) foo(a) ; +#macro (a, b) foo(a, b) ; +#macro (a, b, c) foo(a, b, c) ; -# Syntactic Extensions +# Syntactic Extensions (not yet supported) #syntax let ( := = ) ; # ( a := b ) # define a b ; @@ -75,6 +74,6 @@ macro (a, b, c) foo(a, b, c) ; # ( a = b ) # set! a b ; #end - +# #let foo := "bar" ; #let foo = 5 ; diff --git a/source/main.scm b/source/main.scm index 3b20818..cfe643b 100644 --- a/source/main.scm +++ b/source/main.scm @@ -1,5 +1,14 @@ -(include "loop.scm") -(declare (uses buf) - (uses lexer) +(declare + (uses parser)) +(define (parse-file fname) + (define result + (dlang/program (dlang/lexer (open-input-file fname)))) + (print result)) + +; If we have a file, then parse it +(if (= 1 (length (command-line-arguments))) + (parse-file (car (command-line-arguments))) + (print "No input file provided.")) +