Search in sources :

Example 1 with RedsnakeParser

use of net.taken.redsnake.parser.RedsnakeParser in project redsnake by Taken0711.

the class Redsnake method buildAST.

public Statement buildAST(CharStream inputStream) {
    RedsnakeLexer redsnakeLexer = new RedsnakeLexer(inputStream);
    TokenStream commonTokenStream = new CommonTokenStream(redsnakeLexer);
    RedsnakeParser parser = new RedsnakeParser(commonTokenStream);
    ParseTree t = parser.statement();
    return (Statement) astBuilder.visit(t);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) TokenStream(org.antlr.v4.runtime.TokenStream) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) RedsnakeLexer(net.taken.redsnake.parser.RedsnakeLexer) RedsnakeParser(net.taken.redsnake.parser.RedsnakeParser) Statement(net.taken.redsnake.tree.statements.Statement) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 2 with RedsnakeParser

use of net.taken.redsnake.parser.RedsnakeParser in project redsnake by Taken0711.

the class TestUtils method parseProgram.

public static Program parseProgram(@NotNull String... s) {
    StringBuilder str = new StringBuilder();
    Arrays.stream(s).forEach(st -> str.append(st).append(System.lineSeparator()));
    CharStream inputStream = CharStreams.fromString(str.toString());
    RedsnakeLexer redsnakeLexer = new RedsnakeLexer(inputStream);
    TokenStream commonTokenStream = new CommonTokenStream(redsnakeLexer);
    RedsnakeParser parser = new RedsnakeParser(commonTokenStream);
    ParseTree t = parser.program();
    return (Program) new ASTBuilder().visit(t);
}
Also used : RedsnakeLexer(net.taken.redsnake.parser.RedsnakeLexer) RedsnakeParser(net.taken.redsnake.parser.RedsnakeParser) ASTBuilder(net.taken.redsnake.parser.visitors.ASTBuilder) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 3 with RedsnakeParser

use of net.taken.redsnake.parser.RedsnakeParser in project redsnake by Taken0711.

the class TestUtils method parseStatement.

public static Statement parseStatement(@NotNull String s) {
    CharStream inputStream = CharStreams.fromString(s);
    RedsnakeLexer redsnakeLexer = new RedsnakeLexer(inputStream);
    TokenStream commonTokenStream = new CommonTokenStream(redsnakeLexer);
    RedsnakeParser parser = new RedsnakeParser(commonTokenStream);
    ParseTree t = parser.expression();
    return (Expression) new ASTBuilder().visit(t);
}
Also used : RedsnakeLexer(net.taken.redsnake.parser.RedsnakeLexer) RedsnakeParser(net.taken.redsnake.parser.RedsnakeParser) Expression(net.taken.redsnake.tree.statements.expressions.Expression) ASTBuilder(net.taken.redsnake.parser.visitors.ASTBuilder) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

RedsnakeLexer (net.taken.redsnake.parser.RedsnakeLexer)3 RedsnakeParser (net.taken.redsnake.parser.RedsnakeParser)3 ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 ASTBuilder (net.taken.redsnake.parser.visitors.ASTBuilder)2 Statement (net.taken.redsnake.tree.statements.Statement)1 Expression (net.taken.redsnake.tree.statements.expressions.Expression)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 TokenStream (org.antlr.v4.runtime.TokenStream)1