Programming Language Comparison

Topics: C, Data types, Bitwise operation Pages: 14 (3807 words) Published: July 28, 2013

This section does not cite any references or sources. Please help improve this section by adding citations to reliable sources. Unsourced material may be challenged and removed. (June 2013) Syntactically, Pascal is much more ALGOL-like than C. English keywords are retained where C uses punctuation symbols – Pascal has and, or, and mod where C uses &&, ||, and % for example. However, C is actually more ALGOL-like than Pascal regarding (simple) declarations, retaining the type-name variable-name syntax. For example, C can accept declarations at the start of any block, not just the outer block of a function. Semicolon use

Another more subtle difference is the type of delimiter used. In Pascal semicolons separate individual statements within a compound statement and also used to terminate a statement. They are also syntactically part of the statement itself in C (transforming an expression into a statement). This difference manifests itself primarily in two situations: •there can never be a semicolon directly before else in Pascal whereas it is mandatory in C (unless a block statement is used) •the last statement before an end is not required to be followed by a semicolon A superfluous semicolon can be put on the last line before end, thereby formally inserting an empty statement. Comments

In traditional C, there are only /* block comments */. This is only supported by certain Pascal dialects like MIDletPascal. In traditional Pascal, there are { block comments } and (* block comments *). Modern Pascal, like Object Pascal (Delphi, FPC), as well as modern C implementations allow C++ style comments // comments Identifiers and keywords

C and Pascal differ in their interpretation of upper and lower case. C is case sensitive while Pascal is not, thus MyLabel and mylabel are distinct names in C but identical in Pascal. In both languages, identifiers consist of letters and digits, with the rule that the first character may not be a digit. In C, the underscore counts as a letter, so even _abc is a valid name. Names with a leading underscore are often used to differentiate special system identifiers in C. Both C and Pascal use keywords (words reserved for use by the language itself). Examples are if, while, const, for and goto, which are keywords that happen to be common to both languages. In C, the basic built-in type names are also keywords (e.g. int, char) or combinations of keywords (e.g. unsigned char), while in Pascal the built-in type names are predefined normal identifiers. Definitions, declarations, and blocks

In Pascal, procedure definitions start with keywords procedure or function and type definitions with type. In C, function definitions are determined by syntactical context while type definitions use the keyword typedef. Both languages use a mix of keywords and punctuation for definitions of complex types; for instance, arrays are defined by the keyword array in Pascal and by punctuation in C, while enumerations are defined by the keyword enum in C but by punctuation in Pascal. In Pascal functions, begin and end delimit a block of statements (proper), while C functions use "{" and "}" to delimit a block of statements optionally preceded by declarations. C (before C99) strictly defines that any declarations must occur before the statements within a particular block but allows blocks to appear within blocks, which is a way to go around this. Pascal is strict that declarations must occur before statements, but allows definitions of types and functions - not only variable declarations - to be encapsulated by function definitions to any level of depth. Implementation

The grammars of both languages are of a similar size. From an implementation perspective the main difference between the two languages is that to parse C it is necessary to have access to a symbol table for types, while in Pascal there is only one such construct, assignment. For instance, the C fragment X * Y; could be a declaration of Y to be an...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Procedural Programming Essay
  • Introduction to the C# Programming Language Essay
  • Pointers C-Language Essay
  • Pascal programming Essay
  • Module 2-Varibale Naming Rules Essay
  • A Comparison Programming Languages Essay

Become a StudyMode Member

Sign Up - It's Free