This folder contains some examples from the book "Compilers: Principles, Techniques, and Tools" (the Dragon Book) by Aho, Lam, Sethi, and Ullman.
Folder aho-lam/chapter2/figure.2.27 contains a version of the Java program to translate infix expressions (no spaces, no comments, digits only)into postfix form described in Figure 2.27 of the book.
Folder aho-lam/chapter2/figure.2.28 contains a translator of infix expressions into postfix form corresponding to the translation scheme in Figure 2.28 of the book.
See the ULL OCW course PROCESADORES DE LENGUAJES
- Folder expresiones-regulares-en-flex contains a version of the examples in section Expresiones Regulares en Flex. See the Makefile.
-
Folder analisis-sintactico-con-yacc/calc1` contains a version of the examples in section Análisis Sintáctico con yacc. A very simple calculator.
Just run
make.@crguezl ➜ /workspaces/ocw-pl/analisis-sintactico-con-yacc (main) $ make yacc -d -v hoc1.y flex -l hoc1.l gcc -DYYDEBUG=1 -g -o hoc1 y.tab.c lex.yy.cTo run the executable:
@crguezl ➜ /workspaces/ocw-pl/analisis-sintactico-con-yacc (main) $ ./hoc1 2+3 number detected = 2 char detected = + number detected = 3 char detected = result = 5
- Folder .devcontainer contains a development container to work with the examples in a GitHub Codespace, installing flex, bison, java, etc.
- Folder lox/C contains the C version of the lexical analyzer of the lox interpreter from the book Crafting Interpreters.
Folder java/com/craftinginterpreters/lox contains the Java version of the Lox interpreter from the book Crafting Interpreters.
See file java/com/craftinginterpreters/lox/ScannerTest.java for a simple test of the lexical analyzer of the Lox interpreter in Java.
Build the Java version:
lox git:(main) ✗ make jlox
javac java/com/craftinginterpreters/tool/GenerateAst.java -Werror
javac java/com/craftinginterpreters/lox/AstPrinter.java -Werror
javac java/com/craftinginterpreters/lox/Environment.java -Werror
javac java/com/craftinginterpreters/lox/Expr.java -Werror
javac java/com/craftinginterpreters/lox/Interpreter.java -Werror
javac java/com/craftinginterpreters/lox/Lox.java -Werror
javac java/com/craftinginterpreters/lox/LoxCallable.java -Werror
javac java/com/craftinginterpreters/lox/LoxClass.java -Werror
javac java/com/craftinginterpreters/lox/LoxFunction.java -Werror
javac java/com/craftinginterpreters/lox/LoxInstance.java -Werror
javac java/com/craftinginterpreters/lox/Parser.java -Werror
javac java/com/craftinginterpreters/lox/Resolver.java -Werror
javac java/com/craftinginterpreters/lox/Return.java -Werror
javac java/com/craftinginterpreters/lox/RuntimeError.java -Werror
javac java/com/craftinginterpreters/lox/Scanner.java -Werror
javac java/com/craftinginterpreters/lox/ScannerTest.java -Werror
javac java/com/craftinginterpreters/lox/Stmt.java -Werror
javac java/com/craftinginterpreters/lox/Token.java -Werror
javac java/com/craftinginterpreters/lox/TokenType.java -Werror
➜ lox git:(main) ✗ java -cp build/java com.craftinginterpreters.lox.ScannerTest
To run it:
➜ lox git:(main) ✗ java -cp build/java com.craftinginterpreters.lox.ScannerTest
type: VAR lexeme:var literal: null line: 1
type: IDENTIFIER lexeme:x literal: null line: 1
type: EQUAL lexeme:= literal: null line: 1
type: NUMBER lexeme:42 literal: 42.0 line: 1
type: SEMICOLON lexeme:; literal: null line: 1
type: PRINT lexeme:print literal: null line: 2
type: IDENTIFIER lexeme:x literal: null line: 2
type: PLUS lexeme:+ literal: null line: 2
type: NUMBER lexeme:1 literal: 1.0 line: 2
type: SEMICOLON lexeme:; literal: null line: 2
type: PRINT lexeme:print literal: null line: 2
type: STRING lexeme:"hello world!" literal: hello world! line: 2
type: EOF lexeme: literal: null line: 2