Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any simple languages implemented using ANTLR or similar?

I'm trying to build a simple interpreted language for learning purposes. I've read countless theory and tutorials on ANTLR and JavaCC, but I can't figure out how to actually make it do something useful.

I learn best by "taking something apart and putting it back together again", so, are there any working examples of simple languages implemented with the help of tools such as ANTLR, or similar?

Something like the following might be nice:

x = 1

if x == 1  
     print "true"
like image 210
etheros Avatar asked Mar 20 '10 15:03

etheros


People also ask

What languages use ANTLR?

It turns out ANTLR4 lets you generate parser code in a variety of languages: Java, C#, Python, Go, C++, Swift, JavaScript and even TypeScript!

Is ANTLR a programming language?

ANTLR, ANother Tool for Language Recognition, (formerly PCCTS) is a language tool that provides a framework for constructing recognizers, compilers, and translators from grammatical descriptions containing Java, C#, C++, or Python actions.

Why do we use ANTLR?

ANTLR is a powerful parser generator that you can use to read, process, execute, or translate structured text or binary files. It's widely used in academia and industry to build all sorts of languages, tools, and frameworks. Twitter search uses ANTLR for query parsing, with over 2 billion queries a day.

How do you use ANTLR in Python?

What you need to do to get a parse tree: define a lexer and parser grammar. invoke ANTLR: it will generate a lexer and a parser in your target language (e.g., Java, Python, C#, JavaScript) use the generated lexer and parser: you invoke them passing the code to recognize and they return to you a parse tree.


2 Answers

[shameless plug] Why not buy my Language Implementation Patterns book? I have all the pieces you need to put together a language including multiple interpreters etc...

like image 66
Terence Parr Avatar answered Sep 23 '22 15:09

Terence Parr


You can probably find lots of small languages on Google Code and Github.

Here's a toy language that I did in ANTLR as a class project a few years ago: http://code.google.com/p/bcis/

like image 35
Stuart Sierra Avatar answered Sep 22 '22 15:09

Stuart Sierra