title: In what order does Python find syntax errors?
body: <p>Working on creating syntax debugging exercise for students. We have the following example.</p>
  <pre><code>def five():
      print('five')
  return 5
  
  def hello();
     print('hello')
  </code></pre>
  <p>However when running the file the syntax error is</p>
  <pre><code>def hello();
             ^
  SyntaxError: invalid syntax
  </code></pre>
  <p>I've looked all over but can not figure out why the compiler [sic] doesn't complain about the return keyword outside of the function, but instead first finds the semicolon error under it.</p>
  <p>In what order does Python check the file syntax? Is this part of the specification or is it implemenation defined?</p>