Package fasp.parser.parsers

Source Code of fasp.parser.parsers.ConstantParser

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package fasp.parser.parsers;

import fasp.parser.tokenizer.SymbolToken;
import fasp.parser.*;
import fasp.parser.tokenizer.Token;
import fasp.parser.tokenizer.TokenState;
import fasp.datatypes.FaspConstant;

/**
*
* @author Jeroen Janssen <Jeroen.Janssen@vub.ac.be>
*/
public class ConstantParser extends AbstractParser<FaspConstant> {
  /**
   * This parse function consumes no input on failure and is thus
   * safe to use in tryParse.
   * @param st
   * @return
   * @throws fasp.parser.ParseException
   */
  @Override
  public FaspConstant parse(TokenState st) throws ParseException {
    if (getResult() == null) {
      Token lookahead = st.lookahead();
      if(lookahead.getType().equals(Token.Type.SYMBOL)) {
        SymbolToken sym = (SymbolToken)lookahead;
        if(Character.isLowerCase(sym.getSymbol().charAt(0))) {
          st.eat();
          return new FaspConstant(sym.getSymbol());
        } else {
          throw new ParseException(st,"constant","variable");
        }
      } else {
        throw new ParseException(st,"constant",st.lookahead().toString());
      }
    } else {
      return getResult();
    }
  }
}
TOP

Related Classes of fasp.parser.parsers.ConstantParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.