| /* | |
| * Licensed to the Apache Software Foundation (ASF) under one | |
| * or more contributor license agreements. See the NOTICE file | |
| * distributed with this work for additional information | |
| * regarding copyright ownership. The ASF licenses this file | |
| * to you under the Apache License, Version 2.0 (the | |
| * "License"); you may not use this file except in compliance | |
| * with the License. You may obtain a copy of the License at | |
| * | |
| * https://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, | |
| * software distributed under the License is distributed on an | |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| * KIND, either express or implied. See the License for the | |
| * specific language governing permissions and limitations | |
| * under the License. | |
| */ | |
| Mini-Mini tutorial | |
| ------------------ | |
| Mini is a very simple (semi-functional) language that I wrote to test | |
| the generic package of BCEL. | |
| https://commons.apache.org/bcel/ | |
| Mini uses the JavaCC parser generator which comes precompiled from | |
| http://www.webgain.com/products/java_cc/ | |
| After setting the CLASSPATH to the directory just above the Mini | |
| directory, for example | |
| % cd Mini | |
| % setenv CLASSPATH $CLASSPATH:.:.. | |
| try the following: | |
| % java Mini.MiniC max.mini | |
| This produces a Java class file (max.class) which you can execute with | |
| % java max | |
| Enter a number (for example, 4) and you will be asked to enter 4 numbers. The | |
| program will then tell you the biggest of them. | |
| Alternatively, you can produce a Java file (max.java) which will be | |
| translated automatically to a .class file. | |
| % java Mini.MiniC -java max.mini | |
| There are three examples programs (max.mini, fac.mini, fib.mini) | |
| provided which demonstrate the language syntax and should be quite | |
| easy to understand. | |
| The compiler is not that well documented, I'm afraid, but if you've | |
| ever seen a compiler before, you should be able to understand what I'm | |
| doing. The part that produces the byte code is contained in the | |
| byte_code() method that all AST nodes implement. Take a look at | |
| MiniC.java at line 85 and follow the recursive byte_code() calls. | |
| It's also useful to use the listclass program provided with BCEL | |
| to examine the generated class. For example | |
| % java listclass max.class | |
| Send bug reports and suggestions to | |
| m.dahm@gmx.de (Markus Dahm) |