|
Nachfolgend ist die Definition der
User Language-Syntax in BNF(Backus-Naur-Form)-ähnlicher Notation aufgelistet. Kommentare sind dabei durch
/* und
*/ begrenzt. Der Doppelpunkt
(: ) entspricht einem Zuweisungs-Operator und ist folglich zu lesen als "besteht aus". Das Zeichen
| kennzeichnet Alternativen. Identifier werden durch das Symbol
IDENT , Konstanten durch
NUMBER (numerisch),
SQSTR (Zeichen) und
DQSTR (Zeichenkette) gekennzeichnet. Das Symbol
EOLN definiert das Zeilenende. Die Terminalzeichen-Sequenzen (also die reservierten Worte und Operatoren) sind fett gedruckt dargestellt.
/* User Language Source Code Syntax */
/* Program definition */
program
: progdefs
;
progdefs
: progdefs progdef
|
;
progdef
: preproccmd
| typedef
| storageclass vardef
| storageclass fctdef
;
/* Preprocessor command */
preproccmd
: #include DQSTR EOLN
| #define IDENT optexpr EOLN
| #undef IDENT EOLN
| #if expression EOLN
| #ifdef IDENT EOLN
| #ifndef IDENT EOLN
| #else EOLN
| #endif EOLN
| #bnf { syntaxdef }
| #pragma pragmaval
;
pragmaval
: ULCALLERSTD
| ULCALLERCAP
| ULCALLERSCM
| ULCALLERLAY
| ULCALLERGED
| ULCALLERAR
| ULCALLERCAM
| ULCALLERCV
| ULCALLERICD
| ULCALLERCED
| ULCALLERNOUNDO
;
/* Type definition */
typedef
: typedef declaration
;
/* Variable definition */
vardef
: typespec initdecs ;
;
/* Function definition */
fctdef
: fcttype IDENT ( fctpars ) fctpardecs { cmditems } ;
fcttype
: typespec
| void
|
;
fctpars
: fctpardefs
|
;
fctpardefs
: fctpardefs , IDENT
| IDENT
;
fctpardecs
: fctpardecs vardef
|
;
/* Storage class */
storageclass
| static
| structdef
;
/* Type specification */
typespec
: int
| double
| char
| string
| index IDENT
| structdef
| IDENT
;
/* Struct definition */
structdef
: struct IDENT
| struct IDENT { members }
| struct { members }
;
members
: members declaration
| declaration
;
/* Declaration */
declaration
: typespec decs ;
;
decs
: decs , declarator
| declarator
;
/* Initialized declarator list */
initdecs
: initdecs , initdec
| initdec
|
;
initdec
: declarator
| declarator = initializer
;
/* Declarator */
declarator
: IDENT
| declarator [ ]
;
/* Initializer */
initializer
: assignment
| { initializers }
;
initializers
: initializers , initializer
| initializer
;
/* Command block */
cmdblock
: { cmditems }
| cmditem
;
/* Command list */
cmditems
: cmditems cmditem
|
;
/* Command item */
cmditem
: preproccmd
| typedef
| vardef
| ifcmd
| switchcmd
| forcmd
| whilecmd
| docmd
| forallcmd
| return optexpr ;
| break ;
| continue ;
| optexpr ;
;
/* If control structure */
ifcmd
: if ( expression ) cmdblock elsecmd
;
elsecmd
: else cmdblock
|
;
/* Switch control structure */
switchcmd
: switch ( expression ) { caseblocks }
;
caseblocks
: caseblocks caseblock
|
;
caseblock
: cases cmditems
;
cases
: cases case
| case
;
case
: case expression :
| default :
;
/* For control structure */
forcmd
: for ( optexpr ; optexpr ; optexpr ) cmdblock
;
/* While control structure */
whilecmd
: while ( expression ) cmdblock
;
/* Do control structure */
docmd
: do cmdblock while ( expression ) ;
;
/* Forall control structure */
forallcmd
: forall ( IDENT forallof forallwhere ) cmdblock
;
forallof
: of IDENT
|
;
forallwhere
: where expression
|
;
/* Expression */
optexpr
: expression
|
;
expression
: expression , assignment
| assignment
;
/* Assignment */
assignment
: unary = assignment
| unary |= assignment
| unary ^= assignment
| unary &= assignment
| unary <<= assignment
| unary >>= assignment
| unary += assignment
| unary -= assignment
| unary *= assignment
| unary /= assignment
| unary %= assignment
| conditional
;
/* Conditional evaluation */
conditional
: log_or
| log_or ? conditional : conditional
;
/* Logical OR */
log_or
: log_and
| log_and || log_or
;
/* Logical AND */
log_and
: bit_or
| bit_or && log_and
;
/* Bit OR */
bit_or
: bit_xor
| bit_or | bit_xor
;
/* Bit Exclusive OR */
bit_xor
: bit_and
| bit_xor ^ bit_and
;
/* Bit AND */
bit_and
: equality
| bit_and & equality
;
/* Equivalence comparison */
equality
: comparison
| equality == comparison
| equality != comparison
;
/* Comparison */
comparison
: shift
| comparison < shift
| comparison <= shift
| comparison > shift
| comparison >= shift
;
/* Shift operations */
shift
: sum
| shift << sum
| shift >> sum
;
/* Addition and substraction */
sum
: product
| sum + product
| sum - product
;
/* Multiplication and division */
product
: unary
| product * unary
| product / unary
| product % unary
;
/* Unary operators */
unary
: primary
| primary ++
| primary --
| - unary
| ! unary
| ~ unary
| ++ unary
| -- unary
;
/* Primary operators */
primary
: IDENT
| NUMBER
| SQSTR
| DQSTR
| ( expression )
| IDENT ( optexpr )
| primary [ expression ]
| primary . IDENT
;
/* BNF Precompiler syntax definition */
syntaxdef
: commentdef grammar
;
commentdef
: COMMENT ( commentdel commentend ) ;
|
;
commentend
: , commentdel
|
;
commentdel
: SQSTR
| DQSTR
;
grammar
: grammar rule
| rule
;
rule
: IDENT : forms ;
| IDENT : forms | ;
;
forms
: form | forms
| form
;
form
: form symbol action
| symbol action
;
symbol
: IDENT
| SQSTR
| DQSTR
| IDENT
| NUMBER
| SQSTR
| DQSTR
| EOLN
| EOF
| EOFINC
| UNKNOWN
;
action
| ( IDENT ( NUMBER ) )
| ( IDENT )
|
;
/* BNF syntax description file end */
Syntaxdefinition © 1985-2024 Oliver Bartels F+E • Aktualisiert: 11. October 2010, 10:48 [UTC]
|