javax0.jamal.prog.analyzer.Expression2 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jamal-prog Show documentation
Show all versions of jamal-prog Show documentation
Jamal module for Programmatic Extension
package javax0.jamal.prog.analyzer;
import javax0.jamal.api.BadSyntax;
import javax0.jamal.prog.commands.Operation;
/**
* An expression2 is
*
* expression3 '+' expression2
* expression3 '-' expression2
* expression3
*
*/
public class Expression2 {
public static javax0.jamal.prog.commands.Expression analyze(final Lex.List lexes) throws BadSyntax {
if (lexes.isEmpty()) {
throw new BadSyntax("Expression is empty");
}
var expression3 = Expression3.analyze(lexes);
if (lexes.is("-") || lexes.is("+")) {
final var op = lexes.next().text;
return new Operation(op, expression3, Expression2.analyze(lexes));
}
return expression3;
}
}