On Jan 15, 2006, at 11:47 AM, James Gray wrote:

I do not know the difference between the semantics of M and a formal semantics.

Computer languages have (at least) two aspects: syntax and semantics. Syntax has to do with the form of statements and expressions. For example, MUMPS syntax tells you that 2+3*4 parses as (2+3)*4 instead of 2+(3*4) (as it would in most languages). Syntax is normally expressed formally using something like BNF (Backus-Naur formalism). An expression grammar in MUMPS might look something like this:

<term> ::= literal | variable
<binop> ::= '+' | '-' | '*' | '/'
<expression> ::= <term> | <texpression><binop><term>

(where '::=' means "can be expanded to" and '|' means "or"). Obviously, this grammar is an oversimplification, but it's enough to illustrate the basic idea. How do you parse 2+3*4 ? According to this grammar, the only possibility is as the expression "2+3" followed by '*', followed by 4. A more conventional expression grammar might be

<literal> ::= <number> | <variable>
<term> ::= <literal> '*' <term> | <literal> '/' <term>
<expression> ::= <term> '+' <expression> | <term> '-' <expression>

In this case, "3*4" is a term, but "2+3" is not, so the only possible parse is 2 + (3 * 4)

But at the level of syntax, these are still only symbols. How do you evaluate expressions? An operational semantics might say that 4/2 is evaluated by first evaluating '4' and '2' (to get 4 and 2, respectively), checking that 2 is not 0, and then if it is not, evaluating the whole thing to get what results when you divide 4 by 2 (i.e., 2). When dividing by 0 an error is signaled. What happens then? At a minimum, $ECODE will be set and evaluation of the current expression will be interrupted, but what then? That depends, for example on whether you've installed an error handler, whether there is a stack overflow, etc.

In many languages, semantics is described only informally, as I've done here. But formalisms like operational semantics and denotational semantics allow you to express the way programs are executed more precisely, just as BNF allows you to describe the language syntax more precisely.

===
Gregory Woodhouse
[EMAIL PROTECTED]

"You can't win if you don't finish the race."
--Richard Petty





-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Hardhats-members mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hardhats-members

Reply via email to