Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
lynplexs:tutorial:c03 [2011/01/29 12:34]
127.0.0.1 external edit
lynplexs:tutorial:c03 [2014/05/25 18:39] (current)
Line 1: Line 1:
-====== Structure of Programs ====== +====== Structure of LynPlexS ​Programs ======
-  +
  
 ===== Objectives: ===== ===== Objectives: =====
- 
  
 Having completed this section you should know about: ​ Having completed this section you should know about: ​
  
-  * C'​s ​character set  +  * The LynPlexS ​character set  
-  * C'​s ​keywords  +  * LynPlexS ​keywords  
-  * the general structure of a program  +  * the general structure of a LynPlexS ​program  
-  * that all C statement must end in a ;  +  * that LynPlexS statements may end in a ;  
-  * that is a free format language  +  * that LynPlexS ​is a free format language  
-  * all C programs ​us header files that contain standard library functions. ​ +  * LynPlexS ​programs ​may use header files that contain standard library functions. ​
- +
- +
-===== C's Character Set: ===== +
- +
- +
-C does not use, nor requires the use of, every character found on a modern computer keyboard. The only characters required by the C Programming Language are as follows:+
  
 +===== LynPlexS Character Set: =====
 +LynPlexS does not use, nor requires the use of, every character found on a modern computer keyboard. The only characters required by the LynPlexS Programming Language are as follows:
  
      A - Z       A - Z 
Line 29: Line 22:
      + - / * =       + - / * = 
  
-The use of most of this set of characters will be discussed throughout ​the course+===== The form of a LynPlexS Program: ===== 
 +A LynPlexS program may consist ​of a few lines of code or it may be a large program that consists of multiple functions. The prolog code can be the main function or the main function can be declared as such.
  
 +For more advanced programs the main function will act as a controlling function calling other functions in their turn to do the dirty work! The main function is the first function that is called when your program executes. ​
  
-===== The form of a C Program: =====+LynPlexS makes use of keywords which combine with the formal syntax to the form the LynPlexS programming language. Note that keywords may be written in lower case, upper case or mixed case.  ​
  
 +A keyword may be used for other purposes. //Note that LynPlexS does not support all options at present.//
  
-All C programs will consist ​of at least one function, but it is usual (when your experience grows) to write program ​that comprises several functions. The only function that has to be +===== The layout of LynPlexS Programs: ===== 
-present ​is the function called main. For more advanced programs the main function ​will act as a controlling function calling other functions in their turn to do the dirty work! The main+The general form of a LynPlexS ​program is as follows (don't worry about what everything means at the moment - things ​will be explained later): ​
  
-function is the first function that is called when your program executes. ​ 
- 
-C makes use of only 32 keywords which combine with the formal syntax to the form the C programming language. Note that all keywords are written in lower case - C, like UNIX, uses 
-upper and lower-case text to mean different things. If you are not sure what to use then always use lower-case text in writing your C programs. A keyword may not be used for any other 
-purposes. For example, you cannot have a variable called auto.  
- 
- 
- 
-===== The layout of C Programs: ===== 
- 
- 
-The general form of a C program is as follows (don't worry about what everything means at the moment - things will be explained later): ​ 
- 
-  preprocessor directives 
   global declarations   global declarations
-  main() ​{+  ​prolog code 
 +  function ​main()
    local variables to function main ;    local variables to function main ;
    ​statements associated with function main ;    ​statements associated with function main ;
-   } +   end function //main() 
-  f1() {+  ​function ​f1() 
    local variables to function 1 ;    local variables to function 1 ;
    ​statements associated with function 1 ;    ​statements associated with function 1 ;
-   } +   end function //​f1() ​ 
-  f2() {+  ​function ​f2() 
    local variables to function f2 ;    local variables to function f2 ;
    ​statements associated with function 2 ;    ​statements associated with function 2 ;
-   }+   end function //​f2() ​
   .   .
   .   .
Line 70: Line 53:
   etc   etc
  
-Note the use of the bracket set () and {}. () are used in conjunction with function names whereas {} are used as to delimit the C statements that are associated with that function. ​Also note +Also note the semicolon - yes it is there, but you might have missed it! semicolon (;) can be used to terminate ​   ​LynPlexS ​statements, but it is only necessary to separate multiple ​statements ​on the same line. Statements normally end at the end of a line.
-the semicolon - yes it is there, but you might have missed it! semicolon (;) is used to terminate ​statements. C is a free format language and long statements ​can be continued, without +
-truncation, onto the next line. The semicolon informs the C compiler that the end of the statement has been reached. Free format also means that you can add as many spaces as you like to +
-improve the look of your programs.  +
- +
-A very common mistake made by everyone, who is new to the C programming language, is to miss off the semicolon. The C compiler will concatenate the various lines of the program +
-together and then tries to understand them - which it will not be able to do. The error message produced by the compiler will relate to a line of you program which could be some distance +
-from the initial mistake+
  
 +LynPlexS is a free format language and long statements can be continued onto the next line. Any special character or operator at the end of a line is treated as a continuation. ​
 +Free format also means that you can add as many spaces as you like to improve the look of your programs. ​
  
 ===== Preprocessor Directives: ===== ===== Preprocessor Directives: =====
 +//LynPlexS does not currently have a preprocessor.//​
  
 +LynPlexS is a small language but provides the programmer with all the tools to be able to write powerful programs. Some people don't like LynPlexS because it is too primitive! Look again at the set of keywords that comprises the LynPlexS language and see if you can find a command that allows you to print to the computer'​s screen the result of, say, a simple calculation. Don't look too hard because it doesn'​t exist. ​
  
-C is a small language but provides the programmer with all the tools to be able to write powerful programs. Some people don't like C because it is too primitive! Look again at the set of +It would be very tedious, for all of us, if every time we wanted to communicate with the computer we all had to write our own output functions. Fortunately,​ we do not have to. LynPlexS ​uses libraries of standard functions which are included when we build our programs. For the novice ​LynPlexS ​programmer one of the many questions always asked is does a function already exist for what I want to do? Only experience will help here but we do include a function listing as part of this course. ​
- +
-keywords that comprises the C language and see if you can find a command that allows you to print to the computer'​s screen the result of, say, a simple calculation. Don't look too hard +
-because it doesn'​t exist.  +
- +
-It would be very tedious, for all of us, if every time we wanted to communicate with the computer we all had to write our own output functions. Fortunately,​ we do not have to. uses +
-libraries of standard functions which are included when we build our programs. For the novice ​programmer one of the many questions always asked is does a function already exist for +
-what I want to do? Only experience will help here but we do include a function listing as part of this course.  +
- +
-All programs you will write will need to communicate to the outside world - I don't think I can think of a program that doesn'​t need to tell someone an answer. So all our C programs will +
-need at least one of C's standard libraries which deals with standard inputting and outputting of data. This library is called stdio.h and it is declared in our programs before the main +
-function. The .h extension indicates that this is a header file.  +
- +
-I have already mentioned that C is a free format language and that you can layout your programs how you want to using as much white space as you like. The only exception are statements +
-associated with the preprocessor.  +
- +
-All preprocessor directives begin with a # and the must start in the first column. The commonest directive to all C programs is:  +
- +
-  #include <​stdio.h>​  +
- +
-Note the use of the angle brackets (< and >) around the header'​s name. These indicate that the header file is to be looked for on the system disk which stores the rest of the C program +
-application. Some text books will show the above statement as follows:  +
- +
-  #include "​stdio.h"​  +
- +
-The double quotes indicate that the current working directory should be searched for the required header file. This will be true when you write your own header files but the standard header +
-files should always have the angle brackets around them.  +
- +
-NOTE: just to keep you on your toes - preprocessor statements, such as include, DO NOT use semi-colons as delimiters! But don't forget the # must be in the first column+
  
 +I have already mentioned that LynPlexS is a free format language and that you can layout your programs how you want to using as much white space as you like. The only exception are statements associated with the preprocessor. ​
  
-That's enough background to programs - lets get on with our first program which will start to bring together some of the ideas outlined above.+===== Continue ===== 
 +That's enough background to LynPlexS ​programs - lets get on with our first program which will start to bring together some of the ideas outlined above.
  
 ===== Links ===== ===== Links =====

lynplexs/tutorial/c03.txt · Last modified: 2014/05/25 18:39 (external edit)