~ubuntu-branches/ubuntu/gutsy/jflex/gutsy

« back to all changes in this revision

Viewing changes to examples/cup/Main.java

  • Committer: Bazaar Package Importer
  • Author(s): Takashi Okamoto
  • Date: 2002-02-16 13:38:21 UTC
  • Revision ID: james.westby@ubuntu.com-20020216133821-5wsdprpt9xl7ondr
Tags: upstream-1.3.5
ImportĀ upstreamĀ versionĀ 1.3.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  This example comes from a short article series in the Linux 
 
3
  Gazette by Richard A. Sevenich and Christopher Lopes, titled
 
4
  "Compiler Construction Tools". The article series starts at
 
5
 
 
6
  http://www.linuxgazette.com/issue39/sevenich.html
 
7
 
 
8
  Small changes and updates to newest JFlex+Cup versions 
 
9
  by Gerwin Klein
 
10
*/
 
11
 
 
12
/*
 
13
  Commented By: Christopher Lopes
 
14
  File Name: Main.java
 
15
  To Create: 
 
16
  After the scanner, lcalc.flex, and the parser, ycalc.cup, have been created.
 
17
  > javac Main.java
 
18
  
 
19
  To Run: 
 
20
  > java Main test.txt
 
21
  where test.txt is an test input file for the calculator.
 
22
*/
 
23
   
 
24
import java.io.*;
 
25
   
 
26
class Main {
 
27
  static public void main(String argv[]) {    
 
28
    /* Start the parser */
 
29
    try {
 
30
      parser p = new parser(new Lexer(new FileReader(argv[0])));
 
31
      Object result = p.parse().value;      
 
32
    } catch (Exception e) {
 
33
      /* do cleanup here -- possibly rethrow e */
 
34
      e.printStackTrace();
 
35
    }
 
36
  }
 
37
}
 
38
 
 
39