mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-26 20:53:04 +00:00
style: java: get closer to the Java style
* examples/java/calc/Calc.y, examples/java/simple/Calc.y: here.
This commit is contained in:
@@ -19,8 +19,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
%code {
|
%code {
|
||||||
public static void main(String[] args) throws IOException
|
public static void main(String[] args) throws IOException {
|
||||||
{
|
|
||||||
CalcLexer l = new CalcLexer(System.in);
|
CalcLexer l = new CalcLexer(System.in);
|
||||||
Calc p = new Calc(l);
|
Calc p = new Calc(l);
|
||||||
for (String arg : args)
|
for (String arg : args)
|
||||||
@@ -30,8 +29,7 @@
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String i18n(String s)
|
static String i18n(String s) {
|
||||||
{
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,8 +94,7 @@ class CalcLexer implements Calc.Lexer {
|
|||||||
StreamTokenizer st;
|
StreamTokenizer st;
|
||||||
PositionReader reader;
|
PositionReader reader;
|
||||||
|
|
||||||
public CalcLexer (InputStream is)
|
public CalcLexer(InputStream is) {
|
||||||
{
|
|
||||||
reader = new PositionReader(new InputStreamReader(is));
|
reader = new PositionReader(new InputStreamReader(is));
|
||||||
st = new StreamTokenizer(reader);
|
st = new StreamTokenizer(reader);
|
||||||
st.resetSyntax();
|
st.resetSyntax();
|
||||||
@@ -116,8 +113,7 @@ class CalcLexer implements Calc.Lexer {
|
|||||||
return new Position(end);
|
return new Position(end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportSyntaxError (Calc.Context ctx)
|
public void reportSyntaxError(Calc.Context ctx) {
|
||||||
{
|
|
||||||
System.err.print(ctx.getLocation() + ": syntax error");
|
System.err.print(ctx.getLocation() + ": syntax error");
|
||||||
{
|
{
|
||||||
final int TOKENMAX = 10;
|
final int TOKENMAX = 10;
|
||||||
@@ -135,8 +131,7 @@ class CalcLexer implements Calc.Lexer {
|
|||||||
System.err.println("");
|
System.err.println("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void yyerror (Calc.Location l, String s)
|
public void yyerror(Calc.Location l, String s) {
|
||||||
{
|
|
||||||
if (l == null)
|
if (l == null)
|
||||||
System.err.println(s);
|
System.err.println(s);
|
||||||
else
|
else
|
||||||
@@ -153,8 +148,7 @@ class CalcLexer implements Calc.Lexer {
|
|||||||
start.set(reader.getPosition());
|
start.set(reader.getPosition());
|
||||||
int ttype = st.nextToken();
|
int ttype = st.nextToken();
|
||||||
end.set(reader.getPosition());
|
end.set(reader.getPosition());
|
||||||
switch (ttype)
|
switch (ttype) {
|
||||||
{
|
|
||||||
case StreamTokenizer.TT_EOF:
|
case StreamTokenizer.TT_EOF:
|
||||||
return EOF;
|
return EOF;
|
||||||
case StreamTokenizer.TT_EOL:
|
case StreamTokenizer.TT_EOL:
|
||||||
@@ -196,47 +190,39 @@ class Position {
|
|||||||
public int line = 1;
|
public int line = 1;
|
||||||
public int column = 1;
|
public int column = 1;
|
||||||
|
|
||||||
public Position ()
|
public Position() {
|
||||||
{
|
|
||||||
line = 1;
|
line = 1;
|
||||||
column = 1;
|
column = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Position (int l, int t)
|
public Position(int l, int t) {
|
||||||
{
|
|
||||||
line = l;
|
line = l;
|
||||||
column = t;
|
column = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Position (Position p)
|
public Position(Position p) {
|
||||||
{
|
|
||||||
line = p.line;
|
line = p.line;
|
||||||
column = p.column;
|
column = p.column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set (Position p)
|
public void set(Position p) {
|
||||||
{
|
|
||||||
line = p.line;
|
line = p.line;
|
||||||
column = p.column;
|
column = p.column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals (Position l)
|
public boolean equals(Position l) {
|
||||||
{
|
|
||||||
return l.line == line && l.column == column;
|
return l.line == line && l.column == column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString ()
|
public String toString() {
|
||||||
{
|
|
||||||
return Integer.toString(line) + "." + Integer.toString(column);
|
return Integer.toString(line) + "." + Integer.toString(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int line ()
|
public int line() {
|
||||||
{
|
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int column ()
|
public int column() {
|
||||||
{
|
|
||||||
return column;
|
return column;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
%code {
|
%code {
|
||||||
public static void main (String[] args) throws IOException
|
public static void main(String[] args) throws IOException {
|
||||||
{
|
|
||||||
CalcLexer l = new CalcLexer(System.in);
|
CalcLexer l = new CalcLexer(System.in);
|
||||||
Calc p = new Calc(l);
|
Calc p = new Calc(l);
|
||||||
if (!p.parse())
|
if (!p.parse())
|
||||||
@@ -71,8 +70,7 @@ class CalcLexer implements Calc.Lexer {
|
|||||||
|
|
||||||
StreamTokenizer st;
|
StreamTokenizer st;
|
||||||
|
|
||||||
public CalcLexer (InputStream is)
|
public CalcLexer(InputStream is) {
|
||||||
{
|
|
||||||
st = new StreamTokenizer(new InputStreamReader(is));
|
st = new StreamTokenizer(new InputStreamReader(is));
|
||||||
st.resetSyntax();
|
st.resetSyntax();
|
||||||
st.eolIsSignificant(true);
|
st.eolIsSignificant(true);
|
||||||
@@ -81,8 +79,7 @@ class CalcLexer implements Calc.Lexer {
|
|||||||
st.wordChars('0', '9');
|
st.wordChars('0', '9');
|
||||||
}
|
}
|
||||||
|
|
||||||
public void yyerror (String s)
|
public void yyerror(String s) {
|
||||||
{
|
|
||||||
System.err.println(s);
|
System.err.println(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +91,7 @@ class CalcLexer implements Calc.Lexer {
|
|||||||
|
|
||||||
public int yylex() throws IOException {
|
public int yylex() throws IOException {
|
||||||
int ttype = st.nextToken();
|
int ttype = st.nextToken();
|
||||||
switch (ttype)
|
switch (ttype) {
|
||||||
{
|
|
||||||
case StreamTokenizer.TT_EOF:
|
case StreamTokenizer.TT_EOF:
|
||||||
return EOF;
|
return EOF;
|
||||||
case StreamTokenizer.TT_EOL:
|
case StreamTokenizer.TT_EOL:
|
||||||
|
|||||||
Reference in New Issue
Block a user