af2afda53bb8fd78d3523d5f3efe3192ba9605f5
[feisty_meow.git] / examples / cpp_grammar_code / index.html
1 <html>
2
3 <head>
4 <meta http-equiv="Content-Type"
5 content="text/html; charset=iso-8859-1">
6 <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
7 <title>Ed's Toolkit</title>
8 </head>
9
10 <body bgcolor="#FFFFFF">
11
12 <h1 align="center">Superset C++ Grammar</h1>
13
14 <hr>
15
16 <p>This work area supports a demonstration of the superset C++
17 grammar described in Chapter 5 of <a
18 href="mailto:Ed.Willink@rrl.co.uk">Ed Willink</a>'s thesis on <a
19 href="http://www.computing.surrey.ac.uk/research/dsrg/fog/FogThesis.html">Meta-Compilation
20 for C++</a>. It contains working lex and yacc grammars that
21 enable C++ source to be lexically analysed, then syntactically
22 analysed without semantic knowlege. The lex and yacc grammar have
23 their action routines defined by macros in the hope that
24 reconfiguration may be possible without editing the grammars
25 directly. The dummy implementations of the yacc macros do nothing
26 other than count statements and diagnose the back-tracking
27 behaviour. Users may add their own syntactic level code. A proper
28 C++ parser needs semantic analysis as well, including correction
29 of minor misprses at the syntactic level. Semantic interpretaion
30 is provided by <a
31 href="http://www.computing.surrey.ac.uk/research/dsrg/fog/">FOG</a>
32 from which this demonstration is split off.</p>
33
34 <p>The work area is self-sufficient, requiring only <em>lex</em>
35 and <em>yacc</em>, or <em>flex</em> and <em>bison</em>.</p>
36
37 <hr>
38
39 <h2>Command Line</h2>
40
41 <p>The test grammar is a simple command line utility, for
42 analysing a single <strong>pre-processed</strong> source file
43 (use CC -E to run just the preprocessor on your source files)..</p>
44
45 <pre>   grammar [options] &lt; source-file</pre>
46
47 <p>The full set of command line options is:</p>
48
49 <pre>   -c      Recognise only C keywords - approximates C rather than C++ parsing
50         -m      Display mark activity.
51         -n      Echo line numbers.
52         -t      Echo source line text.
53         -y      Display yacc diagnostics.</pre>
54
55 <p>On completion a three line diagnostic summarises the search
56 activity. </p>
57
58 <hr>
59
60 <h2>Files</h2>
61
62 <p><a href="CxxSrc.tgz">CxxSrc.tgz</a>, <a href="CxxNtSrc.tgz">CxxNtSrc.tgz</a>
63 The source distribution kit including a Sun or NT executable.</p>
64
65 <p><a href="CxxLexer.l">CxxLexer.l</a> A simple lexer for all C
66 and/or C++ tokens</p>
67
68 <p><a href="CxxParser.y">CxxParser.y</a> The parser,
69 automatically extracted from FogParser.y.</p>
70
71 <p><a href="CxxToken.hxx">CxxToken.hxx</a>, <a
72 href="CxxToken.cxx">CxxToken.cxx</a> A trivial class used by the
73 parser to represent each parsed token.</p>
74
75 <p><a href="CxxLexing.hxx">CxxLexing.hxx</a>, <a
76 href="CxxLexing.cxx">CxxLexing.cxx</a> Interface and
77 implementation of token creation routines for the lexer.</p>
78
79 <p><a href="CxxParsing.hxx">CxxParsing.hxx</a>, <a
80 href="CxxParsing.cxx">CxxParsing.cxx</a> Interface and
81 implementation of token manioulation routines for the parser.</p>
82
83 <p><a href="CxxLexer.cpp">CxxLexer.cpp</a>, <a
84 href="CxxParser.cpp">CxxParser.cpp</a>, <a href="CxxToken.cpp">CxxToken.cpp</a>
85 Degenerate compilation units for the above.</p>
86
87 <p><a href="makefile">makefile</a>, <a href="makefile.macros">makefile.macros</a>,
88 <a href="CxxLexer.l">makefile.unix</a> Unix build scripts</p>
89
90 <p><a href="makefile.gmake">makefile.gmake</a>, <a
91 href="makefile.macros">makefile.macros</a>, <a href="grammar.dsw">grammar.dsw</a>,
92 <a href="grammar.dsp">grammar.dsp</a> NT build scripts and
93 DevStudio workspace and project</p>
94
95 <p><a><u>sun4o/grammar</u></a> Built executable (on Unix)</p>
96
97 <p><a><u>Release/grammar.exe</u></a> Built executable (on NT)</p>
98
99 <hr>
100
101 <h2>Unix Builds</h2>
102
103 <p>The code builds under Solaris 2.5 and with Sun C++ 4.2.</p>
104
105 <pre>   make sun</pre>
106
107 <p>or Gnu egcs-1.0.2 release, with flex 2.3.7, bison 1.16</p>
108
109 <pre>   make gnu</pre>
110
111 <hr>
112
113 <h2>NT Builds</h2>
114
115 <p>The code builds under NT 4 and has been tested with DevStudio
116 V6 and cygwin 1.1.</p>
117
118 <h3>a) cygwin</h3>
119
120 <p>You need cygwin, the latest version of which is available <a
121 href="ftp://sunsite.org.uk:21/Mirrors/sourceware.cygnus.com/pub/cygwin/setup.exe">ftp://sunsite.org.uk:21/Mirrors/sourceware.cygnus.com/pub/cygwin/setup.exe</a></p>
122
123 <p>A slightly easier to install earlier version (used by the
124 author) is <a
125 href="ftp://sunsite.org.uk:21/Mirrors/sourceware.cygnus.com/pub/cygwin/old/cygwin-b20/full.exe">ftp://sunsite.org.uk:21/Mirrors/sourceware.cygnus.com/pub/cygwin/old/cygwin-b20/full.exe</a></p>
126
127 <p>Use a mirror site listed at <a
128 href="http://sources.redhat.com/cygwin/mirrors.html">http://sources.redhat.com/cygwin/mirrors.html</a>.</p>
129
130 <p>The older cygwin is a simple standard NT installation - just
131 run full.exe (with administrator rights) and accept the default
132 installation paths (gnu tools build them in). The newer cygwin is
133 much smarter, doing automatic selective downloads - which the
134 author's firewall messes up.</p>
135
136 <h3>b) Path configuration</h3>
137
138 <p>You may want to make cygwin tools accessible from command
139 prompts so</p>
140
141 <pre>Start-&gt;Settings-&gt;ControlPanel
142         System|Environment
143                 Add Variable PATH
144                 Value C:\cygwin\cygwin-b20\H-i586-cygwin32\BIN</pre>
145
146 <h3>c) DevStudio configuration</h3>
147
148 <p>You need to configure DevStudio to use cygwin.</p>
149
150 <p>In DevStudio:</p>
151
152 <pre>Tools-&gt;Options-&gt;Directories
153         Show Directories For Executable files
154         Add C:\cygwin\bin</pre>
155
156 <h3>d) Unpacking</h3>
157
158 <p>Then use winzip or gunzip to extract all of <a
159 href="CxxNtSrc.tgz">CxxNtSrc.tgz</a>:</p>
160
161 <pre>double click in Explorer on <a href="CxxNtSrc.tgz">CxxNtSrc.tgz</a>
162         Yes to decompress archive to temporary file
163         Wait a few moments
164         Actions...-&gt;Extract
165                 All Files, to e.g. C:\CxxGrammar, use Folder names, Extract
166         Close Winzip</pre>
167
168 <h3>e) DevStudio build</h3>
169
170 <pre>Double click in Explorer on <a href="grammar.dsw">grammar.dsw</a>
171         If prompted to browse for a SourceSafe project Click No.
172         If prompted to attempt SourceSafe connection in another session click No.
173         Select your preferred configuration (Win32 Debug is default)
174         Select FileView|grammar Files-&gt;Targets-&gt;executable
175         &lt;Ctrl&gt;F7
176         after a few seconds everything is built</pre>
177
178 <p>DevStudio reports 0 errors and 1 warnings</p>
179
180 <pre>Build : warning : failed to (or don't know how to) build 'C:\CxxGrammar\Targets\executable'</pre>
181
182 <p>The warning is an artefact of fake build targets</p>
183
184 <p>Everything in DevStudio is compiled using a makefile.gmake
185 target which is selected for a &lt;CTRL&gt;F7 in the Workspace
186 window. Steer clear of the standard DevStudio F7 which builds all
187 targets: backup then clean then executables then realclean then
188 test etc. No harm is done but it takes a long time.</p>
189
190 <hr>
191
192 <p><i>Last updated <!--webbot bot="Timestamp" startspan
193 s-type="EDITED" s-format="%d %B, %Y" -->28 July, 2001<!--webbot
194 bot="Timestamp" i-checksum="21078" endspan -->.</i> </p>
195 </body>
196 </html>