aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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