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