Thread View: comp.lang.functional
5 messages
5 total messages
Started by Urban Engberg
Tue, 10 Nov 1992 14:28
Including files from ml-lex and -yacc
Author: Urban Engberg
Date: Tue, 10 Nov 1992 14:28
Date: Tue, 10 Nov 1992 14:28
29 lines
1567 bytes
1567 bytes
In the language of a parser I am writing I want to use the parser
directive %Include <filename> meaning that the file <filename> is to
be included in the parsed file just as if its contents were actually
put there. I would like to do this inside ml-lex and/or -yacc, which
means that I have to do some operations on the streams that are
generated in the lexer and passed on to the parser. Has anyone done
this? How?
This is how I construct the parser:
structure PreParser : PREPARSER =
struct
val parse = fn s =>
let val dev = open_in s
val stream = PreParserParser.makeLexer (fn i => input(dev, i))
val _ = PreParserLex.UserDeclarations.pos := (1, 0)
val error = fn (e, (oldline:int, oldchar:int),
(newline:int, newchar:int)) =>
output(std_out, "...")
in PreParserParser.parse(30, stream, error, ()) before close_in dev
end
end
--
Urban Engberg Computer Science Department
urban@daimi.aau.dk Aarhus University
Phn: +45 86 20 27 11 - 50 91 Ny Munkegade
Fax: +45 86 13 57 25 DK-8000 Aarhus C -- DENMARK
Re: Including files from ml-lex and -yacc
Author: John Farrell
Date: Mon, 16 Nov 1992 06:33
Date: Mon, 16 Nov 1992 06:33
11 lines
1016 bytes
1016 bytes
In <1992Nov10.142821.8095@daimi.aau.dk> urban@daimi.aau.dk (Urban Engberg) writes: >In the language of a parser I am writing I want to use the parser >directive %Include <filename> meaning that the file <filename> is to >be included in the parsed file just as if its contents were actually >put there. I thought the standard way to do this was to use the same compiler directives as C does, then use the C preprocessor :-). It's a hack, I know, but it provides a well-known set of functions at very low cost. John
Re: Including files from ml-lex and -yacc
Author: Andrew Koenig
Date: Mon, 16 Nov 1992 18:01
Date: Mon, 16 Nov 1992 18:01
10 lines
1053 bytes
1053 bytes
In article <farrell.721895635@coral> farrell@coral.cs.jcu.edu.au (John Farrell) writes: > I thought the standard way to do this was to use the same compiler > directives as C does, then use the C preprocessor :-). It's a hack, I know, > but it provides a well-known set of functions at very low cost. Just make sure you don't utter the names of any macros in your ML comments. -- --Andrew Koenig ark@europa.att.com
Re: Including files from ml-lex and -yacc
Author: Patrick Miller
Date: Tue, 17 Nov 1992 16:57
Date: Tue, 17 Nov 1992 16:57
21 lines
1482 bytes
1482 bytes
In article <farrell.721895635@coral>, farrell@coral.cs.jcu.edu.au (John Farrell) writes: |> >directive %Include <filename> meaning that the file <filename> is to |> ... |> I thought the standard way to do this was to use the same compiler |> directives as C does, then use the C preprocessor :-). It's a hack, I know, |> but it provides a well-known set of functions at very low cost. One has to be careful how this is done. Remember that C preprocessors have varying awareness of comment characters, etc... The following was causing the Sisal preprocessor (a CPP hack as described) to bomb. The % is a comment character. for initial % Can't do it too much The problem was that Sisal uses Mark-to-endofline comments. The CPP was getting confused over the single quote without matching end quote! -- Pat Miller I have many opinions, but they patmiller@llnl.gov generally aren't humble ones
Re: Including files from ml-lex and -yacc
Author: Urban Engberg
Date: Wed, 18 Nov 1992 09:50
Date: Wed, 18 Nov 1992 09:50
7 lines
965 bytes
965 bytes
Thanks for all advice. David Tarditi sent me some ml-code implementing a stack of lexers, doing the job brilliantly. Whenever lex meets an include directive, it runs a new lexer on the include file and pushes itself on the stack etc. I would be happy to distribute it to whoever is interested. Urban
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads