Lexical Rules for ASCII Text (.awl) Files

Syntax Description

[…] Means that the contents of the brackets is optional
{…} Means that the contents can be written zero or several times
(…) Terms in round brackets have highest priority; normally they define one expression
.. | .. Either the left or right term is valid
keywords Keywords are in capital letters. They are not case sensitive;lower case, capital letters, or a mix of both can be used.
.. Indicates a range, B..Z means all letter characters from B to Z
CR Indicates a carriage return (end-of-line character)

SIMATIC S7-200 Lexical Rules

Letters and Digits  
letter A | B | .. | Z | a | b | .. |z
digit 0 | 1 | .. | 9
bit digit 0|1| .. |7
binary digit 0 | 1 | _
hex digit digit | A | .. | F | a | .. | f | _
character letter | ASCII 128 | .. | ASCII 255 | _
first identifier character character | space
other identifier character character | digit | space

Identifiers and Variables

Identifier First identifier character { other identifier character }
Global Variables (Global Symbols) [ “ ] identifier [ “ ]

Note:

At entry, the user does not have to type the leading and trailing double quotation marks. They are applied automatically if the global variable is already defined. At entry, all consecutive spaces are converted to a single space and then each space is automatically replaced with one underscore. Finally, consecutive multiple underscores are automatically reduced into one underscore. A global variable or global symbol must be at least 1 character long and can not exceed 23 characters from the character set.

When there is a local and global variable with the same name and no prefix, the local variable takes precedence unless the user explicitly types the double quotation marks.

Local Variables (Local Symbols) [ # ] identifier

Note:

At entry, the user does not have to type the pound character. It is automatically applied if the local variable is already defined. At entry, all consecutive spaces are converted to a single space and then each space is automatically replaced with one underscore. Finally, consecutive multiple underscores are automatically reduced into one underscore. A local variable or local symbol must be at least 1 character long and can not exceed 23 characters from the character set.

When there is a local and global variable with the same name and no prefix, the local variable takes precedence unless the user explicitly types the double quotation marks.

Constants

Boolean constant TRUE | FALSE | ON | OFF Note: Case insensitive
constant descriptor B# | BYTE# | W# | WORD# | DW# | DWORD# Note: Case insensitive
unsigned integer [constant descriptor]digit {digit}
number digit {digit}
signed number [ + | - ] number
signed integer [constant descriptor]signed number
binary integer [constant descriptor]2# binary digit { binary digit }
hex integer [constant descriptor]16# hex digit { hex digit }
exponent ( E | e ) signed number
real constant signed number . {exponent}
real constant number {exponent}
real constant signed number . number {exponent}
printable character ASCII 32 | .. | ASCII 255 excluding DEL and ’
two character hex hex digit hex digit
character representation printable character | $$ | $ | $L | $l | $N | $n | $P | $p | $R | $r | $T | $t | $’

$two character hex

Note: The leading $ sign is a control character

(Also known as an escape code)

  Escape Code Interpretation
  $$ Single dollar sign
  $’ Single quotation mark character
  $L or $l A line feed character
  $N or $n A new line character
  $P or $p Form feed, new page
  $R or $r Carriage return character
  $T ot $t Tab character
ASCII constant [constant descriptor]‘character representation’
string constant {character representation}
constant Boolean constant | binary digit | unsigned integer | signed integer | binary integer | hex integer | real constant | ASCII constant

Note:

An ASCII constant must match the Constant Descriptor, i.e., B#a is valid but B#ab is not. B# expects one and only one character, W# expects exactly two characters, and DW# expects exactly four characters. Any other count of characters results in an error.

Program Comments

comment characters printable character CR
comment // { comment characters } CR

Addressing

discrete input I | E Note: Case insensitive
discrete output Q | A Note: Case insensitive
analog input AI | AE Note: Case insensitive
analog output AQ | AA Note: Case insensitive
db memory DB Note: Case insensitive
variable memory V Note: Case insensitive
flag memory M Note: Case insensitive
system memory SM Note: Case insensitive
stage memory S Note: Case insensitive
accumulator AC Note: Case insensitive
timer T Note: Case insensitive
counter C | Z Note: Case insensitive
high speed counter HC | HZ Note: Case insensitive
data block DB Note: Case insensitive
local memory L Note: Case insensitive
bit point unsigned number . 0 | 1 | … | 7
size prefix B | W | D Note: Case insensitive
direct prefix discrete input | discrete output | variable memory | flag memory | system memory | stage memory
peripheral prefix analog input | analog output
timer counter prefix timer | counter
bit address direct prefix [X] bit point
byte word dword address direct prefix size prefix unsigned number
peripheral address peripheral prefix [W] unsigned number
timer counter address timer counter prefix ((X unsigned number) | unsigned number)
high speed counter address high speed counter unsigned number
accumulator address accumulator [size prefix] unsigned number
db number DB unsigned number
db address [db number .] data block ([X] bit point) | (size prefix unsigned number)
direct address bit address | byte word dword address | peripheral address |

timer counter address | high speed counter address | accumulator address |

db address

indirect address * ((accumulator [ D| d ]) | (variable memory D | d ) | (local memory D | d) | ([db number .] data block D | d)) unsigned number
address of & (variable memory | discrete input | discrete output | timer | counter | flag memory | system memory ([db number.] data block) size prefix unsigned number

Program Structure

Note:

Keywords are case insensitive unless otherwise noted.

block title { white space } (TITLE = comment characters CR | comment)
block comment {comment}
network title { white space } (TITLE = comment characters CR | comment)
network comment {comment}
line comment {comment}
code comment {comment}
network number { space | unsigned number }
operand { white space } global variable | local variable | constant | direct address | indirect address | address of
instruction mnemonic (letter | digit | _ ) { letter | digit | _ }
instruction instruction mnemonic [(white space) { white space } operand {(,| white space) { white space } operand}] ; code comment
statement list {instruction | line comment}
network NETWORK network number (CR | [network title] [network comment]) statement list
ob number OB unsigned number
organization block ORGANIZATION_BLOCK (ob number) (CR | [block title] [block comment])

ob declarations BEGIN [network] END_ORGANIZATION_BLOCK CR

sbr number SBR unsigned number
subroutine block SUBROUTINE_BLOCK (sbr number) (CR [block title] [block comment])

sbr declarations BEGIN [network] END_SUBROUTINE_BLOCK CR

int number INT unsigned_number
interrupt block INTERRUPT_BLOCK (int number) (CR [block title] [block comment]) int declarations BEGIN [network] END_INTERRUPT_BLOCK CR

Local Variable Declaration

ob declaration [var declaration]
int declaration [var declaration]
sbr declaration [io var declaration] ob declarations
io var declaration [var input declaration] [var in out declaration] [var output declaration]
var input declaration VAR_INPUT CR

decl_list

END_VAR CR

var output declaration VAR_OUTPUT CR
  decl_list

END_VAR CR

var in out declaration VAR_IN_OUT CR

decl_list

END_VAR CR

var declaration VAR CR

decl_list

END_VAR CR

decl list {identifier : complex type }; {comment}
type base type | user type | string type
complex type base type | array type | struct type | user type | string type
init value constant | integer ( init value ) | init value , init value
base type BOOL | BYTE | WORD | DWORD | CHAR | INT | DINT | REAL |

See Also:

ASCII file keyword List