Difference between revisions of "PLC Project"

From Marek Běhálek Wiki
Jump to navigation Jump to search
Line 3: Line 3:
 
=== Program's formatting ===
 
=== Program's formatting ===
  
The program consists of a sequence of commands. Commands are written with free formating. Comments, spaces, tabs and line breaks serve only as delimiters and do not affect the meaning of the program. '''Commnets''' are bounded by two slashes and the end of the line. Keywords are reserved. Identifiers and keywords are case sensitive.
+
The program consists of a sequence of commands. Commands are written with free formatting. Comments, spaces, tabs, and line breaks serve only as delimiters and do not affect the meaning of the program. '''Comments''' are bounded by two slashes and the end of the line. Keywords are reserved. Identifiers and keywords are case sensitive.
  
 
=== Variables ===
 
=== Variables ===
  
Variable's identifiers are composed from letters and digits and it must start with a letter. Each variable must be declared before it is used. Repeated declaration of a variable with the same name is an error. Variables must have one of the following types: <code>int</code>, <code>float</code>, <code>boolean</code> or <code>String</code>. After the declaration, variables have initial values: <code>0</code>, <code>0.0</code>, <code>""</code> respectivelly <code>False</code>.
+
Variable's identifiers are composed from letters and digits, and it must start with a letter. Each variable must be declared before it is used. Repeated declaration of a variable with the same name is an error. Variables must have one of the following types: <code>int</code>, <code>float</code>, <code>bool</code> or <code>String</code>. After the variables are declared, they have initial values: <code>0</code>, <code>0.0</code>, <code>""</code> respectively <code>False</code>.
  
 
=== Statements ===
 
=== Statements ===
Line 13: Line 13:
 
Following statements are defined:
 
Following statements are defined:
  
* <code>;</code> - empty command;
+
* <code>;</code> - empty command.
* <code>type variable, variable, ... ;</code> - declaration of variables, type can be one of: <code>int</code>, <code>float</code>, <code>boolean</code>, <code>String</code>
+
* <code>type variable, variable, ... ;</code> - declaration of variables, type can be one of: <code>int</code>, <code>float</code>, <code>bool</code>, <code>String</code>
 
* <code>expression ;</code> - it evaluates given expression, the resulting value of the expression is ignored. Note, there can be some side effects like an assignment to a variable.
 
* <code>expression ;</code> - it evaluates given expression, the resulting value of the expression is ignored. Note, there can be some side effects like an assignment to a variable.
* <code>read variable, variable, ... ;</code> - it reads values ​​from standard input and then these values are assigned to coresponding variables. Each readed value is on a separate line and it is verified, that have an appropriate type.
+
* <code>read variable, variable, ... ;</code> - it reads values ​​from standard input and then these values are assigned to corresponding variables. Each of these input values is on a separate line and it is verified, that have an appropriate type.
 
* <code>write expression, expression, ... ;</code> - it writes values of expressions to standard output. The <code>"\n"</code> character is written after the value of the last expression.
 
* <code>write expression, expression, ... ;</code> - it writes values of expressions to standard output. The <code>"\n"</code> character is written after the value of the last expression.
 
* Command block - block starts {and ends}
 
* Command block - block starts {and ends}

Revision as of 12:55, 14 March 2022

Language Specification

Program's formatting

The program consists of a sequence of commands. Commands are written with free formatting. Comments, spaces, tabs, and line breaks serve only as delimiters and do not affect the meaning of the program. Comments are bounded by two slashes and the end of the line. Keywords are reserved. Identifiers and keywords are case sensitive.

Variables

Variable's identifiers are composed from letters and digits, and it must start with a letter. Each variable must be declared before it is used. Repeated declaration of a variable with the same name is an error. Variables must have one of the following types: int, float, bool or String. After the variables are declared, they have initial values: 0, 0.0, "" respectively False.

Statements

Following statements are defined:

  • ; - empty command.
  • type variable, variable, ... ; - declaration of variables, type can be one of: int, float, bool, String
  • expression ; - it evaluates given expression, the resulting value of the expression is ignored. Note, there can be some side effects like an assignment to a variable.
  • read variable, variable, ... ; - it reads values ​​from standard input and then these values are assigned to corresponding variables. Each of these input values is on a separate line and it is verified, that have an appropriate type.
  • write expression, expression, ... ; - it writes values of expressions to standard output. The "\n" character is written after the value of the last expression.
  • Command block - block starts {and ends}
  • if (condition) statements else statements

Conditional statement, condition must be a Boolean expression. Commands indicate a sequence of commands separated by a semicolon. The else part is optional.

  • for (expression_1; condition; expression_2) statements

Cycle statement, condition must be a Boolean expression. The first expression is executed before the start of the cycle, the second after each step of the cycle.

Expression