On Mon, 21 Oct 2013 21:24:38 -0700, Mark Janssen wrote:

>> A language specification in BNF is just syntax. It doesn't say anything
>> about semantics. So how could this be used to produce executable C code
>> for a program? BNF is used to produce parsers. But a parser isn't
>> sufficient.
> 
> A C program is just syntax also.  How does the compiler generate
> executable machine code?  Extrapolate into a Python front-end to C.

Like every other language, C programs are certainly not *just* syntax. 
Here is some syntax:

&foo bar^ :=

What machine code should be produced? Right now, you should be saying 
"How the hell do I know? What does that line of code *do*???" and you 
would be right to ask that question.

Syntax on its own doesn't mean anything. You also need to know the 
*semantics* of the code, in other words, *what it means*. That knowledge 
is inherent to the compiler: a C compiler "understands" what C code 
means, a Pascal compiler "understands" Pascal code, a Forth compiler 
"understands" Forth.

Merely parsing code doesn't capture that understanding. Parsing a line 
like "foo <= bar" will give you something like this:

NAME "foo"
OPERATOR "<="
NAME "bar"
END_LINE

What does the operator "<=" actually do? What does "foo" represent? Is it 
a variable, a constant, a global, a local, something else? What are the 
rules for deciding whether a variable is in the local scope, a global 
scope, or something else? Does the language even have scopes?



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to