Friday, October 28, 2011

Errors: Syntax

There are very basic yet incredibly important considerations to regard when writing MEL scripts and commands; it is very important to notice details. Here are some common syntax errors that a non-programmer might be familiar with:
  • punctuation
  • capitalization
  • misspellings
  • mistypings 

Syntax Errors: An Example
Syntax errors, even a single minor one, will make Maya think you are talking gibberish to it. 
For instance:
  • if we type sphere into the Command Line, 
    • Maya will say,
      • “Aha! That’s the magic word – let me make that sphere you’re asking for!"
  • if we type sphere. (note the period) into the Command Line, 
    • Maya will say,
      • “I have no idea what you’re trying to tell me.”
Even something as benign as a period changes the command entirely.  Although we entered the right command, sphere, the period at the end ruined the syntax of the command. 


Some questions to consider:
  • What is syntax?
  • How come nothing happened when a simple period was added?
  • What do the error messages mean?

What exactly is Syntax? 
Syntax "refers to the ways symbols may be combined to create well-formed
sentences (or programs) in the language."
(Slonneger)
To put simply, syntax refers to rules in a language.  Syntax is intrinsic in all languages...
  • computer languages:
    • MEL
    • C++
    • Python
    • and many more...
  •   spoken languages:
    • English 
    • Russian
    • French
    • ...you get the picture...
All languages follow a syntax that must be followed in order to understand it. If someone speaks or writes without following proper syntax, it may sound odd or, worse, completely incomprehensible. 

Imagine what this entire blog would look like if I failed to capitalize any letters and neglected all punctuation rules. That is an example of improper syntax.

Syntax affects MEL
Syntax affects languages, so it follows that syntax affects MEL - MEL stands for Maya Embedded Language, after all.

When people communicate to each other, we can make at least TRY to make sense of syntax errors because of contextual information.  That’s why we’re able to understand Yoda when he speaks, despite his flagrant disregard for syntax!

However, making syntax errors in any computer language can be the most frustrating thing in the world simply because
  • computers and compilers are so sensitive to syntax errors
  • its so easy to make syntax errors
  • syntax errors are generally minor grammar mistakes 
Computers can't read our minds and don't take what you say into context.  When you enter a  command with even one syntax error, computers don't say, “Oh, you wrote this for me to do, but I'm guessing that this is what you really mean.”  


There's either a right way or a wrong way to communicate with computers; there is very little room for a gray area.  That's why placing a period at the end of the command, sphere, confuses Maya, leading to a syntax error. To Maya, sphere is totally different from sphere. (again, note the period)

There are too many ways to list what not to do; what’s important is:
  • there are correct ways to communicate with Maya
  • there are countless ways to miscommunicate with Maya, with regards to syntax

Next Post:

The next blog post will introduce the Script Editor and write our first MEL command

Bibliography:


Slonneger, K. (n.d.). Syntax and Semantics of Programming Languages. Retrieved October 14, 2011, from The University of Iowa: Department of Computer Science: http://www.divms.uiowa.edu/~slonnegr/plf/Book/Chapter1.pdf

No comments:

Post a Comment