SCM Repository
View of /branches/vis12/src/compiler/parser/parser.sml
Parent Directory
|
Revision Log
Revision 3291 -
(download)
(annotate)
Wed Oct 14 21:25:00 2015 UTC (5 years, 6 months ago) by jhr
File size: 2265 byte(s)
Wed Oct 14 21:25:00 2015 UTC (5 years, 6 months ago) by jhr
File size: 2265 byte(s)
code is copyright University of Chicago
(* parser.sml * * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu) * * COPYRIGHT (c) 2015 The University of Chicago * 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 datatype add_or_delete = datatype AntlrRepair.add_or_delete (* 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; when adding a token, we use a generic name where it makes sense *) fun tokToString ADD (DiderotTokens.ID _) = "<identifier>" | tokToString DEL (DiderotTokens.ID x) = Atom.toString x | tokToString _ (DiderotTokens.STRING s) = concat["\"", String.toCString s, "\""] | tokToString ADD (DiderotTokens.FLOAT f) = "<number>" | tokToString DEL (DiderotTokens.FLOAT f) = FloatLit.toString f | tokToString ADD (DiderotTokens.INT i) = "<integer>" | tokToString DEL (DiderotTokens.INT i) = IntInf.toString i | tokToString ADD DiderotTokens.KW_vec4 = "<type>" | tokToString ADD DiderotTokens.KW_vec3 = "<type>" | tokToString ADD DiderotTokens.KW_vec2 = "<type>" | tokToString ADD DiderotTokens.KW_real = "<type>" | tokToString ADD DiderotTokens.KW_int = "<type>" | tokToString ADD DiderotTokens.KW_bool = "<type>" | 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 |