Imp
Copyright (c) 1998-1999 Redshift Software Inc. All Rights Reserved

7

EBNF Grammar

 

7.1
Miscellaneous
  tPeriod .
  tAssign <-
  tMap ->
  tAlpha any alphabetic character
  tUnder _
  tDigit any numeric digit
  tWhitespace tab,return,space,etc...

7.2
Grouping tokens
  tOpenParen (
  tCloseParen )
  tOpenBrace {
  tCloseBrace }
  tOpenBracket [
  tCloseBracket ]

7.3
Delimitor tokens
  tComma ,
  tSemicolon ;
  tColon :

7.4
Operator tokens
  tPlus +
  tMinus -
  tMultiply *
  tDivide /
  tModulus %
  tEqual =
  tNotEqual <>
  tLessThan <
  tLessThanEqual <=
  tGreaterThan >
  tGreaterThanEqual >=
  tNegation ~
  tReference &
  tDereference @
  tUserOperator tUserOperators [ tUserOperators ]
  tUserOperators ~ | ` | ! | $ | % | ^ | * | < | > | - | + | | | \ | /

7.5
Literals
  Literal lNumber | lString | lCharacter | lBase

7.5.1
Decimal numbers
  lNumber [ tMinus ] tDigit+ [ tPeriod tDigit+ ]

7.5.2
Array of characters
  lString " { lEscapedCharacter | >"< }* "

7.5.3
Single character
  lCharacter ' { lEscapedCharacter | >'< } '

7.5.4
Escaped character
  lEscapedCharacter \ { " | ' | \ | { tIdentifier \ } }

7.5.5
Specific base number
  lBase tBase tOpenParen lNumber tComma [ tMinus ] { tDigit | tAlpha }+ [ tPeriod { tDigit | tAlpha }+ ] tCloseParen

7.6
Reserved words
  tIf if
  tImport import
  tExport export
  tLoop loop
  tCase case
  tConditional on
  tDisjunction and
  tJunction or
  tNumber number
  tType type
  tBit bit
  tRoutine routine
  tEnum enum
  tRecord record
  tCharacter character
  tElse else
  tCoerce coerce
  tOperator operator
  tSize size
  tCast cast
  tAssembly asm
  tConstant constant
  tBase base
  tVolatile volatile
  tTrue true
  tFalse false
  tLogical logical
  tPrecedence precedence
  tRegister register
  tGuard guard
  tFail fail
  tRecover recover
  tHandle handle

7.7
Identifiers
  tSimpleIdentifier { tAlpha | tUnder } { tAlpha | tDigit | tUnder }*
  tQualifiedIdentifier tSimpleIdentifier { . tSimpleIdentifier }+
  tIdentifier tSimpleIdentifier { . tSimpleIdentifier }*
  Identifier tIdentifier
  SimpleIdentifier tSimpleIdentifier
  QualifiedIdentifier tQualifiedIdentifier

7.8
Statements
  Statement LoopStatement | CaseStatement | IfStatement | AssignmentStatement | RoutineStatement | AssemblyStatement | DeclarationStatement | BlockStatement | GuardStatement | FailStatement | RecoverStatement | HandleStatement
  LoopStatement tLoop [ VariableDeclaration ] { tOpenBrace { [ Statement | EmptyStatement ] [ ConditionalStatement ] }* tCloseBrace } | { [ Statement | EmptyStatement ] [ ConditionalStatement ] }
  CaseStatement tCase [ VariableDeclaration ] Block(CaseConditionalStatement) tOpenBrace { ConditionalStatement [ Statement | EmptyStatement ] }* tCloseBrace
  IfStatement tIf ConditionalStatement [ { tElse ConditionalStatement }* tElse { Statement | EmptyStatement } ]
  AssignmentStatement { Expression { tComma Expression }+ tAssign Expression { tComma Expression }+ tSemicolon } | { Expression { tComma Expression }+ Operator tWhitespace tAssign Expression { tComma Expression }+ tSemicolon }
  RoutineStatement Identifier tOpenParen [ Expression { tComma Expression }+ ] tCloseParen tSemicolon
  AssemblyStatement tAssembly tColon tOpenBrace { { tOpenBrace Expression tCloseBrace } | tCloseBrace~ }* tCloseBrace
  DeclarationStatement Declaration tSemicolon
  BlockStatement tOpenBrace { Statement | EmptyStatement }* tCloseBrace
  GuardStatement tGuard VariableDeclaration tOpenBrace { Statement ConditionalStatement }* tCloseBrace
  FailStatement tFail tOpenParen Expression [ tComma Expression ] tCloseParen tSemicolon
  RecoverStatement tRecover tOpenParen Expression [ tComma Expression ] tCloseParen tSemicolon
  HandleStatement tHandle ParameterDefinition BlockStatement
  ConditionalStatement tConditional tOpenParen Expression tCloseParen { Statement | EmptyStatement } { { tJunction | tDisjunction } Parenthetical(Expression) { Statement | EmptyStatement } }*
  EmptyStatement tSemicolon

7.9
Declarations
  Declaration ScopeDeclaration | RoutineDeclaration | ImportDeclaration | TypeDeclaration | VariableDeclaration | PrecedenceDeclaration
  IdentifierDeclaration Identifier { tComma Identifier }+ tColon [ ScopeSpecifier ] [ AccessSpecifier ] [ StorageSpecifier ]
  ScopeSpecifier tExport
  AccessSpecifier tConstant
  StorageSpecifier tVolatile
  ScopeDeclaration IdentifierDeclaration tOpenBrace Block(DeclarationStatement)
  VariableDeclaration IdentifierDeclaration TypeDefinition ! [ tAssign Expression { tComma Expression }* ]
  TypeDeclaration IdentifierDeclaration tType ! TypeDefinition ! [ tOpenBrace { OperatorDefinition }* tCloseParen ]
  OperatorDefinition { Operator | tCoerce } tColon tOperator ! ParameterDefinition ! ResultDefinition ! [ tPrecedence tAssign Identifier ] ! BlockStatement !
  RoutineDeclaration IdentifierDeclaration RoutineType ! [ BlockStatement ]
  ImportDeclaration IdentifierDeclaration tImport
  PrecedenceDeclaration IdentifierDeclaration tPrecedence ! [ { tLessThan | tGreaterThan | tEqual } Identifier ]
  TypeDefinition [ GroupType ] { RoutineType | RecordType | EnumType | BaseType | InternalType | Identifier }
  RoutineType tRoutine ParameterDefinition [ ResultDefinition ]
  ParameterDefinition tOpenParen [ VariableDeclaration { tSemicolon VariableDeclaration }* ] tCloseParen
  ResultDefinition ParameterDefinition
  RecordType tRecord tOpenBrace { DeclarationStatement }* tCloseBrace
  EnumType tEnum TypeDefinition tOpenParen Identifier { tSemicolon Identifier }* tCloseParen tMap tOpenParen [ Expression ] { tSemicolon [ Expression ] }* tCloseParen
  InternalType NumberType | CharacterType | LogicalType
  BaseType BitType | RegisterType
  NumberType tNumber
  CharacterType tCharacter
  LogicalType tLogical
  BitType tBit
  RegisterType tRegister
  GroupType { tReference | ArrayType }+
  ArrayType tOpenBracket [ [ Expression ] { tComma [ Expression ] }* ] tCloseBracket

7.10
Expressions
  Expression [ Operator ] SimpleExpression { Operator SimpleExpression }*
  SimpleExpression CoerceExpression | CastExpression | SizeExpression | RoutineExpression | Identifier | Literal | tOpenParen Expression tCloseParen
  RoutineExpression Identifier tOpenParen [ Expression { tComma Expression }* ] tCloseParen
  CoerceExpression tCoerce tOpenParen Expression { tComma Expression }* tCloseParen
  CastExpression tCast tOpenParen Expression tCloseParen
  SizeExpression tSize tOpenParen Expression tCloseParen

7.11
Operators
  Operator RelationalOperator | ArithmeticOperator | AccessOperator
  ArithmeticOperator tPlus | tMinus | tMultiply | tDivide | tModulus | tUserOperator
  RelationalOperator tNotEqual | tLessThanEqual | tGreaterThanEqual | tEqual | tLessThan | tGreaterThan | tNegation
  AccessOperator { tReference | tDereference | { tOpenBracket Expression { tComma Expression }* tCloseBracket } }+

7.12
Top Level
  File [ ws ] { DeclarationStatement ! }* [ ws ]

7.13
Preprocessor
 

7.13.1
Preprocessor Tokens & Macros
  tPreprocess #
  TPreprocess #
  tRest rest
  tMacro macro
  tPipe |
  pStream { pPreprocess | TPreprocess }*
  pPreprocess pEscape | pStatement | pExpression | pInsert | pComment
  pEscape tPreprocess !
  pExpression tPreprocess $ Expression $ tPreprocess
  pInsert tPreprocess lString tPreprocess
  pStatement tPreprocess ws pSingleStatement* ws tPreprocess
  pSingleStatement pLoopStatement | pIfStatement | pBlockStatement | pStreamStatement | pAssignmentStatement | pMacroInvocationStatement | pMacroDefinitionStatement | pExpression | pLiteralStatement
  pLiteralStatement tPreprocess tPipe pStream tPipe tPreprocess
  pLoopStatement tLoop tOpenBrace { pLoopConditionalStatement }* tCloseBrace
  pLoopConditionalStatement [ pStatement ] [ pConditionalStatement ]
  pIfStatement tIf pConditionalStatement [ { tElse pConditionalStatement }* tElse { pStatement } ]
  pConditionalStatement tConditional tOpenParen Expression tCloseParen pStatement { { tJunction | tDisjunction } tOpenParen Expression tCloseParen pStatement }*
  pBlockStatement tOpenBrace { pStatement }* tCloseBrace
  pStreamStatement ws tPreprocess pStream tPreprocess ws
  pAssignmentStatement SimpleIdentifier { tComma SimpleIdentifier }* tAssign Expression { tComma Expression }* tSemicolon | SimpleIdentifier { tComma SimpleIdentifier }* Operator ws tAssign Expression { tComma Expression }* tSemicolon
  pMacroInvocationStatement SimpleIdentifier tOpenParen Expression { tComma Expression }* tCloseParen
  pMacroDefinitionStatement SimpleIdentifier tColon tMacro tOpenParen SimpleIdentifier { tSemicolon SimpleIdentifier }* [ tSemicolon tRest ] tCloseParen pStatement

7.13.2
Comments
  pComment

tPreprocess { tPreprocess >Newline<* | { >}<* } tPreprocess | ( >)<* ) tPreprocess | [ >]<* ] tPreprocess | < ><<* > tPreprocess | any printing char >same printing char<* tPreprocess }


 
Reference
 
1 Lexical
2 Programs
3 Declarations
4 Expressions
5 Statements
6 Preprocessor
7 EBNF