KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javacc > parser > JavaCCErrors


1 /*
2  * Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
3  * California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has
4  * intellectual property rights relating to technology embodied in the product
5  * that is described in this document. In particular, and without limitation,
6  * these intellectual property rights may include one or more of the U.S.
7  * patents listed at http://www.sun.com/patents and one or more additional
8  * patents or pending patent applications in the U.S. and in other countries.
9  * U.S. Government Rights - Commercial software. Government users are subject
10  * to the Sun Microsystems, Inc. standard license agreement and applicable
11  * provisions of the FAR and its supplements. Use is subject to license terms.
12  * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
13  * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. This
14  * product is covered and controlled by U.S. Export Control laws and may be
15  * subject to the export or import laws in other countries. Nuclear, missile,
16  * chemical biological weapons or nuclear maritime end uses or end users,
17  * whether direct or indirect, are strictly prohibited. Export or reexport
18  * to countries subject to U.S. embargo or to entities identified on U.S.
19  * export exclusion lists, including, but not limited to, the denied persons
20  * and specially designated nationals lists is strictly prohibited.
21  */

22
23 package org.javacc.parser;
24
25 public class JavaCCErrors {
26
27   private static int parse_error_count = 0, semantic_error_count = 0, warning_count = 0;
28
29   private static void printLocationInfo(Object JavaDoc node) {
30     if (node instanceof NormalProduction) {
31       NormalProduction n = (NormalProduction)node;
32       System.err.print("Line " + n.line + ", Column " + n.column + ": ");
33     } else if (node instanceof TokenProduction) {
34       TokenProduction n = (TokenProduction)node;
35       System.err.print("Line " + n.line + ", Column " + n.column + ": ");
36     } else if (node instanceof Expansion) {
37       Expansion n = (Expansion)node;
38       System.err.print("Line " + n.line + ", Column " + n.column + ": ");
39     } else if (node instanceof CharacterRange) {
40       CharacterRange n = (CharacterRange)node;
41       System.err.print("Line " + n.line + ", Column " + n.column + ": ");
42     } else if (node instanceof SingleCharacter) {
43       SingleCharacter n = (SingleCharacter)node;
44       System.err.print("Line " + n.line + ", Column " + n.column + ": ");
45     } else if (node instanceof Token) {
46       Token t = (Token)node;
47       System.err.print("Line " + t.beginLine + ", Column " + t.beginColumn + ": ");
48     }
49   }
50
51   public static void parse_error(Object JavaDoc node, String JavaDoc mess) {
52     System.err.print("Error: ");
53     printLocationInfo(node);
54     System.err.println(mess);
55     parse_error_count++;
56   }
57
58   public static void parse_error(String JavaDoc mess) {
59     System.err.print("Error: ");
60     System.err.println(mess);
61     parse_error_count++;
62   }
63
64   public static int get_parse_error_count() {
65     return parse_error_count;
66   }
67
68   public static void semantic_error(Object JavaDoc node, String JavaDoc mess) {
69     System.err.print("Error: ");
70     printLocationInfo(node);
71     System.err.println(mess);
72     semantic_error_count++;
73   }
74
75   public static void semantic_error(String JavaDoc mess) {
76     System.err.print("Error: ");
77     System.err.println(mess);
78     semantic_error_count++;
79   }
80
81   public static int get_semantic_error_count() {
82     return semantic_error_count;
83   }
84
85   public static void warning(Object JavaDoc node, String JavaDoc mess) {
86     System.err.print("Warning: ");
87     printLocationInfo(node);
88     System.err.println(mess);
89     warning_count++;
90   }
91
92   public static void warning(String JavaDoc mess) {
93     System.err.print("Warning: ");
94     System.err.println(mess);
95     warning_count++;
96   }
97
98   public static int get_warning_count() {
99     return warning_count;
100   }
101
102   public static int get_error_count() {
103     return parse_error_count + semantic_error_count;
104   }
105
106    public static void reInit()
107    {
108       parse_error_count = 0;
109       semantic_error_count = 0;
110       warning_count = 0;
111    }
112
113 }
114
Popular Tags