Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /trunk/src/compiler/parser/parser.sml
ViewVC logotype

View of /trunk/src/compiler/parser/parser.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2356 - (download) (annotate)
Sun Apr 7 14:45:25 2013 UTC (6 years, 6 months ago) by jhr
File size: 1542 byte(s)
  Merging in bug fixes and language enhancements from the vis12 branch (via staging).
  Features include type promotion, the curl and colon operator, transpose, and functions.
(* parser.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * Parser glue.
 *)

structure Parser : sig

  (* parse a file; return NONE if there are syntax errors *)
    val parseFile : (Error.err_stream * TextIO.instream) -> ParseTree.program option

  end = struct

  (* glue together the lexer and parser *)
    structure DiderotParser = DiderotParseFn(DiderotLex)

  (* error function for lexers *)
    fun lexErr errStrm (pos, msg) = Error.errorAt(errStrm, (pos, pos), msg)

  (* map tokens to strings *)
    fun tokToString (DiderotTokens.ID x) = Atom.toString x
      | tokToString (DiderotTokens.STRING s) = concat["\"", String.toCString s, "\""]
      | tokToString (DiderotTokens.FLOAT f) = FloatLit.toString f
      | tokToString (DiderotTokens.INT i) = IntInf.toString i
      | tokToString tok = DiderotTokens.toString tok

  (* error function for parsers *)
    val parseErr = Error.parseError tokToString

  (* parse a file, returning a parse tree *)
    fun parseFile (errStrm, file) = let
          fun get () = TextIO.input file
          val lexer = DiderotLex.lex (Error.sourceMap errStrm) (lexErr errStrm)
          in
            case DiderotParser.parse lexer (DiderotLex.streamify get)
             of (SOME pt, _, []) => (TextIO.closeIn file; SOME pt)
              | (_, _, errs) => (
                  TextIO.closeIn file;
                  List.app (parseErr errStrm) errs;
                  NONE)
            (* end case *)
          end

  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0