Dedent Java code blocks

This commit is contained in:
Kiril Kovachev 2025-03-07 16:26:44 +00:00
parent c263db95f0
commit 9162219ca4

View File

@ -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