From 9162219ca4a356a03c176b8f4b0e22d52dc56e6e Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Fri, 7 Mar 2025 16:26:44 +0000 Subject: [PATCH] Dedent Java code blocks --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7400bae..7e0d96c 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,8 @@ The part of code delimited by `PARSER_BEGIN(Assignment)` and `PARSER_END(Assignm represents the parser at the highest level. You can create an instance of this parser class and feed it some input in order to see its effects. That's exactly what this code does: ```java - Assignment parser = new Assignment(System.in); - parser.Start(); +Assignment parser = new Assignment(System.in); +parser.Start(); ``` ...which takes our parser (whose name is `Assignment`, because that's what was specified inside `PARSER_BEGIN`), constructs an instance of it, giving it the input stream `System.in` (standard input), and then calls the entry point to the parser (its start symbol or sentence symbol). @@ -139,19 +139,19 @@ And, with that, the main part of the grammar is done! ### Driver code Here is the entry point to our parser again, the part within the PARSER_BEGIN directive: ```java - class Assignment { - public static void main(String[] args) throws ParseException, TokenMgrError - { - try { - Assignment parser = new Assignment(System.in); - parser.Start(); - System.out.println("PASS"); - } catch (ParseException e) { - System.out.println("FAIL"); - System.err.println(e.currentToken.beginLine); - } +class Assignment { + public static void main(String[] args) throws ParseException, TokenMgrError + { + try { + Assignment parser = new Assignment(System.in); + parser.Start(); + System.out.println("PASS"); + } catch (ParseException e) { + System.out.println("FAIL"); + System.err.println(e.currentToken.beginLine); } } +} ``` In order to implement the desired I/O action of printing pass/fail to the standard output, and printing the error line if occurred to standard error, we use exception handling to handle the possible exceptions generated by JavaCC's output tokenizer and parser. Note that, because of the `ANY` token