
org.parboiled.examples.abc.Main Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2009-2011 Mathias Doenitz
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.parboiled.examples.abc;
import org.parboiled.Parboiled;
import org.parboiled.common.StringUtils;
import org.parboiled.errors.ErrorUtils;
import org.parboiled.parserunners.RecoveringParseRunner;
import static org.parboiled.support.ParseTreeUtils.printNodeTree;
import org.parboiled.parserunners.ReportingParseRunner;
import org.parboiled.support.ParsingResult;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
AbcParser parser = Parboiled.createParser(AbcParser.class);
while (true) {
System.out.print("Enter an a^n b^n c^n expression (single RETURN to exit)!\n");
String input = new Scanner(System.in).nextLine();
if (StringUtils.isEmpty(input)) break;
ParsingResult> result = new ReportingParseRunner(parser.S()).run(input);
if (!result.parseErrors.isEmpty())
System.out.println(ErrorUtils.printParseError(result.parseErrors.get(0)));
else
System.out.println(printNodeTree(result) + '\n');
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy