Package fasp.parser.parsers

Source Code of fasp.parser.parsers.VariableParser

/*
* 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.FaspVariable;

/**
*
* @author Jeroen Janssen <Jeroen.Janssen@vub.ac.be>
*/
public class VariableParser extends AbstractParser<FaspVariable> {

  /**
   * 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 FaspVariable 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.isUpperCase(sym.getSymbol().charAt(0))) {
          st.eat();
          return new FaspVariable(sym.getSymbol());
        } else {
          throw new ParseException(st,"variable","constant");
        }
      } else {
        throw new ParseException(st,"variable",st.lookahead().toString());
      }
    } else {
      return getResult();
    }
  }
}
TOP

Related Classes of fasp.parser.parsers.VariableParser

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.