Python Front-end to GCC

Ned Batchelder ned at nedbatchelder.com
Tue Oct 22 11:46:11 EDT 2013


On 10/22/13 11:04 AM, Mark Janssen wrote:
> I love it.  Watch this...
>
> [context]
>>>> 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.
> [Dave Angel responds:]
>> Did you even read the paragraph you quoted above?  The BNF specification
>> does NOT completely describe a language, it only defines its syntax.
> [Steven D'Aprano responds:]
>> Like every other language, C programs are certainly not *just* syntax.
>> Here is some syntax:
>>
>> &foo bar^ :=
> Now, I don't know where y'all were taught Computer Science, but BNF
> specifies not only syntax (which would be the *tokens* of a language),
> but also its *grammar*;  how syntax relates to linguistic categories
> like keywords, and tokens relate to each other.

Mark, you had expressed interest in "an app that will take a language 
specification in BNF (complete with keywords and all) and output C code 
which is then compiled to an executable".   I'm interested in how that 
app might work.

Here's a BNF for a (very!) simple language:

     <program> ::= <number> <op> <number>
     <op> ::=  "*!?" | "--+" | "..:"

That means these are three valid programs:

     123 *!? 456
     2 --+ 2
     1001 ..: 4

What will the app output as C code for each of these?

>
> Dave is claiming that BNF only defines the syntax of a language, but
> then Stephen goes on to supply some syntax that a BNF specification of
> the language would not allow (even though Steven calls it "syntax"
> which is what BNF in Dave's claim parses).
>
> So which of you is confused?  I ask that in the inclusive (not
> exclusive OR) sense.... ;^)  <-- face says "both".

Could you please be less snarky?  We're trying to communicate here, and 
it is not at all clear yet who is confused and who is not.  If you are 
interested in discussing technical topics, then discuss them.

--Ned.

>
> Mark Janssen
> Tacoma, Washington.




More information about the Python-list mailing list