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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations