Package fasp.parser.parsers

Source Code of fasp.parser.parsers.BodyExpParser

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

package fasp.parser.parsers;

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

/**
*
* @author Jeroen Janssen <Jeroen.Janssen@vub.ac.be>
*/
public class BodyExpParser extends AbstractParser<BodyExpression> {
  public BodyExpression parse(TokenState st) throws ParseException {
    FaspVariable leftOp = new VariableParser().parse(st);
    FaspBodyOp op;
    Token opTok = st.getNext();
    if(opTok.getType().equals(Token.Type.NEQOP))
      op = new FaspBodyOpIneq();
    else if(opTok.getType().equals(Token.Type.EQOP))
      op = new FaspBodyOpEq();
    else
      throw new ParseException(opTok.getLocation(),"body expression operator (== or /=)",opTok.toString());

    ConstantParser constP = new ConstantParser();
    VariableParser varP = new VariableParser();
    if(constP.tryParse(st))
      return new BodyExpression(op,leftOp,constP.getResult());
    else if (varP.tryParse(st))
      return new BodyExpression(op,leftOp,varP.getResult());
    else
      throw new ParseException(st,"variable or constant",st.lookahead().toString());
  }
}
TOP

Related Classes of fasp.parser.parsers.BodyExpParser

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.