From: chak Date: Sun, 18 Nov 2001 12:32:22 +0000 (+0000) Subject: [project @ 2001-11-18 12:32:22 by chak] X-Git-Tag: Approximately_9120_patches~563 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=0a432d487ba39bd595cebd74456be4f0d635e82e [project @ 2001-11-18 12:32:22 by chak] Added a new section that covers lexing and parsing. --- diff --git a/ghc/docs/comm/index.html b/ghc/docs/comm/index.html index 5763542..a4875ac 100644 --- a/ghc/docs/comm/index.html +++ b/ghc/docs/comm/index.html @@ -6,7 +6,7 @@ -

The Glasgow Haskell Compiler (GHC) Commentary [v0.4]

+

The Glasgow Haskell Compiler (GHC) Commentary [v0.5]

-Last modified: Tue Nov 13 10:32:11 EST 2001 +Last modified: Sat Nov 17 14:10:48 EST 2001 diff --git a/ghc/docs/comm/the-beast/syntax.html b/ghc/docs/comm/the-beast/syntax.html new file mode 100644 index 0000000..d54b4ee --- /dev/null +++ b/ghc/docs/comm/the-beast/syntax.html @@ -0,0 +1,80 @@ + + + + + The GHC Commentary - Just Syntax + + + +

The GHC Commentary - Just Syntax

+

+ The lexical and syntactic analyser for Haskell programs are located in + fptools/ghc/compiler/parser/. +

+ +

The Lexer

+

+ The lexer is a rather tedious piece of Haskell code contained in the + module Lex. + Its complexity partially stems from covering, in addition to Haskell 98, + also the whole range of GHC language extensions plus its ability to + analyse interface files in addition to normal Haskell source. The lexer + defines a parser monad P a, where a is the + type of the result expected from a successful parse. More precisely, a + result of type +

+data ParseResult a = POk PState a
+		   | PFailed Message
+
+

+ is produced with Message being from ErrUtils + (and currently is simply a synonym for SDoc). +

+ The record type PState contains information such as the + current source location, buffer state, contexts for layout processing, + and whether Glasgow extensions are accepted (either due to + -fglasgow-exts or due to reading an interface file). Most + of the fields of PState store unboxed values; in fact, even + the flag indicating whether Glasgow extensions are enabled is + represented by an unboxed integer instead of by a Bool. My + (= chak's) guess is that this is to avoid having to perform a + case on a boxed value in the inner loop of the lexer. +

+ The same lexer is used by the Haskell source parser, the Haskell + interface parser, and the package configuration parser. + +

The Haskell Source Parser

+

+ The parser for Haskell source files is defined in the form of a parser + specification for the parser generator Happy in the file Parser.y. + The parser exports three entry points for parsing entire modules + (parseModule, individual statements + (parseStmt), and individual identifiers + (parseIdentifier), respectively. The last two are needed + for GHCi. All three require a parser state (of type + PState) and are invoked from HscMain. + +

The Haskell Interface Parser

+

+ The parser for interface files is also generated by Happy from ParseIface.y. + It's main routine parseIface is invoked from RnHiFiles.readIface. + +

The Package Configuration Parser

+

+ The parser for configuration files is by far the smallest of the three + and defined in ParsePkgConf.y. + It exports loadPackageConfig, which is used by DriverState.readPackageConf. + +

+ +Last modified: Sun Nov 18 21:22:38 EST 2001 + + + +