Skip to content
/ scalc Public

A calculator for s-expressions using a modified version of the Extended Backus–Naur form. Made using Java and ANTLR4.

Notifications You must be signed in to change notification settings

vedarthv/scalc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

S-expression calculator

Getting Started

Please download the scalc.jar file to run the code. Then use the following command to use the program: java -jar ./scalc.jar <arg>. Please use JDK 8 or more recent versions of Java.

Usage

The general syntax of an expression is (OP EXPR EXPR), where OP = {add, multiply, exponent} and EXPR ={ $\mathbb{N}$, (OP EXPR EXPR)}.

Example

java -jar ./scalc.jar (add 1 (multiply 2 0))

1

Technologies Used

For this project I used Java and ANTLR4. ANTLR is used to specify a grammer, which is then used to generate a Java interface which can be used to parse some given text. ANTLR is very powerful as it has extensive tooling such as the ability to generate parse trees. Here is a generated parse tree of the expression (add 1 (multiply 5 (exponent 3 5)) 5 (multiply 4 2) 5) using the grammer from Calc.g4:

parseTree Normally a grammer is defined in a *.g4 file and then it is complied using the ANTLR library. The generated classes can vary depending on your choice of having visitor and or listener classes.

ANTLR defines an interface for the respective visitor and/or listener Java classes and a base implementation which can be extended to do meaningful computation and evaluation of an expression following the specified grammer.

File Index / Important Files

About

A calculator for s-expressions using a modified version of the Extended Backus–Naur form. Made using Java and ANTLR4.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published