From 85e5d41217d27fd481a21d17f061d31dc120873b Mon Sep 17 00:00:00 2001 From: dibyendumajumdar Date: Thu, 7 Sep 2023 19:33:52 +0100 Subject: Removed all external code. Removed the common chapter. Reimplemented Lexer. Revised the list of chapters to something more accurate. --- .../com/seaofnodes/simple/lexer/TestParser.java | 66 ---------------------- .../com/seaofnodes/simple/parser/TestParser.java | 62 ++++++++++++++++++++ 2 files changed, 62 insertions(+), 66 deletions(-) delete mode 100644 chapter01/src/test/java/com/seaofnodes/simple/lexer/TestParser.java create mode 100644 chapter01/src/test/java/com/seaofnodes/simple/parser/TestParser.java (limited to 'chapter01/src/test/java/com') diff --git a/chapter01/src/test/java/com/seaofnodes/simple/lexer/TestParser.java b/chapter01/src/test/java/com/seaofnodes/simple/lexer/TestParser.java deleted file mode 100644 index 3f65e0f9..00000000 --- a/chapter01/src/test/java/com/seaofnodes/simple/lexer/TestParser.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * DO NOT REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Contributor(s): - * - * This file is part of the Sea Of Nodes Simple Programming language - * implementation. See https://github.com/SeaOfNodes/Simple - * - * The contents of this file are subject to the terms of the - * Apache License Version 2 (the "APL"). You may not use this - * file except in compliance with the License. A copy of the - * APL may be obtained from: - * http://www.apache.org/licenses/LICENSE-2.0 - */ - -package com.seaofnodes.simple.lexer; - -import com.seaofnodes.simple.lexer.ecstasy.ErrorListener; -import com.seaofnodes.simple.lexer.ecstasy.Lexer; -import com.seaofnodes.simple.lexer.ecstasy.Source; -import com.seaofnodes.simple.parser.Parser; -import org.junit.Assert; -import org.junit.Test; - -public class TestParser { - - @Test - public void testParseSingleDecl() - { - final String source = "int i;"; - Lexer lexer = new Lexer(new Source(source), new ErrorListener()); - Parser parser = new Parser(); - var ast = parser.parse(lexer); - Assert.assertEquals("{int i;}", ast.toString()); - } - - @Test - public void testParseTwoDecls() { - final String source = "int i;\nint j;"; - Lexer lexer = new Lexer(new Source(source), new ErrorListener()); - Parser parser = new Parser(); - var ast = parser.parse(lexer); - Assert.assertEquals("{int i;int j;}", ast.toString()); - } - - @Test - public void testIfAndWhile() { - final String source = - """ - int i; - int j; - - i = 0; - j = 100; - while ( 1 ) { - i = i + 1; - j = j - 1; - if ( i >= j ) break; - } - """; - Lexer lexer = new Lexer(new Source(source), new ErrorListener()); - Parser parser = new Parser(); - var ast = parser.parse(lexer); - Assert.assertEquals("{int i;int j;i=0;j=100;while(1) {i=(i+1);j=(j-1);if((i>=j)) break;}}", ast.toString()); - } -} diff --git a/chapter01/src/test/java/com/seaofnodes/simple/parser/TestParser.java b/chapter01/src/test/java/com/seaofnodes/simple/parser/TestParser.java new file mode 100644 index 00000000..356420eb --- /dev/null +++ b/chapter01/src/test/java/com/seaofnodes/simple/parser/TestParser.java @@ -0,0 +1,62 @@ +/* + * DO NOT REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Contributor(s): + * + * This file is part of the Sea Of Nodes Simple Programming language + * implementation. See https://github.com/SeaOfNodes/Simple + * + * The contents of this file are subject to the terms of the + * Apache License Version 2 (the "APL"). You may not use this + * file except in compliance with the License. A copy of the + * APL may be obtained from: + * http://www.apache.org/licenses/LICENSE-2.0 + */ + +package com.seaofnodes.simple.parser; + +import org.junit.Assert; +import org.junit.Test; + +public class TestParser { + + @Test + public void testParseSingleDecl() + { + final String source = "int i;"; + Lexer lexer = new Lexer(source); + Parser parser = new Parser(); + var ast = parser.parse(lexer); + Assert.assertEquals("{int i;}", ast.toString()); + } + + @Test + public void testParseTwoDecls() { + final String source = "int i;\nint j;"; + Lexer lexer = new Lexer(source); + Parser parser = new Parser(); + var ast = parser.parse(lexer); + Assert.assertEquals("{int i;int j;}", ast.toString()); + } + + @Test + public void testIfAndWhile() { + final String source = + """ + int i; + int j; + + i = 0; + j = 100; + while ( 1 ) { + i = i + 1; + j = j - 1; + if ( i >= j ) break; + } + """; + Lexer lexer = new Lexer(source); + Parser parser = new Parser(); + var ast = parser.parse(lexer); + Assert.assertEquals("{int i;int j;i=0;j=100;while(1) {i=(i+1);j=(j-1);if((i>=j)) break;}}", ast.toString()); + } +} -- cgit v1.2.3