aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaël Gassmann <mael.gassmann@students.bfh.ch>2021-06-11 22:30:14 +0200
committerMaël Gassmann <mael.gassmann@students.bfh.ch>2021-06-11 22:30:14 +0200
commitf02eee6fd65e352c3fdc16b51aa7f99c2c63482d (patch)
treedaeea722c33832195f6eb99631b9383ea94e82e4
parentfed70f3ac817ed4943a230cb901fcd65dc6fdd0c (diff)
[+] Added basic structure for the javacc-calculator
-rw-r--r--calculator-javacc/.gitignore4
-rw-r--r--calculator-javacc/Calculator.jj35
-rwxr-xr-xcalculator-javacc/compileRun.sh2
3 files changed, 41 insertions, 0 deletions
diff --git a/calculator-javacc/.gitignore b/calculator-javacc/.gitignore
new file mode 100644
index 0000000..0e5a09f
--- /dev/null
+++ b/calculator-javacc/.gitignore
@@ -0,0 +1,4 @@
+calculator-javacc.iml
+.idea/
+*.java
+*.class
diff --git a/calculator-javacc/Calculator.jj b/calculator-javacc/Calculator.jj
new file mode 100644
index 0000000..6cc78f5
--- /dev/null
+++ b/calculator-javacc/Calculator.jj
@@ -0,0 +1,35 @@
+options{DEBUG_PARSER = true; DEBUG_TOKEN_MANAGER = true;}
+
+PARSER_BEGIN(Calculator)
+public class Calculator {
+ public static void main(String[] args) {
+ try{
+ Calculator parser = new Calculator(System.in);
+ parser.Start();
+ }catch (ParseException e){
+ System.out.println(e.getMessage());
+ }
+ }
+}
+PARSER_END(Calculator)
+
+/**
+* For now only using the Hello World grammar
+*/
+
+SKIP : {
+ " "|"\t"|"\n"|"\r"
+}
+
+TOKEN : {
+ <SPACE: " "|"\t">|
+ <HELLO: "hello">|
+ <WORLD: "world">|
+ <HELLOWORLD: <HELLO> ( <SPACE> ) + <WORLD>>
+}
+
+void Start() : {
+}
+{
+ (<HELLOWORLD>)* <EOF>
+} \ No newline at end of file
diff --git a/calculator-javacc/compileRun.sh b/calculator-javacc/compileRun.sh
new file mode 100755
index 0000000..555604e
--- /dev/null
+++ b/calculator-javacc/compileRun.sh
@@ -0,0 +1,2 @@
+#/bin/sh
+javacc Calculator.jj && javac *.java && clear && java Calculator