A small ANTLR-based toolchain that parses the tabloid-inspired "Tabloid" language and emits runnable Python. Use it to showcase language tooling: a custom grammar, generated parser/lexer, and a listener that translates constructs to clean Python.
- Grammar: Tabloid.g4
- Converter entrypoint: Tabloid2Python.java
- AST-to-Python listener: TabloidToPythonListener.java
- Generated parser/lexer: TabloidParser.java, TabloidLexer.java (and companion files)
- Samples: sample1.tbd–sample6.tbd with their expected Python outputs
- Ensure ANTLR is on the classpath (example uses
antlr-4.13.1-complete.jar). - Compile Java sources:
javac -cp ".:antlr-4.13.1-complete.jar" Tabloid*.java
- Convert a Tabloid program to Python:
java -cp ".:antlr-4.13.1-complete.jar" Tabloid2Python sample1.tbd - Run the generated Python:
python3 sample1.py
- Dramatic keywords (e.g.,
WHAT IF,STAY TUNED WHILE,SHOCKING DEVELOPMENT) mapped to familiar Python control flow. - Functions with
DISCOVER HOW TO ... WITH ... RUMOR HAS IT ... END OF STORY. - Boolean and arithmetic comparisons (
SMALLER THAN,BEATS,IS ACTUALLY, etc.) lowered to Python operators. - Simple input/output helpers (
YOU WON'T WANT TO MISS,TELL ME,LATEST NEWS ON).
If you tweak Tabloid.g4, regenerate the lexer and parser:
antlr4 Tabloid.g4 -visitor -listener
javac -cp ".:antlr-4.13.1-complete.jar" Tabloid*.java- Samples exercise functions, recursion, conditionals, loops, arithmetic, logic, and user input.
- The transpiler now renders properly spaced Python with accurate operators and else-handling, keeping the generated code readable.