/*********************************************************************
*
*      Copyright (C) 2002 Andrew Khan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/

package jxl.biff.formula;

/**
 * This file is generated by JLex.  Do not alter the contents of this file
 * because changes will be overridden
 */

import jxl.biff.WorkbookMethods;

%%

%{
  int getPos() { return yychar ; }
%}

%{
  private boolean emptyString;
%}

%{
  private ExternalSheet externalSheet;
  private WorkbookMethods nameTable;

  void setExternalSheet(ExternalSheet es)
  {
    externalSheet = es;
  }

  void setNameTable(WorkbookMethods nt)
  {
    nameTable = nt;
  }
%}

%yylexthrow{
 jxl.biff.formula.FormulaException
%yylexthrow}

%line
%char
%type ParseItem
%state YYSTRING

ALPHA=[A-Za-z]
DIGIT=[0-9]
SYMBOL=[$!%^&*#_=+;:#~@/?.,<>|-]
INTEGER={DIGIT}+
FLOAT={DIGIT}+"."{DIGIT}+
NON_RELATIVE_CELL_IND="$"
CELL_REFERENCE={NON_RELATIVE_CELL_IND}?{ALPHA}{ALPHA}?{NON_RELATIVE_CELL_IND}?{INTEGER}
CELL_RANGE={CELL_REFERENCE}:{CELL_REFERENCE}
CELL_RANGE_3D={CELL_REFERENCE_3D}:{CELL_REFERENCE}
CELL_REFERENCE_3D={SINGLE_QUOTE}?({ALPHA}|{DIGIT}|{WHITE_SPACE}|{SYMBOL})+{SINGLE_QUOTE}?!{CELL_REFERENCE} | {SINGLE_QUOTE}({ALPHA}|{DIGIT}|{WHITE_SPACE}|{SYMBOL}|{OPEN_PARENTHESES}|{CLOSE_PARENTHESES})+{SINGLE_QUOTE}!{CELL_REFERENCE}
NAME={ALPHA}{ALPHA}({ALPHA}|{INTEGER})*
WHITE_SPACE=[\n\ \t\b\012]
ARGUMENT_SEPARATOR=","
OPEN_PARENTHESES="("
CLOSE_PARENTHESES=")"
FUNCTION={ALPHA}+{OPEN_PARENTHESES}
QUOTE="\""
STRING=[^{QUOTE}]*
SINGLE_QUOTE="'"


%% 

<YYINITIAL> "+"  { return new Plus() ;}
<YYINITIAL> "-"  { return new Minus() ; }
<YYINITIAL> "*"  { return new Multiply() ; }
<YYINITIAL> "/"  { return new Divide() ; }
<YYINITIAL> ">"  { return new GreaterThan() ; }
<YYINITIAL> "="  { return new Equal() ; }
<YYINITIAL> ">=" { return new GreaterEqual() ; }
<YYINITIAL> "<"  { return new LessThan() ; }
<YYINITIAL> "<=" { return new LessEqual() ; }
<YYINITIAL> {ARGUMENT_SEPARATOR} { return new ArgumentSeparator() ; }
<YYINITIAL> {INTEGER} { return new IntegerValue(yytext()) ; }
<YYINITIAL> {FLOAT} { return new DoubleValue(yytext()) ; }
<YYINITIAL> {CELL_REFERENCE} { return new CellReference(yytext()) ; }
<YYINITIAL> {CELL_RANGE_3D} { return new Area3d(yytext(),externalSheet) ; }
<YYINITIAL> {CELL_RANGE} { return new Area(yytext()) ; }
<YYINITIAL> {CELL_REFERENCE_3D} 
             { return new CellReference3d(yytext(),externalSheet) ; }
<YYINITIAL> {NAME} {return new NameRange(yytext(), nameTable); }
<YYINITIAL> {WHITE_SPACE} {}
<YYINITIAL> {OPEN_PARENTHESES} { return new OpenParentheses() ;}
<YYINITIAL> {CLOSE_PARENTHESES} { return new CloseParentheses() ;}
<YYINITIAL> {FUNCTION} { return new StringFunction(yytext()) ; }
<YYINITIAL> {QUOTE} {emptyString = true; yybegin(YYSTRING);}

<YYSTRING>  {STRING} {emptyString = false; return new StringValue(yytext()) ; }
<YYSTRING>  {QUOTE} {yybegin(YYINITIAL); if (emptyString) return new StringValue("");}


