Chapter 8: Add statement AST generator

This commit is contained in:
Tom Willemse 2020-11-18 17:10:21 -08:00
parent 2894c7ebfd
commit 055b5257fb
2 changed files with 7 additions and 3 deletions

View file

@ -1,8 +1,11 @@
get_target_property(GENERATE_AST_JAR GenerateAst JAR_FILE)
set(EXPR_JAVA_FILENAME ${CMAKE_CURRENT_BINARY_DIR}/Expr.java CACHE INTERNAL "")
set(GENERATED_JAVA_FILENAMES
${CMAKE_CURRENT_BINARY_DIR}/Expr.java
${CMAKE_CURRENT_BINARY_DIR}/Stmt.java
CACHE INTERNAL "")
add_custom_command(OUTPUT ${EXPR_JAVA_FILENAME}
add_custom_command(OUTPUT ${GENERATED_JAVA_FILENAMES}
COMMAND java -jar ${GENERATE_AST_JAR} ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS GenerateAst)
@ -11,7 +14,7 @@ add_jar(Lox
TokenType.java
Token.java
Scanner.java
${EXPR_JAVA_FILENAME}
${GENERATED_JAVA_FILENAMES}
AstPrinter.java
Parser.java
Interpreter.java

View file

@ -16,6 +16,7 @@ public class GenerateAst {
defineAst(outputDir, "Expr", Arrays.asList("Binary : Expr left, Token operator, Expr right",
"Grouping : Expr expression", "Literal : Object value", "Unary : Token operator, Expr right"));
defineAst(outputDir, "Stmt", Arrays.asList("Expression : Expr expression", "Print : Expr expression"));
}
private static void defineAst(String outputDir, String baseName, List<String> types) throws IOException {