home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / function / 1344 < prev    next >
Encoding:
Text File  |  1992-11-10  |  1.5 KB  |  41 lines

  1. Newsgroups: comp.lang.functional
  2. Path: sparky!uunet!mcsun!sunic!dkuug!daimi!urban
  3. From: urban@daimi.aau.dk (Urban Engberg)
  4. Subject: Including files from ml-lex and -yacc
  5. Message-ID: <1992Nov10.142821.8095@daimi.aau.dk>
  6. Keywords: ml-lex ml-yacc sml
  7. Sender: urban@daimi.aau.dk (Urban Engberg)
  8. Organization: DAIMI: Computer Science Department, Aarhus University, Denmark
  9. Date: Tue, 10 Nov 92 14:28:21 GMT
  10. Lines: 29
  11.  
  12. In the language of a parser I am writing I want to use the parser
  13. directive %Include <filename> meaning that the file <filename> is to
  14. be included in the parsed file just as if its contents were actually
  15. put there.  I would like to do this inside ml-lex and/or -yacc, which
  16. means that I have to do some operations on the streams that are
  17. generated in the lexer and passed on to the parser.  Has anyone done
  18. this?  How?
  19.  
  20. This is how I construct the parser:
  21.  
  22. structure PreParser : PREPARSER =
  23.   struct
  24.     val parse = fn s =>
  25.       let val dev    = open_in s
  26.           val stream = PreParserParser.makeLexer (fn i => input(dev, i))
  27.           val _      = PreParserLex.UserDeclarations.pos := (1, 0)
  28.           val error  = fn (e, (oldline:int, oldchar:int),
  29.                   (newline:int, newchar:int)) => 
  30.                       output(std_out, "...")
  31.       in PreParserParser.parse(30, stream, error, ()) before close_in dev
  32.       end
  33.   end
  34.  
  35.  
  36. --
  37. Urban Engberg                    Computer Science Department
  38. urban@daimi.aau.dk                Aarhus University
  39. Phn: +45 86 20 27 11 - 50 91            Ny Munkegade
  40. Fax: +45 86 13 57 25                DK-8000 Aarhus C  --  DENMARK
  41.