Skip to content

moorekevin/CS-modelling-Assignment

Repository files navigation

This folder contains examples of "calculator" programs in F# and Java tha read an arithmetic expression from the command line and print the result of evaluating such expression.

Files

F#/FsLexYacc

Java/ANTLR4

  • Calculator.g: The ANTLR4 grammar for arithmetic expressions.
  • Calculator.java: The Java calculator, which uses the parser generated by ANTLR4.

Instructions for F# #/FSLexYacc

This is instructions assume that you have followed the guidelines to getting started with F# and FSLexYacc and that you are using a terminal on a folder contaning the F# files mentioned above.

Invoke the lexer generator with

mono FsLexYacc.10.0.0/build/fslex/net46/fslex.exe CalculatorLexer.fsl --unicode

Invoke the parser generator with

mono FsLexYacc.10.0.0/build/fsyacc/net46/fsyacc.exe CalculatorParser.fsp --module CalculatorParser

Invoke the calculator with

fsharpi Calculator.fsx

You should be able to interact with the calculator program as follows:

Enter an arithmetic expression: 1
1.0
Enter an arithmetic expression: 1 + 2
3.0
Enter an arithmetic expression: 1 + 2 * 3
7.0

Instructions for Java/ANTLR

This is instructions assume that you have followed the guidelines to getting started with Java and ANLTR4 and that you are using a terminal on a folder contaning Calculator.g and Calculator.java.

Generate the visitor-based parser with

antlr4 -visitor -no-listener Calculator.g

Compile the program with

javac *.java

Run the program with

java Calculator

You should be able to interact with the calculator program as follows:

Enter an arithmetic expression: 1
1.0
Enter an arithmetic expression: 1 + 2
3.0
Enter an arithmetic expression: 1 + 2 * 3
7.0

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages