- Overview
- cv1: Arithmetic Expression Evaluator
- cv2_cv5_cv6: Lexer and Parser
- cv3_and_cv4: Grammar Operations
- cv7_cv8_cv9_cv10: ANTLR Interpreter
- License
- Acknowledgments
Lab solutions for the PJP course (Programming Languages and Compilers) at VSB-TUO, spring 2025. The repository holds four mini projects:
cv1- arithmetic expression evaluatorcv2_cv5_cv6- lexer and parser built by hand on regular expressionscv3_and_cv4- grammar operations: EMPTY, FIRST and FOLLOW sets, LL(1) checkcv7_cv8_cv9_cv10- ANTLR 4 interpreter with a type checker and a stack machine (Maven project)
The final version of the compiler grew into a separate repository: AntlrCompiler.
A console evaluator of integer arithmetic expressions with + - * / and parentheses.
To run it, ensure JDK 17 or newer is installed and execute from the repository root:
javac cv1/*.java
java cv1.ArithmeticInterpreter
The first input line is the number of expressions, then one expression per line. The program prints the result of each expression, or ERROR for an invalid one.
Example input:
2
2+3*4
(2+3)*4
prints 14 and 20.
A lexer built on regular expressions and a recursive descent parser of arithmetic expressions. One main covers three classes:
- cv2 - prints the token stream
- cv5 - prints the numbers of the applied grammar rules
- cv6 - evaluates the expressions (active by default)
To switch the variant, uncomment its block in LexicalAnalyzer.java and comment out the active one.
To run it, ensure JDK 17 or newer is installed and execute from the repository root:
javac cv2_cv5_cv6/*.java
java cv2_cv5_cv6.LexicalAnalyzer
The input format is the same as in cv1. Expressions may also contain // line comments.
Reads a context-free grammar from a file, computes its EMPTY, FIRST and FOLLOW sets and checks whether it is LL(1).
To run it, ensure JDK 17 or newer is installed and execute from the repository root:
javac cv3_and_cv4/grammar/*.java cv3_and_cv4/grammarOperation/*.java
java cv3_and_cv4.grammarOperation.Test cv3_and_cv4/grammar.txt
The path to the grammar file is the only argument. Two test grammars are included:
cv3_and_cv4/grammar.txt- not an LL(1) grammarcv3_and_cv4/grammarLL1.txt- an LL(1) grammar
An interpreter for a small language with int and float variables, built on ANTLR 4. It parses a program (cv7), checks the types (cv8), generates stack machine instructions (cv9) and executes them (cv10).
To run it, ensure JDK 17 and Maven are installed and execute:
cd cv7_cv8_cv9_cv10/antlr-interpreter
mvn compile exec:java
By default the interpreter runs test.lang. Input programs live in src/test/resources; to run another one, pass its name:
mvn compile exec:java "-Dexec.args=program.lang"
The program prints the generated instructions and then the value of every expression statement. input.txt in the project folder is a reference instruction listing for test.lang.
This project is authored by Demid Ostiakov. All rights reserved.
Thanks to the instructors of the PJP course at VSB-TUO:
- Ing. Marek Běhálek, Ph.D. for the lectures and the course materials these labs are built on
- Ing. Michal Vašinek, Ph.D. for leading the exercises and for his advice along the way
Thanks also to the instructors of UTI (Introduction to Theoretical Computer Science), where the theory of formal languages and automata behind these labs comes from:
- doc. Ing. Zdeněk Sawa, Ph.D. for the lectures and his presentations covering the whole course
- doc. Mgr. Pavla Dráždilová, Ph.D. for leading the exercises and her clear and illustrative explanations