Search in sources :

Example 16 with RegexException

use of priv.bajdcc.util.lexer.error.RegexException 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 17 with RegexException

use of priv.bajdcc.util.lexer.error.RegexException 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 18 with RegexException

use of priv.bajdcc.util.lexer.error.RegexException in project jMiniLang by bajdcc.

the class UIMainFrame method startOS.

private void startOS(UIGraphics g) {
    IOSCodePage[] pages = new IOSCodePage[] { // OS
    new OSEntry(), new OSIrq(), new OSTask(), // IRQ
    new IRPrint(), new IRRemote(), new IRTask(), new IRSignal(), // TASK
    new TKSystem(), new TKUtil(), new TKUI(), new TKNet(), // UI
    new UIMain(), new UIClock(), new UIHitokoto(), new UIMonitor(), // USER
    new UserMain(), // USER ROUTINE
    new URShell(), new UREcho(), new URPipe(), new URDup(), new URGrep(), new URRange(), new URProc(), new URTask(), new URSleep(), new URTime(), new URCount(), new URTest(), new URMsg(), new URNews(), new URBash(), new URReplace(), new URUtil(), new URAI(), // USER FILE
    new URFileLoad(), new URFileSave(), new URFileAppend() };
    try {
        String code = "import \"sys.base\";\n" + "import \"sys.proc\";\n" + "call g_load_sync_x(\"/kern/entry\");\n";
        interpreter = new Interpreter();
        for (IOSCodePage page : pages) {
            interpreter.load(page);
        }
        Grammar grammar = new Grammar(code);
        // System.out.println(grammar.toString());
        RuntimeCodePage page = grammar.getCodePage();
        // System.out.println(page.toString());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        RuntimeCodePage.exportFromStream(page, baos);
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        interpreter.run("@main", bais);
    } catch (RegexException e) {
        System.err.println();
        System.err.println(e.getPosition() + "," + e.getMessage());
        e.printStackTrace();
    } catch (SyntaxException e) {
        System.err.println();
        System.err.println(String.format("模块名:%s. 位置:%s. 错误:%s-%s(%s:%d)", e.getPageName(), e.getPosition(), e.getMessage(), e.getInfo(), e.getFileName(), e.getPosition().iLine + 1));
        e.printStackTrace();
    } catch (RuntimeException e) {
        System.err.println();
        System.err.println(e.getkError().getMessage() + " " + e.getPosition() + ": " + e.getInfo());
        e.printStackTrace();
    } catch (Exception e) {
        System.err.println();
        System.err.println(e.getMessage());
        e.printStackTrace();
    }
}
Also used : OSTask(priv.bajdcc.LALR1.interpret.os.kern.OSTask) IOSCodePage(priv.bajdcc.LALR1.interpret.os.IOSCodePage) URFileSave(priv.bajdcc.LALR1.interpret.os.user.routine.file.URFileSave) SyntaxException(priv.bajdcc.LALR1.syntax.handler.SyntaxException) UIHitokoto(priv.bajdcc.LALR1.interpret.os.ui.UIHitokoto) UserMain(priv.bajdcc.LALR1.interpret.os.user.UserMain) URFileAppend(priv.bajdcc.LALR1.interpret.os.user.routine.file.URFileAppend) IRPrint(priv.bajdcc.LALR1.interpret.os.irq.IRPrint) ByteArrayInputStream(java.io.ByteArrayInputStream) TKUtil(priv.bajdcc.LALR1.interpret.os.task.TKUtil) UIClock(priv.bajdcc.LALR1.interpret.os.ui.UIClock) IRSignal(priv.bajdcc.LALR1.interpret.os.irq.IRSignal) OSEntry(priv.bajdcc.LALR1.interpret.os.kern.OSEntry) TKSystem(priv.bajdcc.LALR1.interpret.os.task.TKSystem) RuntimeException(priv.bajdcc.LALR1.grammar.runtime.RuntimeException) UIMain(priv.bajdcc.LALR1.interpret.os.ui.UIMain) Interpreter(priv.bajdcc.LALR1.interpret.Interpreter) OSIrq(priv.bajdcc.LALR1.interpret.os.kern.OSIrq) TKNet(priv.bajdcc.LALR1.interpret.os.task.TKNet) IRRemote(priv.bajdcc.LALR1.interpret.os.irq.IRRemote) Grammar(priv.bajdcc.LALR1.grammar.Grammar) RuntimeCodePage(priv.bajdcc.LALR1.grammar.runtime.RuntimeCodePage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TKUI(priv.bajdcc.LALR1.interpret.os.task.TKUI) SyntaxException(priv.bajdcc.LALR1.syntax.handler.SyntaxException) RuntimeException(priv.bajdcc.LALR1.grammar.runtime.RuntimeException) RegexException(priv.bajdcc.util.lexer.error.RegexException) UIMonitor(priv.bajdcc.LALR1.interpret.os.ui.UIMonitor) IRTask(priv.bajdcc.LALR1.interpret.os.irq.IRTask) URFileLoad(priv.bajdcc.LALR1.interpret.os.user.routine.file.URFileLoad) RegexException(priv.bajdcc.util.lexer.error.RegexException)

Example 19 with RegexException

use of priv.bajdcc.util.lexer.error.RegexException 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)

Example 20 with RegexException

use of priv.bajdcc.util.lexer.error.RegexException in project jMiniLang by bajdcc.

the class TestSyntaxLexer method main.

public static void main(String[] args) {
    try {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        SyntaxLexer lexer = new SyntaxLexer();
        lexer.setContext(str);
        Token token;
        for (; ; ) {
            token = lexer.nextToken();
            if (token.kToken == TokenType.EOF) {
                break;
            }
            System.out.println(token.toString());
        }
        scanner.close();
    } catch (RegexException e) {
        System.err.println(e.getPosition() + "," + e.getMessage());
        e.printStackTrace();
    }
}
Also used : Scanner(java.util.Scanner) SyntaxLexer(priv.bajdcc.LL1.syntax.lexer.SyntaxLexer) RegexException(priv.bajdcc.util.lexer.error.RegexException) Token(priv.bajdcc.LL1.syntax.token.Token)

Aggregations

RegexException (priv.bajdcc.util.lexer.error.RegexException)40 SyntaxException (priv.bajdcc.LALR1.syntax.handler.SyntaxException)24 Grammar (priv.bajdcc.LALR1.grammar.Grammar)18 RuntimeCodePage (priv.bajdcc.LALR1.grammar.runtime.RuntimeCodePage)16 RuntimeException (priv.bajdcc.LALR1.grammar.runtime.RuntimeException)16 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 Interpreter (priv.bajdcc.LALR1.interpret.Interpreter)14 Scanner (java.util.Scanner)6 Token (priv.bajdcc.util.lexer.token.Token)5 Semantic (priv.bajdcc.LALR1.semantic.Semantic)4 SyntaxException (priv.bajdcc.OP.syntax.handler.SyntaxException)4 OperatorType (priv.bajdcc.util.lexer.token.OperatorType)4 Syntax (priv.bajdcc.LALR1.syntax.Syntax)3 GrammarException (priv.bajdcc.OP.grammar.error.GrammarException)3 IPatternHandler (priv.bajdcc.OP.grammar.handler.IPatternHandler)3 RegexStringIteratorData (priv.bajdcc.util.lexer.regex.RegexStringIteratorData)3 RegexStringUtility (priv.bajdcc.util.lexer.regex.RegexStringUtility)3 RuntimeMachine (priv.bajdcc.LALR1.grammar.runtime.RuntimeMachine)2 ISemanticAnalyzer (priv.bajdcc.LALR1.semantic.token.ISemanticAnalyzer)2