jdt-core-home/howto/generate parser/generateParser.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7, Thu Oct 12 19:00:54 2006 UTC revision 1.8, Thu Oct 12 19:09:57 2006 UTC
# Line 16  Line 16 
16  <tr>  <tr>
17          <td ALIGN=RIGHT VALIGN=TOP WIDTH="2%"><img SRC="http://dev.eclipse.org/images/Adarrow.gif" NOSAVE BORDER=0 height=16 width=16></td>          <td ALIGN=RIGHT VALIGN=TOP WIDTH="2%"><img SRC="http://dev.eclipse.org/images/Adarrow.gif" NOSAVE BORDER=0 height=16 width=16></td>
18          <td WIDTH="98%"><b>Where to get the parser generator</b><br>          <td WIDTH="98%"><b>Where to get the parser generator</b><br>
19          <blockquote>The parser files and resources are automatically generated using the LPG parser generator. This tools has          <blockquote>The parser files and resources are automatically generated using the Jikespg parser generator. This tools has
20          been renamed Jikes Parser generator. You can find more information and latest releases at this <A HREF="http://sourceforge.net/project/showfiles.php?group_id=128803&package_id=144579">link</A>.          been renamed Jikes Parser generator. You can find more information and latest releases at this <A HREF="http://sourceforge.net/project/showfiles.php?group_id=128803&package_id=144579">link</A>.
21          The latest tool is provided in source format. We don't provide any help for compiling these          The latest tool is provided in source format. We don't provide any help for compiling these
22          source files. Refer to the link above if you have trouble to get binaries.          source files. Refer to the link above if you have trouble to get binaries.
23      <br>Our grammar is generated using the version 1.3 of LPG. If newer versions fail to generate resources from our      <br>Our grammar is generated using the version 1.3 of Jikespg. If newer versions fail to generate resources from our
24          grammar, please send request to the Jikes Parser Generator team.          grammar, please send request to the Jikes Parser Generator team.
25          </blockquote>          </blockquote>
         </p>  
26          </td>          </td>
27  </tr>  </tr>
28  <tr>  <tr>
29          <td ALIGN=RIGHT VALIGN=TOP WIDTH="2%"><img SRC="http://dev.eclipse.org/images/Adarrow.gif" NOSAVE BORDER=0 height=16 width=16></td>          <td ALIGN=RIGHT VALIGN=TOP WIDTH="2%"><img SRC="http://dev.eclipse.org/images/Adarrow.gif" NOSAVE BORDER=0 height=16 width=16></td>
30          <td WIDTH="98%"><b>Where to get the grammar</b><br>          <td WIDTH="98%"><b>Where to get the grammar</b><br>
31          <blockquote>The latest grammar is always located in the <code>java_1_5.g</code> file. (N.B.: Older versions of the grammar, such as java_1_4.g are not supported and are no longer functional.) Go to the org.eclipse.jdt.core plugins          <blockquote>The latest grammar is always located in the <code>java_1_5.g</code> file.
32            (N.B.: Older versions of the grammar, such as java_1_4.g are not supported and are no longer functional.). Go to the org.eclipse.jdt.core plugins
33          directory (<font color="#3366FF">eclipse\plugins\org.eclipse.jdt.core</font> where eclipse is the root of your eclipse installation) and open the          directory (<font color="#3366FF">eclipse\plugins\org.eclipse.jdt.core</font> where eclipse is the root of your eclipse installation) and open the
34          <font color="#3366FF">grammar</font> directory. Then search for the <font color="#3366FF">java_1_5.g</font> file inside the          <font color="#3366FF">grammar</font> directory. Then search for the <font color="#3366FF">java_1_5.g</font> file inside the
35          folder <font color="#3366FF">grammar</font>. Then copy its contents from:          folder <font color="#3366FF">grammar</font>. Then copy its contents from:
# Line 43  Line 43 
43          You can save this file where you want, we will assume from thereon you saved it in <code>d:\temp\</code>.          You can save this file where you want, we will assume from thereon you saved it in <code>d:\temp\</code>.
44          <!-- Also make sure that the file has Unix-style end-of-line characters (i.e., not those of MS-DOS), as the parser generator is quite picky about this. -->          <!-- Also make sure that the file has Unix-style end-of-line characters (i.e., not those of MS-DOS), as the parser generator is quite picky about this. -->
45          </blockquote>          </blockquote>
         </p>  
46          </td>          </td>
47  </tr>  </tr>
48  <tr>  <tr>
49          <td ALIGN=RIGHT VALIGN=TOP WIDTH="2%"><img SRC="http://dev.eclipse.org/images/Adarrow.gif" NOSAVE BORDER=0 height=16 width=16></td>          <td ALIGN=RIGHT VALIGN=TOP WIDTH="2%"><img SRC="http://dev.eclipse.org/images/Adarrow.gif" NOSAVE BORDER=0 height=16 width=16></td>
50          <td WIDTH="98%"><b>What to do with these files and update the parser class...</b><br>          <td WIDTH="98%"><b>What to do with these files and update the parser class...</b><br>
51          <blockquote>          <blockquote>
52  Assuming the LPG executable (<code>lpg.exe</code> or <code>jikespg.exe</code>) is located in <code>d:\lpg</code>.  Assuming the Jikespg executable (<code>jikespg.exe</code>) is located in <code>d:\jikespg</code>.
53   <ol>   <ol>
54   <li>First in a console, run:   <li>First in a console, run:
55   <PRE>   <PRE>
56          d:          d:
57          cd \temp          cd \temp
58          d:\lpg\lpg.exe java.g          d:\jikespg\jikespg.exe java.g
59   </PRE>   </PRE>
60   </li>   </li>
61   <li>You will get an output that looks like this:   <li>You will get an output that looks like this:
62   <PRE>   <PRE>
63   LPG Parser Generator (V2.30)            Tue Apr 02 12:49:13 2002   IBM Research Jikes Parser Generator            Fri Oct 14 09:22:32 2005
64  %OPTIONS ACTION, AN=JavaAction.java, GP=java,  %OPTIONS ACTION, AN=JavaAction.java, GP=java,
65  %OPTIONS FILE-PREFIX=java, ESCAPE=$, PREFIX=TokenName, OUTPUT-SIZE=125 ,  %OPTIONS FILE-PREFIX=java, ESCAPE=$, PREFIX=TokenName, OUTPUT-SIZE=125 ,
66  %OPTIONS NOGOTO-DEFAULT, SINGLE-PRODUCTIONS, LALR=1 , TABLE=TIME ,  %OPTIONS NOGOTO-DEFAULT, SINGLE-PRODUCTIONS, LALR=1 , TABLE,
67  %OPTIONS ERROR_MAPS  %OPTIONS ERROR_MAPS
68  %OPTIONS first follow  %OPTIONS first follow
69  %OPTIONS TRACE=FULL ,  %OPTIONS TRACE=FULL ,
70  %OPTIONS VERBOSE  %OPTIONS VERBOSE
71    %OPTIONS DEFERRED
72    %OPTIONS NAMES=MAX
73    %OPTIONS SCOPES
74  Options in effect:  Options in effect:
75      ACTION  ACTFILE-NAME=JavaAction.java  BLOCKB=/.  BLOCKE=./  BYTE  CONFLIC      ACTION  ACTFILE-NAME=JavaAction.java  BLOCKB=/.  BLOCKE=./  BYTE  CONFLI
76      DEFAULT=5  NODEBUG  DEFERRED  NOEDIT  ERROR-MAPS  ESCAPE=$      DEFAULT=5  NODEBUG  DEFERRED  NOEDIT  ERROR-MAPS  ESCAPE=$
77      FILE-PREFIX=java  FIRST  FOLLOW  GENERATE-PARSER=JAVA  NOGOTO-DEFAULT      FILE-PREFIX=java  FIRST  FOLLOW  GENERATE-PARSER=JAVA  NOGOTO-DEFAULT
78      HACTFILE-NAME=javahdr.java  HBLOCKB=/:  HBLOCKE=:/  LALR=1  LIST      HACTFILE-NAME=javahdr.java  HBLOCKB=/:  HBLOCKE=:/  LALR=1  LIST
79      MAX-DISTANCE=30  MIN-DISTANCE=3  NAMES=OPTIMIZED  NONT-CHECK  ORMARK=|      MAX-DISTANCE=30  MIN-DISTANCE=3  NAMES=MAXIMUM  NONT-CHECK  ORMARK=|
80      OUTPUT-SIZE=125  PREFIX=TokenName  READ-REDUCE  NOSCOPES  NOSHIFT-DEFAULT      OUTPUT-SIZE=125  PREFIX=TokenName  READ-REDUCE  SCOPES  NOSHIFT-DEFAULT
81      SINGLE-PRODUCTIONS  STACK-SIZE=128  STATES  SUFFIX=  TABLE=TIME  TRACE=FU      SINGLE-PRODUCTIONS  STACK-SIZE=128  STATES  SUFFIX=  TABLE=SPACE
82      VERBOSE  WARNINGS  XREF      TRACE=FULL  VERBOSE  WARNINGS  XREF
83    
84    *** The following Terminals are useless:
85            const  goto
86    
87  This grammar is LALR(1).  This grammar is LALR(1).
88    
89  Number of Terminals: 105  Number of Terminals: 110
90  Number of Nonterminals: 202  Number of Nonterminals: 306
91  Number of Productions: 437  Number of Productions: 693
92  Number of Single Productions: 162  Number of Single Productions: 232
93  Number of Items: 1265  Number of Items: 2165
94  Number of States: 591  Number of Scopes: 132
95  Number of Shift actions: 3482  Number of States: 954
96  Number of Goto actions: 4061  Number of Shift actions: 6057
97  Number of Shift/Reduce actions: 369  Number of Goto actions: 7493
98  Number of Goto/Reduce actions: 687  Number of Shift/Reduce actions: 593
99  Number of Reduce actions: 7736  Number of Goto/Reduce actions: 1041
100    Number of Reduce actions: 13922
101  Number of Shift-Reduce conflicts: 0  Number of Shift-Reduce conflicts: 0
102  Number of Reduce-Reduce conflicts: 0  Number of Reduce-Reduce conflicts: 0
103  Number of Reductions saved by default: 4913  Reallocating storage for SPACE table, adding 2820 entries
 Reallocating storage for TIME table, adding 3603 entries  
104    
105  Length of Check table: 16836  Length of base Action Table: 12268
106  Length of Action table: 16608  Number of entries in base Action Table: 9488
107  Number of entries in Action Table: 12013  Percentage of increase: 29.3%
108  Percentage of increase: 38.2%  Storage required for base Tables: 24536 Bytes, 24K
109  Highest symbol in Check Table: 307  Storage required for Rules: 2076 Bytes
110  Storage Required for Tables: 66888 Bytes, 66K  Number of unique terminal states: 727
111  Storage Required for Rules: 1308 Bytes  Number of Shift actions saved by merging: 4113
112    Number of Reduce actions saved by merging: 967
113    Number of Reduce saved by default: 8997
114    
115    Length of Terminal Check Table: 7913
116    Length of Terminal Action Table: 7902
117    Number of entries in Terminal Action Table: 7222
118    Percentage of increase: 9.4%
119    Storage required for Terminal Tables: 23717 Bytes, 24K
120    Total storage required for Tables: 48253 Bytes, 48K
121    
122    
123  Actions in Compressed Tables:  Actions in Compressed Tables:
124       Number of Shifts: 3482       Number of Shifts: 2211
125       Number of Shift/Reduces: 369       Number of Shift/Reduces: 326
126       Number of Gotos: 4061       Number of Gotos: 7493
127       Number of Goto/Reduces: 687       Number of Goto/Reduces: 1041
128       Number of Reduces: 2823       Number of Reduces: 3958
129       Number of Defaults: 390       Number of Defaults: 475
130    
131  Error maps storage:  Error maps storage:
132      Storage required for ACTION_SYMBOLS_BASE map: 1182 Bytes      Storage required for ACTION_SYMBOLS_BASE map: 1908 Bytes
133      Storage required for ACTION_SYMBOLS_RANGE map: 1007 Bytes      Storage required for ACTION_SYMBOLS_RANGE map: 1709 Bytes
134      Storage required for NACTION_SYMBOLS_BASE map: 1182 Bytes      Storage required for NACTION_SYMBOLS_BASE map: 1908 Bytes
135      Storage required for NACTION_SYMBOLS_RANGE map: 630 Bytes      Storage required for NACTION_SYMBOLS_RANGE map: 960 Bytes
136      Storage required for SYMBOL_INDEX map: 616 Bytes      Storage required for TERMINAL_INDEX map: 220 Bytes
137      Storage required for STRING_BUFFER map: 4652 Bytes      Storage required for NON_TERMINAL_INDEX map: 614 Bytes
138        Storage required for STRING_BUFFER map: 12004 Bytes
139    
140  ***Warning: Base Check vector contains value > 127. 16-bit words used.  ***Warning: Base Check vector contains value > 127. 16-bit words used.
 ***Warning: Terminal symbol > 127. 16-bit words used.  
141  Escaped symbol $eof is an invalid C variable.  Escaped symbol $eof is an invalid C variable.
142    
143  Escaped symbol $error is an invalid C variable.  Escaped symbol $error is an invalid C variable.
144   </PRE>   </PRE>
145   It can be quite different if the output changed since version 2.30 of LPG. The important part is:<br>   It can be quite different if the output changed since version 1.3 of jikespg. The important part is:<br>
146   <blockquote><b>This grammar is LALR(1).</b></blockquote>   <blockquote><b>This grammar is LALR(1).</b></blockquote>
147   This creates some java source files and information files in the current directory.   This creates some java source files and information files in the current directory.
148   <blockquote><table BORDER=1 CELLSPACING=2 CELLPADDING=10>   <blockquote><table BORDER=1 CELLSPACING=2 CELLPADDING=10>
149   <tr>   <tr>
150   <th VALIGN=top align=left>java.l</th>   <th VALIGN=top align=left>java.l</th>
151   <td VALIGN=top>Log information generated by lpg/jikespg. Enumarates all the states created for the automaton, etc.</td>   <td VALIGN=top>Information generated by jikespg. Enumarate all the states created for the automaton, etc.</td>
152   </tr>   </tr>
153   <tr>   <tr>
154   <th VALIGN=top align=left>JavaAction.java</th>   <th VALIGN=top align=left>JavaAction.java</th>
# Line 151  Line 164 
164   </tr>   </tr>
165   <tr>   <tr>
166  <th VALIGN=top align=left>javasym.java</th>  <th VALIGN=top align=left>javasym.java</th>
167   <td>This is the contents of the class org.eclipse.jdt.core.compiler.TerminalTokens.</td>   <td>Contents of the class org.eclipse.jdt.core.compiler.TerminalTokens.</td>
168   </tr>   </tr>
169   <tr>   <tr>
170  <th VALIGN=top align=left>javadef.java</th>  <th VALIGN=top align=left>javadef.java</th>
171   <td>This is the contents of the class org.eclipse.jdt.internal.compiler.parser.ParserBasicInformation.</td>   <td>Contents of the class org.eclipse.jdt.internal.compiler.parser.ParserBasicInformation.</td>
172   </tr>   </tr>
173   <tr>   <tr>
174  <th VALIGN=top align=left>javaprs.java</th>  <th VALIGN=top align=left>javaprs.java</th>
# Line 168  Line 181 
181   <ol>   <ol>
182   <li>Copy the contents of the <font color="#3366FF">JavaAction.java</font> file into the <font color="#3366FF">consumeRule(int)</font> method of the org.eclipse.jdt.internal.compiler.parser.Parser class.   <li>Copy the contents of the <font color="#3366FF">JavaAction.java</font> file into the <font color="#3366FF">consumeRule(int)</font> method of the org.eclipse.jdt.internal.compiler.parser.Parser class.
183   </li>   </li>
184   <li>The class <font color="#3366FF">org.eclipse.jdt.internal.compiler.parser.ParserBasicInformation</font> needs to be updated with the contents of the file <font color="#3366FF">javadef.java</font>. Don't copy the   <li>The class <font color="#3366FF">org.eclipse.jdt.internal.compiler.parser.ParserBasicInformation</font> needs to be updated with the content of the file <font color="#3366FF">javadef.java</font>. Don't copy the
185   interface name. Simply copy the field declarations. The actual source of this class will guide you.</li>   interface name. Simply copy the field declarations. The actual source of this class will guide you.</li>
186   <li>Similarly, update the class <font color="#3366FF">org.eclipse.jdt.internal.compiler.parser.TerminalTokens</font> with the contents of the file <font color="#3366FF">javasym.java</font>.   <li>Similarly, update the class <font color="#3366FF">org.eclipse.jdt.internal.compiler.parser.TerminalTokens</font> with the contents of the file <font color="#3366FF">javasym.java</font>.</li>
187   <li>The last step is to update the resource files:<br>   <li>The last step is to update the resource files:<br>
188   Copy the jdtcore.jar file in d:\temp. Compile this <A HREF="UpdateParserFiles.java">source</A> inside d:\temp. You will have a file UpdateParserFiles.class.   Copy the jdtcore.jar file in d:\temp. Compile this <A HREF="UpdateParserFiles.java">source</A> inside d:\temp. You will have a file UpdateParserFiles.class.
189   Then run the following command-line:   Then run the following command-line:
# Line 184  Line 197 
197   </ol>   </ol>
198   </li>   </li>
199   </ol>   </ol>
200     <p><b>Warning:</b> <blockquote>If the number of terminals is over 128, then the parser term_check field needs to be converted
201     to a <code>char[]</code>. Also the generation of the parser resources files needs to be changed to support
202     an array of <code>char[]</code>.
203     </blockquote></p>
204   <P>   <P>
205   <b>NOTE:</b>  <blockquote>Changing the parser is a risky operation if you miss one of the steps above. The resulting parser can be completely   <b>NOTE:</b>  <blockquote>Changing the parser is a risky operation if you miss one of the steps above. The resulting parser can be completely
206   unpredictable. It can go from crashing to reporting invalid errors. Be sure that you followed all the steps and that all the   unpredictable. It can go from crashing to reporting invalid errors. Be sure that you followed all the steps and that all the

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8