<div dir="ltr">There isn't an ambiguity as the simplified syntax I'm proposing doesn't allow for an instance initialization block. For the instance initialization block to be available, you must be in a class declaration, at which point you're in the full syntax.<div><br></div><div>Parsing would be as follows, if the first token is:</div><div>* package - parse and work as a normal java class</div><div>* import - parse import statements until you reach either '{' or a token that starting with a letter</div><div>  - if a letter, then treat as a normal java class</div><div>  - if { use this syntax.</div><div><br></div><div>When I have implemented this in the past, I've written it as a frontend and generated an underlying Java source file to pass to the standard compiler (the template using class Main is an example), then done line number fixups on the errors.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 13, 2023 at 12:55 PM Holo The Sage Wolf <<a href="mailto:holo3146@gmail.com">holo3146@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>I can't comment on the first point, but the second point won't work.</div><div dir="auto">The syntax you suggested creates at best an order of declaration dependency between the entry point and the instance initialized block, and at worst an ambiguity to the compiler.</div><div dir="auto"><br></div><div dir="auto">Also, I believe that in the current solution it is possible to import in an unnamed main class.</div><div dir="auto"><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Thu, Apr 13, 2023, 18:49 Andrew Evers <<a href="mailto:andrew.evers@gmail.com" target="_blank">andrew.evers@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I really like the idea of reducing the amount of boilerplate required to get to a simple Java program. </div><div><br>Two comments:</div><div>1. Would it be at all possible to consider a main that returns int? Operating systems that don't support it are free to disregard it, and it feels better than System.exit(). It also allows skipping the idea of void, which is somewhat of a holdover from C.</div><div>2. I have an idea for a slightly different approach to the problem that may solve a few of the problems being proposed, and allows for imports, which would make it more useful for scripting use cases. </div><div><br></div><div>Here are three examples showing the syntax.</div><div><br></div><div>Example 1:</div><div>{</div><div>  System.out.println("Hello, World");</div><div>}</div><div><br></div><div>Example 2:<br></div><div>import java.nio.*;<br></div><div><br></div><div>{</div><div>  Path filePath = Path.of("file.txt");</div><div>  String fileContent = new String(Files.readAllBytes(filePath));</div><div>  System.out.println("Content is " + fileContent);<br></div><div>}</div><div><br></div><div>Example 3:<br></div><div>import java.nio.*;<br></div><div><br></div><div>{<br></div><div><div>  Path filePath = Path.of("file.txt");</div><div>  String fileContent = new String(Files.readAllBytes(filePath));</div><div>  greet(fileContent);<br></div><div>}</div></div><div><br></div><div>void greet(String s)</div><div>{</div><div><div>  System.out.println("Content is " + s);</div></div><div>}</div><div><br></div><div>The rules are simple:</div><div>1. If the first non-whitespace is a {, then treat it as the block defining the method public static void main(String [] args).</div><div>2. If the first non-whitespace is "import" then capture the imports.</div><div>3. If there is non-whitespace after the closing } in the main block, include it before the class closing brace.</div><div><br></div><div>That is:</div><div><br></div><div>// import statements if any</div><div>class Main  </div><div>{</div><div>  public static void main(String [] args) </div><div>  { // Content including { from source </div><div>  } // end of content, including }</div><div><br></div><div>  // Content after closing } in source, if any.</div><div>}</div><div><br></div><div>There are some minor fixups required on line numbers after the import statements, these can be overcome by either ensuring that the additional code takes up zero lines, or by fixing up the output of the compiler.</div><div><br></div><div>Regards,</div><div><br></div><div>Andrew.</div><div><br></div></div>
</blockquote></div></div></div>
</blockquote></div>