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);
String[] nons = new String[] { "E", "T", "F" };
for (String non : nons) {
syntax.addNonTerminal(non);
}
syntax.infer("E -> E @PLUS T | E @MINUS T | T");
syntax.infer("T -> T @MINUS F | T @DIVIDE F | F");
syntax.infer("F -> @LPA E @RPA | @SYMBOL");
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();
}
}
use of priv.bajdcc.util.lexer.error.RegexException in project jMiniLang by bajdcc.
the class StringFilter method filter.
@Override
public RegexStringIteratorData filter(IRegexStringIterator iterator) {
// 获取解析组件
RegexStringUtility utility = iterator.utility();
RegexStringIteratorData data = new RegexStringIteratorData();
try {
if (!iterator.available()) {
data.kMeta = MetaType.END;
data.chCurrent = MetaType.END.getChar();
} else {
data.kMeta = iterator.meta();
data.chCurrent = iterator.current();
iterator.next();
if (data.kMeta == kMeta) {
// 过滤终结符
data.kMeta = MetaType.NULL;
} else if (data.kMeta == MetaType.ESCAPE) {
// 处理转义
data.chCurrent = iterator.current();
iterator.next();
data.kMeta = MetaType.MUST_SAVE;
data.chCurrent = utility.fromEscape(data.chCurrent, RegexError.ESCAPE);
}
}
} catch (RegexException e) {
System.err.println(e.getPosition() + " : " + e.getMessage());
data.kMeta = MetaType.ERROR;
data.chCurrent = MetaType.ERROR.getChar();
}
return data;
}
use of priv.bajdcc.util.lexer.error.RegexException in project jMiniLang by bajdcc.
the class StringPairFilter method filter.
@Override
public RegexStringIteratorData filter(IRegexStringIterator iterator) {
// 获取解析组件
RegexStringUtility utility = iterator.utility();
RegexStringIteratorData data = new RegexStringIteratorData();
try {
if (!iterator.available()) {
data.kMeta = MetaType.END;
data.chCurrent = MetaType.END.getChar();
} else {
data.kMeta = iterator.meta();
data.chCurrent = iterator.current();
iterator.next();
if (data.kMeta == kMetaBegin || data.kMeta == kMetaEnd) {
// 过滤终结符
data.kMeta = MetaType.NULL;
} else if (data.kMeta == MetaType.ESCAPE) {
// 处理转义
data.chCurrent = iterator.current();
iterator.next();
data.kMeta = MetaType.MUST_SAVE;
data.chCurrent = utility.fromEscape(data.chCurrent, RegexError.ESCAPE);
}
}
} catch (RegexException e) {
System.err.println(e.getPosition() + " : " + e.getMessage());
data.kMeta = MetaType.ERROR;
data.chCurrent = MetaType.ERROR.getChar();
}
return data;
}
use of priv.bajdcc.util.lexer.error.RegexException in project jMiniLang by bajdcc.
the class TestLexer method main.
public static void main(String[] args) {
try {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
scanner.close();
Lexer lexer = new Lexer(str);
Token token;
for (; ; ) {
token = lexer.scan();
if (token.kToken == TokenType.EOF) {
break;
}
System.out.println(token.toString());
}
} catch (RegexException e) {
System.err.println(e.getPosition() + "," + e.getMessage());
e.printStackTrace();
}
}
Aggregations