The syntax of C (note: homework task)

F

Fred Nurk

I'm doing my IT holiday homework and I get this:

Investigate your chosen programming or scripting language and determine
the following:

....
(d) What is the syntax of the language?

I've chosen C. In table 8.3 (Programming languages and codes), under PHP,
it says: 'Syntax is fairly simple and similar to that of Perl, with some
aspects like Javascript and C.'
Under ActionScript, it says: 'Has its own syntax that determines which
characters and words are used to create meaning and in which order they
can be written.'

Do you think: 'Syntax (of C) is the basis of the syntax of many other
high-level programming/scripting languages. Pointer and structure syntax
can become complex.' is adequate?

TIA,
Fred
 
I

Ian Collins

I'm doing my IT holiday homework and I get this:

Investigate your chosen programming or scripting language and determine
the following:

...
(d) What is the syntax of the language?

I've chosen C. In table 8.3 (Programming languages and codes), under PHP,
it says: 'Syntax is fairly simple and similar to that of Perl, with some
aspects like Javascript and C.'

Well that's rubbish, PHP syntax (excluding the OO parts) is much more
like C than Perl. Where is this table you refer to?
Under ActionScript, it says: 'Has its own syntax that determines which
characters and words are used to create meaning and in which order they
can be written.'

Do you think: 'Syntax (of C) is the basis of the syntax of many other
high-level programming/scripting languages. Pointer and structure syntax
can become complex.' is adequate?

Adequate for what? The question appears to be looking for a description
of the language syntax (which would be long), not how it relates to others.
 
F

Fred Nurk

Ian said:
<snip>
Where is this table you refer to?

At http://sites.google.com/site/xtheunknown0/information-technology
<snip>
Adequate for what? The question appears to be looking for a description
of the language syntax (which would be long), not how it relates to
others.

Well, my IT course doesn't really go into any specific programming
language. I doubt that a 'description of the language syntax' would be
expected.

Do you think that my answer models the 'overviews' in the textbook?

TIA,
Fred
 
B

bart.c

Fred Nurk said:
I'm doing my IT holiday homework and I get this:

Investigate your chosen programming or scripting language and determine
the following:

...
(d) What is the syntax of the language?

I've chosen C. In table 8.3 (Programming languages and codes), under PHP,
it says: 'Syntax is fairly simple and similar to that of Perl, with some
aspects like Javascript and C.'
Under ActionScript, it says: 'Has its own syntax that determines which
characters and words are used to create meaning and in which order they
can be written.'

Do you think: 'Syntax (of C) is the basis of the syntax of many other
high-level programming/scripting languages.
Pointer and structure syntax
can become complex.' is adequate?

It would be wrong; they're not particularly complex.

What *are* complex are type declarations, which can become near impossible
to decipher without special tools or following an algorithm.

Fortunately most languages that borrowed it's syntax wisely decided not to
copy it's type declarations.
 
P

Pascal J. Bourguignon

Fred Nurk said:
I'm doing my IT holiday homework and I get this:

Investigate your chosen programming or scripting language and determine
the following:

...
(d) What is the syntax of the language?

I've chosen C. In table 8.3 (Programming languages and codes), under PHP,
it says: 'Syntax is fairly simple and similar to that of Perl, with some
aspects like Javascript and C.'
Under ActionScript, it says: 'Has its own syntax that determines which
characters and words are used to create meaning and in which order they
can be written.'

Do you think: 'Syntax (of C) is the basis of the syntax of many other
high-level programming/scripting languages. Pointer and structure syntax
can become complex.' is adequate?

The syntax of a programming language is determined by its lexic and
its grammar.

The lexic is the set (possibly infinite) of 'letters' of the language.

In a language like C, '{' is one 'letter', but 'while' is one too, as
well as 'generateGrammar'.

The grammar is a tuple (S, NT, T, R) where is the start symbol, an
element of NT ∪ T. (Usually it's from NT), NT is a set of non-terminal
symbols, T is a set of terminal symbols, it's the lexic, and R is a
set of production rules. Each rule is of the form: lhs -> rhs where
(lhs,rhs) ∈ (NT ∪ T)². In practice, we use restricted forms of
grammar, where lhs is in NT (and S in NT too), and depending on the
parsing algorithm we want to use, additionnal restriction may be
placed on the rhs (such as avoiding right, or left recursion, etc).


So, comparing the complexity of languages is comparing the
'complexity' of two tuples (S, NT, T, R).

Here is the first difficulty: there is not a unique grammar for a
given language. Two different grammars may generate the same
language. I'm not sure we could define a 'normal form' for grammars.
If you can define a less-complex relationship for grammars generating
the same language, you can probably find grammars of minimal
complexity, but there will be probably be several uncomparable minima.


Then you may want to consider other complexities, such as the
complexity of the parsing algorithm required by the grammar, or the
complexity of the parsing process.

In either case, you may find that a more complex grammar (a more
complex (S, NT, T, R)) is actually simplier to parse (ie. it's
possible to parse with a simplier parser algorithm, or is faster to
parse (there is an algorithm producing a simplier parsing process)).

But what's more, these complexities have little relation with the
difficulty a human brain will have to write or read words of these
languages. Often a very simple grammar will be very hard to read or
write. A typical example is C, which has a grammar relatively
simplier than other languages that existed at the time it was created,
or after, (because C was defined with the sole purpose to write an
operating system on a computer that was too small to do anything
useful so it was given to Kerningham, Ritchie and Thompson so they may
play with it (and indeed, they had to write this OS only to be able to
port and run a game program from Multics)), but which is actually much
harder to read and write for most programmers (even without semantics
considerations, the syntax of C is hard enough to justify a sizeable
share of bugs).

Of course it could be argued that languages with complex grammars are
also hard to read and write. I would say that it depends. Natural
language grammars are usually more complex than programming language,
but they're often more eassily read and written, on one hand, and on
the other, there are languages with very simple grammar, that are also
very easy to read and write.




Finally, the fact that two different languages use the same lexic
doesn't imply anything about their relative 'complexity' however you
defined this (while you don't restrict this definition to a comparison
of the lexic). An example of this would be C vs. C++, where the lexic
are about the same (there are a few additions in C++), but where the
grammar of C++ is much more complex than the grammar of C (there are
more grammar rules).
 
B

BGB / cr88192

bart.c said:
It would be wrong; they're not particularly complex.

What *are* complex are type declarations, which can become near impossible
to decipher without special tools or following an algorithm.

Fortunately most languages that borrowed it's syntax wisely decided not to
copy it's type declarations.

agreed...


even though, for example, declarations in C# or Java resemble those of C,
their underlying mechanics are somewhat different, and as a result it is
possible to parse C# or Java without knowing in advance what the types are,
but similar is not possible with C or C++.

granted, it is possible that one could make a sort of "faux C" which uses a
C# style syntax, although at the cost that it would not generally be fully
source-compatible with C.

oddly enough, a lot of my code is forced into a similar notation anyways,
mostly as I tend to use specialized code-processing tools which place
restrictions on the allowed syntax (as they are fairly dumb tools with an
incomplete understanding of the language syntax).
 
D

Denis McMahon

Do you think: 'Syntax (of C) is the basis of the syntax of many other
high-level programming/scripting languages. Pointer and structure syntax
can become complex.' is adequate?

If you really thought it was adequate, you wouldn't even be asking.

Rgds

Denis McMahon
 
B

Bart van Ingen Schenau

Well, my IT course doesn't really go into any specific programming
language. I doubt that a 'description of the language syntax' would be
expected.

Do you think that my answer models the 'overviews' in the textbook?

No. The table you refer to seems to give, mostly, a short description
of the defining characteristics of the languages, along the lines of
answers to the question "What makes languag X be language X".
TIA,
Fred

Bart v Ingen Schenau
 
D

Daniel Pitts

I'm doing my IT holiday homework and I get this:

Investigate your chosen programming or scripting language and determine
the following:

...
(d) What is the syntax of the language?

I've chosen C. In table 8.3 (Programming languages and codes), under PHP,
it says: 'Syntax is fairly simple and similar to that of Perl, with some
aspects like Javascript and C.'
Under ActionScript, it says: 'Has its own syntax that determines which
characters and words are used to create meaning and in which order they
can be written.'

Do you think: 'Syntax (of C) is the basis of the syntax of many other
high-level programming/scripting languages. Pointer and structure syntax
can become complex.' is adequate?

TIA,
Fred
The Syntax of C is losely based on the Algol family of languages.

It is primarily an imperative language, with syntax for flow control
structures and data structures.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top