diff options
| author | Cliff Click <cliffc@acm.org> | 2023-10-29 09:32:35 -0700 |
|---|---|---|
| committer | Dibyendu Majumdar <dibyendumajumdar@users.noreply.github.com> | 2023-11-01 18:56:50 +0000 |
| commit | ccd83187b172f8ba3cd7c49b59a080fb027a184b (patch) | |
| tree | 87fb77fb0629d6db2de5560970f8b480ae57ecfc /chapter05/src/test/java/com/seaofnodes | |
| parent | 0a669bf5fa11a63516ea8f5316b0079c2eee4bde (diff) | |
| download | Simple-ccd83187b172f8ba3cd7c49b59a080fb027a184b.tar.gz Simple-ccd83187b172f8ba3cd7c49b59a080fb027a184b.zip | |
Fix bugs using keywords as ids
Add an exact 'matchx' for keywords. Add a list of keywords.
int true=0; return true; // Expected id, found 'true'
int else=arg; if(else) else=2; else else=1; return else; // Expected id, found 'else'
inta=1; return a; // undefined inta
Diffstat (limited to 'chapter05/src/test/java/com/seaofnodes')
| -rw-r--r-- | chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java index 8f09620e..32ac5aac 100644 --- a/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java +++ b/chapter05/src/test/java/com/seaofnodes/simple/Chapter05Test.java @@ -95,6 +95,26 @@ return c; StopNode stop = new Parser("return true;").parse(); assertEquals("return 1;",stop.toString()); } + + @Test + public void testChapter5Keyword1() { + try { + new Parser("int true=0; return true;").parse(); + fail(); + } catch( RuntimeException e ) { + assertEquals("Expected an identifier, found 'true'",e.getMessage()); + } + } + + @Test + public void testChapter5Keyword2() { + try { + new Parser("int else=arg; if(else) else=2; else else=1; return else;").parse(); + fail(); + } catch( RuntimeException e ) { + assertEquals("Expected an identifier, found 'else'",e.getMessage()); + } + } @Test public void testChapter4Peephole() { @@ -197,6 +217,16 @@ return c; } @Test + public void testChapter4Bug3() { + try { + new Parser("inta=1; return a;").parse(); + fail(); + } catch( RuntimeException e ) { + assertEquals("Undefined name 'inta'",e.getMessage()); + } + } + + @Test public void testVarDecl() { Parser parser = new Parser("int a=1; return a;"); StopNode ret = parser.parse(); @@ -242,7 +272,6 @@ return c; } } - @Test public void testChapter2ParseGrammar() { Node._disablePeephole = true; // disable peephole so we can observe full graph |
