summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2020-04-30 08:34:15 +0200
committerAkim Demaille <akim.demaille@gmail.com>2020-05-01 10:36:05 +0200
commit0407acbc595882374febf0a2e471e996131125e6 (patch)
treefd7c24382192633d84491a2c7e193456806a3db7 /examples
parent0c0e778bd13f25771da5390d0649fd96a634ecc6 (diff)
downloadbison-0407acbc595882374febf0a2e471e996131125e6.tar.gz
java: comment changes
* data/skeletons/lalr1.java, examples/java/calc/Calc.y: here.
Diffstat (limited to 'examples')
-rw-r--r--examples/java/calc/Calc.y25
1 files changed, 20 insertions, 5 deletions
diff --git a/examples/java/calc/Calc.y b/examples/java/calc/Calc.y
index d0b507f3..5a5d2048 100644
--- a/examples/java/calc/Calc.y
+++ b/examples/java/calc/Calc.y
@@ -113,6 +113,9 @@ class CalcLexer implements Calc.Lexer {
return new Position(end);
}
+ /**
+ * Build and emit a syntax error message.
+ */
public void reportSyntaxError(Calc.Context ctx) {
System.err.print(ctx.getLocation() + ": syntax error");
{
@@ -131,11 +134,18 @@ class CalcLexer implements Calc.Lexer {
System.err.println("");
}
- public void yyerror(Calc.Location l, String s) {
- if (l == null)
- System.err.println(s);
+ /**
+ * Emit an error referring to the given location in a user-defined way.
+ *
+ * @@param loc The location of the element to which the
+ * error message is related.
+ * @@param msg The string for the error message.
+ */
+ public void yyerror(Calc.Location loc, String msg) {
+ if (loc == null)
+ System.err.println(msg);
else
- System.err.println(l + ": " + s);
+ System.err.println(loc + ": " + msg);
}
Integer yylval;
@@ -185,7 +195,9 @@ class CalcLexer implements Calc.Lexer {
}
}
-
+/**
+ * A class defining a point in the input.
+ */
class Position {
public int line = 1;
public int column = 1;
@@ -227,6 +239,9 @@ class Position {
}
}
+/**
+ * A Stream reader that keeps track of the current Position.
+ */
class PositionReader extends BufferedReader {
private Position position = new Position();