Skip to content

ULL-ESIT-PL/lexical-analysis-pl

Repository files navigation

aho-lam Folder

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.

Open Courseware Procesadores de Lenguajes at ULL

Open Courseware PL at ULL: Flex examples

See the ULL OCW course PROCESADORES DE LENGUAJES

Open Courseware PL at ULL: "Analisis Sintactico con yacc y flex"

  • 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.c
    

    To 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
    

Development Container for GitHub Codespaces

  • Folder .devcontainer contains a development container to work with the examples in a GitHub Codespace, installing flex, bison, java, etc.

Lox Interpreter: C Lexical Analyzer

Testing the Java Lox Scanner

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

Releases

No releases published

Packages

 
 
 

Contributors