LanguageSyntax

 Edit this page
This is a discussion of the issues of syntax as a whole in Wheat. For a discussion of the specific syntax constructs, see LanguageConstructs. --MarkLentczner 2003-03-08

The language of Wheat can be expressed at two different levels: An abstract syntax, and one of several concrete syntaxes.

Abstract Syntax

The abstract syntax describes what can happen in a Wheat method. It is the description of the instructions to the execution model. It can be specified with a BNF where the terminals are all symbols, not character strings.

The top level abstract syntax might go something like this:
method ::= declaration* statement* statement ::= message assignment* assignment ::= variable message ::= name receiver argument* receiver ::= value argument ::= keyword value value ::= variable | constant | message ...
This can be parsed by a tree parser, such as those generated by [http://www.antlr.org/ Antlr]. In fact, the Wheat syntax parsers generate the abstract syntax trees from the other syntaxes. These abstract syntax trees are then parsed by tree parsers to either produce compiled methods or to output the other syntaxes.

The actual Antlr grammar files are checked. See ScriptCompiler.g which parses the tree and generates bytecodes. --MarkLentczner 2004-04-21

I have for years been thinking about a new kind of byte coding for virtual machines that would a more direct encoding of this sort of abstract syntax. It is now implemented. Nicely enough, it turns out to be be both more compact and more efficient to execute. --MarkLentczner 2003-04-21

Concrete Syntaxes

Of course, programmers don't want to read or write parse trees directly. Hence, Wheat's language must have a concrete syntax. Actually, it can, and does, have several.

Text Syntax: The text syntax of Wheat is often written in the <textarea> input fields in web browsers. As such, it must support these generally poor featured editors. In this context there may be different character sets in use, there is generally no formatting available, and the support for editing is poor.

The text syntax only requires characters in the ASCII printing range (33~126) and limited use of the ASCII control range. It is line-ending neutral (meaning it doesn't care about the difference between CR, LF, or CRLF style endings), and makes limited use of white space.

See: TextSyntax.

XML Syntax: There is value in making code in the language be easily manipulatable by machine. Rather than make the main syntax be more geared for this purpose (like Lisp does), Wheat instead has a second syntax for this purpose. The XML syntax renders code into an XML document.

Formatted Syntax: Viewing code is a different activity than writing code. When reading and reviewing large amounts of code, one can present the code in a format that is easier to read than the text syntax. The formatted syntax of code makes use of commonly available typographic formatting: bold, italic, font size changes, and color, to make the code as clear as possible. This furthers the Wheat belief that the code is its own best documentation.

Protocol Specific Syntaxes: Some protocols, over which the Wheat server communicates, will want to be able to express code, or at least code fragments. There may be syntaxes for Wheat that encode all or part of the Wheat abstract syntax in way compatible with existing protocols.

Two obvious candidates for a protocol specific syntax are encoding a message as an HTTP request or as a URL. (These are obviously related, but the HTTP request can make use of HTTP methods, headers, and the MIME body.)


Issues

Transformation: Can a method be transformed between all syntax representations without loss? Surely there is no loss semantic information: Moving from the ASCII syntax to abstract syntax to XML syntax and then back to the ASCII results in a method that functions the same. But does it look the same? Was all the extraneous formatting of the ASCII syntax somehow captured and added to the abstract and XML syntaxes as annotations (since they have no semantic value to the abstract syntax)?
I believe that formatting information should NOT go into the xml representation. The formatting information is more like metadata that should be stored separately, so it can also be changed independently. Stylesheets can be used to convert xml back into ascii syntax. That way, if a programmer wants his ascii to use a particular coding style, then he can change the stylesheets. --SummerMisherghi 2003-03-10

Syntatic Sugar: This is really just a special case of the transformation issue. But, it is conceivable that it may make sense that, while not preserving formatting, syntatic sugar should be preserved. "candied"?


Discussion

Subject: Heretical remark
WheatScript syntax should look like C++ or Java. E.g.
object->method(args...)
Anything wrong with that.
--BruceSchwartz

Well, I agree that in this day and age there are alot of conventions in programming languages that it would wrong to ignore. Too many people now have a 'natural' association with what foo.x means to make foo.x mean anything other than member reference.

On the other hand, consider another, now assumed 'natural' syntax:
http://bigfoo.com/repository/object/method?args...
Hmmmm...
http://bigfoo.com/repository/object/method?x=3&y=4
looks alot like key word arguments to me....
--MarkLentczner

I don't have a problem with named arguments but I'm thinking that a space-optional syntax would be good for method invocation. So
object->method(arg1,foo=3,bar=4)

I know it is ugly but I'm no longer sure that ugliness in syntax is such a bad thing.
--BruceSchwartz

Ugliness is definitely in the eye of the beholder. Who's the target audience as a Wheat programmer? I think that should help drive some of the questions of syntax & sugar. It's also a fact that if the main interface for programming is to use a web browser, then shorter, more easily typed items are going to be pretty important (although the web interface could allow shorthand that gets converted to true Wheat). For example, if I had to type
http://someverylongurl.com/repository/myrepository/myverylongobjectname/someextremelylongmethodnamethatisverydescriptive?toolongargumentname1=value1&anotherlongargumentname=value2
then I'm very likely to make mistakes in typing that, and just generally have lots of problems (not to mention the problems of funky line breaks with very long items without spaces in them). Of course, using namespaces may be a way to simplify the object links without sacrificing the generality.

By the way, I don't know if it's just because I'm using Netscape, but the only easy way for me to get a tab in this stuff is to copy one of the ones already in the page. Just a comment on how having a web browser interface to coding can cause some styles to be good & others to be bad.
--TimLearmont

Whatever happened to an XML-based model? Wouldn't precise syntax be arbitrary, and only the basic structural restrictions important to define. Store wheat programs as xml. Then let the IDE do the conversion from whatever syntax it wants to allow into the wheat format.

"It's also a fact that if the main interface for programming is to use a web browser"

Is this true? I doubt it. I doubt invoking methods on objects directly from a browser is how people are going to want to access that functionality. first of all that bypasses the whole idea of the templates as the front end for a typical application. And if you just want to access a particular remote object's functionality, then you would likely want to do this programmatically.

Are the objects planned to be exposed to wheat-free systems other than web-browsers?
OK let me go look at the rest of the site, maybe I'll get some answers.
--SummerMisherghi

See DevelopmentEnvironment as the place to discuss whether you write code in a browser or if not, how
--JimKingdon

By the way, regarding URL retrieval, most popular browsers restrict the maximum length possible for a URL of course. Does that matter-- I imagine it could lead to trouble if wheat is flown over HTTP. Or is it an extremely lax limitation? Never noticed other systems caring about this issue. Just throwin out ideas.
--SummerMisherghi

How about XML calls
<object method="abc"> <param1>val1</param1> <param2>val2</param2> </object>

--VirenGupta?

A fair compromise would be to have optional named arguments.

You should be able to choose between
http://bigfoo.com/repository/object/method?longparam1=100&longparam2=200

And
http://bigfoo.com/repository/object/method?100&200

With an optional mixed syntax:
http://bigfoo.com/repository/object/method?100&200&longparam3=300

--NoName?


See VariousNameRules
There is no comment on this page. [Display comments/form]