KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > beaver > Action


1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * This file is part of Beaver Parser Generator. *
3  * Copyright (C) 2003,2004 Alexander Demenchuk <alder@softanvil.com>. *
4  * All rights reserved. *
5  * See the file "LICENSE" for the terms and conditions for copying, *
6  * distribution and modification of Beaver. *
7  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

8
9 package beaver;
10
11 /**
12  * An "interface" to Java code executed when a production is reduced.
13  */

14 public abstract class Action
15 {
16     static public final Action NONE = new Action()
17     {
18         public Symbol reduce(Symbol[] args, int offset)
19         {
20             return new Symbol(null);
21         }
22     };
23     
24     static public final Action RETURN = new Action()
25     {
26         public Symbol reduce(Symbol[] args, int offset)
27         {
28             return args[offset + 1];
29         }
30     };
31     
32     /**
33      * Am action code that is executed when the production is reduced.
34      *
35      * @param args an array part of which is filled with this action arguments
36      * @param offset to the last element <b>BEFORE</b> the first argument of this action
37      * @return a symbol or a value of a LHS nonterminal
38      */

39     public abstract Symbol reduce(Symbol[] args, int offset);
40 }
41
Popular Tags