Adding the original version from the blog.

This commit is contained in:
shing19m 2013-07-23 20:31:04 +02:00
parent 2d4623a80a
commit 4200d0a62f
6 changed files with 103 additions and 12 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
*.jar
*.war
*.ear
/target/

34
pom.xml
View File

@ -11,20 +11,24 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>3.1.3-1</version>
<executions>
<execution>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>
1.5
</source>
<target>
1.5
</target>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
@ -62,6 +66,12 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>jline</artifactId>
<version>0.9.9</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
<version>3.2</version>
<type>jar</type>
</dependency>
</dependencies>
<repositories>
<repository>

View File

@ -0,0 +1,37 @@
// Name der Grammatik
grammar b1;
// einfache, feste Tokens
tokens {
PLUS = '+' ;
MINUS = '-' ;
MULT = '*' ;
DIV = '/' ;
}
@header {
package b1;
}
@lexer::header {
package b1;
}
ausdruck:
term ( ( PLUS | MINUS ) term )* ;
term :
faktor ( ( MULT | DIV ) faktor )* ;
faktor :
ZAHL ;
ZAHL :
(DIGIT)+ ;
WHITESPACE :
( '\t' | ' ' | '\r' | '\n'| '\u000C' )+
{ $channel = HIDDEN; } ;
fragment DIGIT :
'0'..'9' ;

View File

@ -0,0 +1,23 @@
package b1;
import java.io.IOException;
import java.io.PrintWriter;
import jline.ConsoleReader;
public class Main {
public static void main(String[] args) throws IOException {
ConsoleReader reader = new ConsoleReader();
String line;
PrintWriter out = new PrintWriter(System.out);
while ((line = reader.readLine("number or quit> ")) != null) {
if (line.equalsIgnoreCase("quit")) {
break;
}
int i = Integer.parseInt(line);
System.out.println(
Math.square(i) + " ist " + i + " quadriert");
out.flush();
}
}
}

View File

@ -0,0 +1,8 @@
package b1;
public class Math {
public static int square(int a) {
return a * a;
}
}

View File

@ -0,0 +1,12 @@
package b1;
import org.junit.Assert;
import org.junit.Test;
public class MathTest {
@Test
public void testSqure() {
Assert.assertEquals(16, Math.square(4));
}
}