All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unlaxer.tinyexpression.parser.ExpressionParser Maven / Gradle / Ivy

package org.unlaxer.tinyexpression.parser;

import org.unlaxer.parser.Parser;
import org.unlaxer.parser.RootParserIndicator;
import org.unlaxer.parser.ascii.MinusParser;
import org.unlaxer.parser.ascii.PlusParser;
import org.unlaxer.parser.combinator.Chain;
import org.unlaxer.parser.combinator.Choice;
import org.unlaxer.parser.combinator.NoneChildCollectingParser;
import org.unlaxer.parser.combinator.ZeroOrMore;

public class ExpressionParser extends NoneChildCollectingParser implements RootParserIndicator{
	
	private static final long serialVersionUID = -2100891203224283395L;
	
	Parser parser;

	public ExpressionParser() {
		super();
	}

	@Override
	public void initialize() {
		//  ::= [('+'|'-')]*
		parser = 
			new Chain(
					Parser.get(TermParser.class),
					new ZeroOrMore(
						new Chain(
							new Choice(
								Parser.get(PlusParser.class),
								Parser.get(MinusParser.class)
							),
							Parser.get(TermParser.class)
						)
					)
				);
	}



	@Override
	public Parser createParser() {
		return parser;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy