View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2001-2004 Open World Ltd
4   // Copyright (C) 2004 Stephen F. K. Leach
5   // Copyright (C) 2004-2005 Kevin Rogers
6   //
7   // This file is part of MillScript.
8   //
9   // MillScript is free software; you can redistribute it and/or modify it under
10  // the terms of the GNU General Public License as published by the Free
11  // Software Foundation; either version 2 of the License, or (at your option)
12  // any later version.
13  //
14  // MillScript is distributed in the hope that it will be useful, but WITHOUT
15  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17  // more details.
18  //
19  // You should have received a copy of the GNU General Public License along with
20  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
21  // Place, Suite 330, Boston, MA  02111-1307  USA
22  ////////////////////////////////////////////////////////////////////////////////
23  package org.millscript.office.spreadsheet.formula;
24  
25  import org.millscript.millscript.conf.Configuration;
26  import org.millscript.millscript.syntax.AppendSyntax;
27  import org.millscript.millscript.syntax.ConfigurationParserImpl;
28  import org.millscript.office.spreadsheet.formula.syntax.AddSyntax;
29  import org.millscript.office.spreadsheet.formula.syntax.DivSyntax;
30  import org.millscript.office.spreadsheet.formula.syntax.MulSyntax;
31  import org.millscript.office.spreadsheet.formula.syntax.PercentSyntax;
32  import org.millscript.office.spreadsheet.formula.syntax.PowerSyntax;
33  import org.millscript.office.spreadsheet.formula.syntax.SubSyntax;
34  
35  import java.io.Reader;
36  
37  //    Constants: string, number
38  //    Variables
39  //    RelOps:           < <= == >= >
40  //    Assignment:       x := E
41  //    Application:      f(x)
42  //    Conditionals:     if, unless
43  //    Loops:            for
44  
45  /**
46   * This class implements the MillScript parser.
47   */
48  public class FormulaParserImpl extends ConfigurationParserImpl {
49  
50      //    Initializer
51      static {
52          // Arithmetic
53          put( "+", new AddSyntax().setPrec( ARITH_PREC + 100 ) );
54          put( "-", new SubSyntax().setPrec( ARITH_PREC + 100 ) );
55          put( "*", new MulSyntax().setPrec( ARITH_PREC + 200 ) );
56          put( "/", new DivSyntax().setPrec( ARITH_PREC + 200 ) );
57          put( "^", new PowerSyntax().setPrec( ARITH_PREC + 200 ) );
58          put( "&", new AppendSyntax().setPrec( ARITH_PREC + 200 ) );
59  
60          // Postfix
61          put( "%", new PercentSyntax().setPrec( ARITH_PREC + 100 ) );
62      }
63  
64      /**
65       * Constructs a new <code>ParserImpl</code> with the specified origin, source,
66       * interactive prompt and end of line comment status.
67       *
68       * @param origin    the origin message for this tokenizer
69       * @param r         the character source to tokenize
70       * @param eolc      flag indicating if end of line comments are supported
71       * @param c         the configuration
72       */
73      public FormulaParserImpl( final String origin, final Reader r, final Configuration c ) {
74          super( origin, r, false, c );
75      }
76  
77  }