Search in sources :

Example 1 with Syntax

use of priv.bajdcc.LALR1.syntax.Syntax in project jMiniLang by bajdcc.

the class TestSyntax method main.

public static void main(String[] args) {
    // System.out.println("Z -> `a`<,> | B | [`a` `b` Z B]");
    try {
        // Scanner scanner = new Scanner(System.in);
        Syntax syntax = new Syntax();
        syntax.addTerminal("PLUS", TokenType.OPERATOR, OperatorType.PLUS);
        syntax.addTerminal("MINUS", TokenType.OPERATOR, OperatorType.MINUS);
        syntax.addTerminal("TIMES", TokenType.OPERATOR, OperatorType.TIMES);
        syntax.addTerminal("DIVIDE", TokenType.OPERATOR, OperatorType.DIVIDE);
        syntax.addTerminal("LPA", TokenType.OPERATOR, OperatorType.LPARAN);
        syntax.addTerminal("RPA", TokenType.OPERATOR, OperatorType.RPARAN);
        syntax.addTerminal("SYMBOL", TokenType.ID, "i");
        syntax.addNonTerminal("E");
        syntax.addNonTerminal("T");
        syntax.addNonTerminal("F");
        syntax.addErrorHandler("sample", null);
        // syntax.infer("E -> T `PLUS`<+> E | T `MINUS`<-> E | T");
        // syntax.infer("T -> F `TIMES`<*> T | F `DIVIDE`</> T | F");
        // syntax.infer("F -> `LPA`<(> E `RPA`<)>  | `SYMBOL`<i>");
        syntax.infer("E -> E @PLUS<+> T");
        syntax.infer("E -> E @MINUS<-> T");
        syntax.infer("E -> T");
        syntax.infer("T -> T @TIMES<*> F");
        syntax.infer("T -> T @DIVIDE</> F");
        syntax.infer("T -> F");
        syntax.infer("F -> @LPA<(> E @RPA<)>");
        syntax.infer("F -> @SYMBOL<i>");
        syntax.initialize("E");
        System.out.println(syntax.toString());
        System.out.println(syntax.getNGAString());
        System.out.println(syntax.getNPAString());
    // scanner.close();
    } catch (RegexException e) {
        System.err.println(e.getPosition() + "," + e.getMessage());
        e.printStackTrace();
    } catch (SyntaxException e) {
        System.err.println(e.getPosition() + "," + e.getMessage() + " " + e.getInfo());
        e.printStackTrace();
    }
}
Also used : SyntaxException(priv.bajdcc.LALR1.syntax.handler.SyntaxException) RegexException(priv.bajdcc.util.lexer.error.RegexException) Syntax(priv.bajdcc.LALR1.syntax.Syntax)

Example 2 with Syntax

use of priv.bajdcc.LALR1.syntax.Syntax in project jMiniLang by bajdcc.

the class TestSyntax2 method main.

public static void main(String[] args) {
    try {
        // Scanner scanner = new Scanner(System.in);
        Syntax syntax = new Syntax();
        syntax.addTerminal("a", TokenType.ID, "a");
        syntax.addTerminal("b", TokenType.ID, "b");
        syntax.addNonTerminal("Z");
        syntax.addNonTerminal("S");
        syntax.addNonTerminal("B");
        syntax.addErrorHandler("sample", null);
        syntax.infer("Z -> S");
        syntax.infer("S -> B B");
        syntax.infer("B -> @a B");
        syntax.infer("B -> @b");
        syntax.initialize("Z");
        System.out.println(syntax.toString());
        System.out.println(syntax.getNGAString());
        System.out.println(syntax.getNPAString());
    // scanner.close();
    } catch (RegexException e) {
        System.err.println(e.getPosition() + "," + e.getMessage());
        e.printStackTrace();
    } catch (SyntaxException e) {
        System.err.println(e.getPosition() + "," + e.getMessage() + " " + e.getInfo());
        e.printStackTrace();
    }
}
Also used : SyntaxException(priv.bajdcc.LALR1.syntax.handler.SyntaxException) RegexException(priv.bajdcc.util.lexer.error.RegexException) Syntax(priv.bajdcc.LALR1.syntax.Syntax)

Example 3 with Syntax

use of priv.bajdcc.LALR1.syntax.Syntax in project jMiniLang by bajdcc.

the class TestSyntax3 method main.

public static void main(String[] args) {
    try {
        // Scanner scanner = new Scanner(System.in);
        Syntax syntax = new Syntax();
        syntax.addTerminal("a", TokenType.ID, "a");
        syntax.addTerminal("c", TokenType.ID, "c");
        syntax.addTerminal("d", TokenType.ID, "d");
        syntax.addNonTerminal("S");
        syntax.addNonTerminal("A");
        syntax.addErrorHandler("sample", null);
        syntax.infer("S -> @c A @d");
        syntax.infer("A -> @a");
        syntax.infer("A -> A @a");
        syntax.initialize("S");
        System.out.println(syntax.toString());
        System.out.println(syntax.getNGAString());
        System.out.println(syntax.getNPAString());
    // scanner.close();
    } catch (RegexException e) {
        System.err.println(e.getPosition() + "," + e.getMessage());
        e.printStackTrace();
    } catch (SyntaxException e) {
        System.err.println(e.getPosition() + "," + e.getMessage() + " " + e.getInfo());
        e.printStackTrace();
    }
}
Also used : SyntaxException(priv.bajdcc.LALR1.syntax.handler.SyntaxException) RegexException(priv.bajdcc.util.lexer.error.RegexException) Syntax(priv.bajdcc.LALR1.syntax.Syntax)

Example 4 with Syntax

use of priv.bajdcc.LALR1.syntax.Syntax in project jMiniLang by bajdcc.

the class TestSyntax method main.

public static void main(String[] args) {
    // System.out.println("Z -> `a`<,> | B | [`a` `b` Z B]");
    try {
        // Scanner scanner = new Scanner(System.in);
        Syntax syntax = new Syntax();
        syntax.addTerminal("SYMBOL", TokenType.ID, "i");
        syntax.addTerminal("PLUS", TokenType.OPERATOR, OperatorType.PLUS);
        syntax.addTerminal("MINUS", TokenType.OPERATOR, OperatorType.MINUS);
        syntax.addTerminal("TIMES", TokenType.OPERATOR, OperatorType.TIMES);
        syntax.addTerminal("DIVIDE", TokenType.OPERATOR, OperatorType.DIVIDE);
        syntax.addTerminal("LPA", TokenType.OPERATOR, OperatorType.LPARAN);
        syntax.addTerminal("RPA", TokenType.OPERATOR, OperatorType.RPARAN);
        syntax.setEpsilonName("epsilon");
        String[] nons = new String[] { "E", "E1", "T", "T1", "F", "A", "M" };
        for (String non : nons) {
            syntax.addNonTerminal(non);
        }
        syntax.infer("E -> T E1");
        syntax.infer("E1 -> A T E1 | @epsilon");
        syntax.infer("T -> F T1");
        syntax.infer("T1 -> M F T1 | @epsilon");
        syntax.infer("F -> @LPA E @RPA | @SYMBOL");
        syntax.infer("A -> @PLUS | @MINUS");
        syntax.infer("M -> @TIMES | @DIVIDE");
        syntax.initialize("E");
        System.out.println(syntax.toString());
    // scanner.close();
    } catch (RegexException e) {
        System.err.println(e.getPosition() + "," + e.getMessage());
        e.printStackTrace();
    } catch (SyntaxException e) {
        System.err.println(e.getPosition() + "," + e.getMessage() + " " + e.getInfo());
        e.printStackTrace();
    }
}
Also used : SyntaxException(priv.bajdcc.LL1.syntax.handler.SyntaxException) RegexException(priv.bajdcc.util.lexer.error.RegexException) Syntax(priv.bajdcc.LL1.syntax.Syntax)

Aggregations

RegexException (priv.bajdcc.util.lexer.error.RegexException)4 Syntax (priv.bajdcc.LALR1.syntax.Syntax)3 SyntaxException (priv.bajdcc.LALR1.syntax.handler.SyntaxException)3 Syntax (priv.bajdcc.LL1.syntax.Syntax)1 SyntaxException (priv.bajdcc.LL1.syntax.handler.SyntaxException)1