Permalink
Browse files

Merge pull request #1 from allonhadaya/clean_scanner

Clean scanner
  • Loading branch information...
allonhadaya committed Nov 22, 2011
2 parents 4012908 + 07e1e0a commit 3b29a201867fda5ce1d40edddb4dacccd5e1c752
View
@@ -2,5 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -1,4 +1,4 @@
-#Sat Nov 19 16:56:14 EST 2011
+#Mon Nov 21 16:21:47 EST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
@@ -68,10 +68,10 @@ org.eclipse.jdt.core.formatter.comment.format_html=true
org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
org.eclipse.jdt.core.formatter.comment.format_line_comments=true
org.eclipse.jdt.core.formatter.comment.format_source_code=true
-org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
-org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
org.eclipse.jdt.core.formatter.comment.line_length=9999
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
@@ -280,7 +280,7 @@ org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
-org.eclipse.jdt.core.formatter.lineSplit=80
+org.eclipse.jdt.core.formatter.lineSplit=9999
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
View
@@ -0,0 +1,2 @@
+true
+false
File renamed without changes.
@@ -1,6 +1,4 @@
//This checks for literals
-true
-false
3234
6
234
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,6 @@
+_NotLegal
+$Nope
+#
+\
+&
+|
File renamed without changes.
View
@@ -1,3 +1,4 @@
+// this is a comment
void main() {
someIdentifier;
35 + 7;
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -1,21 +1,17 @@
/**
- * @author Christelle
- *
+ * @author Allon Hadaya, Keith McPherson
*/
public class ScannerDemo {
- private static String file1 = "testjay.txt";
+ private static String file1 = "Test.jay";
private static int counter = 1;
public static void main(String args[]) {
- TokenStream ts = new TokenStream(file1);
-
System.out.println(file1);
-
- while (!ts.isEndofFile()) {
- Token t = ts.nextToken();
- System.out.println(t);
- }
+ TokenStream ts = new TokenStream(file1);
+ while (!ts.isEoF()) {
+ System.out.println(ts.nextToken());
+ }
}
}
View
@@ -0,0 +1,61 @@
+import org.junit.Test;
+import junit.framework.Assert;
+
+public class TestTokenStream {
+
+ @Test
+ public void testIdentifier() {
+ TokenStream ts = new TokenStream("Identifier.jay");
+ while (!ts.isEoF()) {
+ Assert.assertEquals("Identifier", ts.nextToken().getType());
+ }
+ }
+
+ @Test
+ public void testKeyword() {
+ TokenStream ts = new TokenStream("Keyword.jay");
+ while (!ts.isEoF()) {
+ Assert.assertEquals("Keyword", ts.nextToken().getType());
+ }
+ }
+
+ @Test
+ public void testBooleanLiteral() {
+ TokenStream ts = new TokenStream("BooleanLiteral.jay");
+ while (!ts.isEoF()) {
+ Assert.assertEquals("Boolean-Literal", ts.nextToken().getType());
+ }
+ }
+
+ @Test
+ public void testIntegerLiteral() {
+ TokenStream ts = new TokenStream("IntegerLiteral.jay");
+ while (!ts.isEoF()) {
+ Assert.assertEquals("Integer-Literal", ts.nextToken().getType());
+ }
+ }
+
+ @Test
+ public void testOperator() {
+ TokenStream ts = new TokenStream("Operator.jay");
+ while (!ts.isEoF()) {
+ Assert.assertEquals("Operator", ts.nextToken().getType());
+ }
+ }
+
+ @Test
+ public void testSeparator() {
+ TokenStream ts = new TokenStream("Separator.jay");
+ while (!ts.isEoF()) {
+ Assert.assertEquals("Separator", ts.nextToken().getType());
+ }
+ }
+
+ @Test
+ public void testOther() {
+ TokenStream ts = new TokenStream("Other.jay");
+ while (!ts.isEoF()) {
+ Assert.assertEquals("Other", ts.nextToken().getType());
+ }
+ }
+}
View
@@ -1,42 +1,30 @@
+/**
+ * Representation of a Token that has a type and value.
+ *
+ * @author Allon Hadaya, Keith McPherson
+ */
public class Token {
- private String type; // Token type
- // Identifier, Keyword, Literal,
- // Separator, Operator, or Other
- private String value; // Token value
+ private String type = "Other";
+ private String value = "";
- /**
- * @param value
- * . Set the value of a Token.
- */
- public void setValue(String value) {
- this.value = value;
- }
-
- /**
- * @return Returns the value of a Token.
- */
- public String getValue() {
- return value;
- }
-
- /**
- * @param type
- * . Set the type of a Token.
- */
public void setType(String type) {
this.type = type;
}
- /**
- * @return Returns the type of a Token.
- */
public String getType() {
- return type;
+ return type.toString();
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
}
public String toString() {
- return "Value: " + this.getValue() + " " + "Type: " + this.getType();
+ return "Value: " + value + " " + "Type: " + type;
}
-
}
Oops, something went wrong.

0 comments on commit 3b29a20

Please sign in to comment.