Adding the original version from the blog.
This commit is contained in:
parent
2d4623a80a
commit
4200d0a62f
|
@ -4,3 +4,4 @@
|
|||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
/target/
|
34
pom.xml
34
pom.xml
|
@ -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>
|
||||
|
|
|
@ -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' ;
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package b1;
|
||||
|
||||
public class Math {
|
||||
|
||||
public static int square(int a) {
|
||||
return a * a;
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue