Chapter 8: Add statement AST generator
This commit is contained in:
parent
2894c7ebfd
commit
055b5257fb
2 changed files with 7 additions and 3 deletions
|
@ -1,8 +1,11 @@
|
||||||
get_target_property(GENERATE_AST_JAR GenerateAst JAR_FILE)
|
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}
|
COMMAND java -jar ${GENERATE_AST_JAR} ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
DEPENDS GenerateAst)
|
DEPENDS GenerateAst)
|
||||||
|
|
||||||
|
@ -11,7 +14,7 @@ add_jar(Lox
|
||||||
TokenType.java
|
TokenType.java
|
||||||
Token.java
|
Token.java
|
||||||
Scanner.java
|
Scanner.java
|
||||||
${EXPR_JAVA_FILENAME}
|
${GENERATED_JAVA_FILENAMES}
|
||||||
AstPrinter.java
|
AstPrinter.java
|
||||||
Parser.java
|
Parser.java
|
||||||
Interpreter.java
|
Interpreter.java
|
||||||
|
|
|
@ -16,6 +16,7 @@ public class GenerateAst {
|
||||||
|
|
||||||
defineAst(outputDir, "Expr", Arrays.asList("Binary : Expr left, Token operator, Expr right",
|
defineAst(outputDir, "Expr", Arrays.asList("Binary : Expr left, Token operator, Expr right",
|
||||||
"Grouping : Expr expression", "Literal : Object value", "Unary : 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 {
|
private static void defineAst(String outputDir, String baseName, List<String> types) throws IOException {
|
||||||
|
|
Loading…
Reference in a new issue