Ad/2010-08-01 Concrete Syntax for a uml action Language for Foundational uml (Alf) Second Revised Submission



Download 1.74 Mb.
Page61/62
Date28.01.2017
Size1.74 Mb.
#9041
1   ...   54   55   56   57   58   59   60   61   62

Parser


The syntax grammar given below is an LL grammar, that is, a grammar designed for “top down” parsing (such as recursive descent). A lookahead of only one token is required for most of the grammar. In all other cases except one, a maximum lookahead of three tokens is required. The parsing of qualified names with template bindings, however, requires a potentially unbounded lookahead to distinguish the use of a “<” as an opening bracket of a template binding from its use as a less-than sign.

As discussed in Subclause 8.2, the parsing of a syntactic element with the form of a qualified name using the dot notation may be ambiguous. In such cases, the grammar below always parses the potentially ambiguous element as a qualified name (using the non-terminal “PotentiallyAmbiguousQualifiedName”. If such an element is later disambiguated as a feature reference, this will also generally require reparsing of the expression containing the ambiguous qualified name (e.g., a name expression becomes a property access expression and a behavior invocation becomes a feature invocation).

Finally, the LL form of the grammar given here is considerably simplified by allowing any unary expression as the left-hand side of an assignment and any primary expression as the operand of an increment or decrement expression, even though the required form for a left-hand side is actually more restrictive (see Subclause 8.8). This requires that the left-hand side of an assignment and the operand of an increment or decrement expression be checked after parsing to ensure that it has the form of a name expression, a property access expression or a sequence access expression whose primary expression is a name expression or a property access expression. Note that a similar static check needs to be performed anyway on the argument expressions for inout parameters (see Subclause 8.3.8).

NOTE. The grammar as presented below uses a slightly different EBNF notation than in the main text, with (…)? meaning optional, (…)* meaning zero or more and (..)+ meaning one or more. Terminal symbols are written in the form , were TOKEN_NAME is the name of a lexical token, as given by a lexical analyzer production above.

/***************

* NAMES *

***************/

Name = |

QualifiedName = UnqualifiedName


( ColonQualifiedNameCompletion
| DotQualifiedNameCompletion
)?

PotentiallyAmbiguousQualifiedName


= UnqualifiedName
( ColonQualifiedNameCompletion
| DotQualifiedNameCompletion /* AMBIGUOUS */
)?

ColonQualifiedName = UnqualifiedName ColonQualifiedNameCompletion

ColonQualifiedNameCompletion = ( NameBinding )+

DotQualifiedName = UnqualifiedName DotQualifiedNameCompletion

DotQualifiedNameCompletion = ( NameBinding )+

UnqualifiedName = NameBinding

NameBinding = Name ( TemplateBinding )?
/* ^ Unbounded lookahead required here */

TemplateBinding = ( NamedTemplateBinding


| PositionalTemplateBinding )

PositionalTemplateBinding = QualifiedName ( QualifiedName )*

NamedTemplateBinding = TemplateParameterSubstitution
( TemplateParameterSubstitution )*

TemplateParameterSubstitution = Name QualifiedName

/***************

* EXPRESSIONS *

***************/

Expression = UnaryExpression ExpressionCompletion

NonNameExpression = NonNameUnaryExpression ExpressionCompletion

NameToExpressionCompletion = ( NameToPrimaryExpression )?


PrimaryToExpressionCompletion

PrimaryToExpressionCompletion = PostfixExpressionCompletion


ExpressionCompletion

ExpressionCompletion = AssignmentExpressionCompletion


| ConditionalExpressionCompletion

/* PRIMARY EXPRESSIONS */

PrimaryExpression = ( NameOrPrimaryExpression
| BaseExpression
| ParenthesizedExpression )
PrimaryExpressionCompletion

BaseExpression = LiteralExpression


| ThisExpression
| SuperInvocationExpression
| InstanceCreationOrSequenceConstructionExpression
| SequenceAnyExpression

NameToPrimaryExpression = ( LinkOperationCompletion


| ClassExtentExpressionCompletion )
| SequenceConstructionExpressionCompletion
| BehaviorInvocation

PrimaryExpressionCompletion = ( Feature ( FeatureInvocation )?


| SequenceOperationOrReductionOrExpansion
| Index
)*

/* LITERAL EXPRESSIONS */

LiteralExpression =
|
|
|
|
|
|

/* NAME EXPRESSIONS */

NameOrPrimaryExpression = PotentiallyAmbiguousQualifiedName
( NameToPrimaryExpression )?

/* THIS EXPRESSIONS */

ThisExpression = ( Tuple )?

/* PARENTHESIZED EXPRESSIONS */

ParenthesizedExpression = Expression

/* PROPERTY ACCESS EXPRESSIONS */

Feature = NameBinding

/* INVOCATION EXPRESSIONS */

Tuple =
( NamedTupleExpressionList
| ( PositionalTupleExpressionList )?
)

PositionalTupleExpressionList = Expression


PositionalTupleExpressionListCompletion

PositionalTupleExpressionListCompletion


= ( Expression )*

NamedTupleExpressionList = NamedExpression ( NamedExpression )*

NamedExpression = Name Expression

BehaviorInvocation = Tuple

FeatureInvocation = Tuple

SuperInvocationExpression = ( QualifiedName )? Tuple

/* INSTANCE CREATION EXPRESSIONS */

InstanceCreationOrSequenceConstructionExpression


= QualifiedName
( SequenceConstructionExpressionCompletion
| Tuple )

/* LINK OPERATION EXPRESSIONS */

LinkOperationCompletion = LinkOperation LinkOperationTuple

LinkOperation =


|
|

LinkOperationTuple =


( Name
( Index
(
IndexedNamedExpressionListCompletion
| PrimaryToExpressionCompletion
PositionalTupleExpressionListCompletion
)
|
IndexedNamedExpressionListCompletion
)
| PositionalTupleExpressionList
)?

IndexedNamedExpressionListCompletion


= Expression
( IndexedNamedExpression )*

IndexedNamedExpression = Name ( Index )? Expression

/* CLASS EXTENT EXPRESSIONS */

ClassExtentExpressionCompletion


=

/* SEQUENCE CONSTRUCTION EXPRESSIONS */

SequenceAnyExpression =
SequenceConstructionExpressionCompletion
|

SequenceConstructionExpressionCompletion


= ( MultiplicityIndicator )?
( SequenceElements )?

MultiplicityIndicator =

SequenceElements = Expression ( Expression
| SequenceElementListCompletion )
| SequenceInitializationExpression
SequenceElementListCompletion

SequenceElementListCompletion = ( SequenceElement )* ( )?

SequenceElement = Expression
| SequenceInitializationExpression

SequenceInitializationExpression


= ( )? SequenceElements

/* SEQUENCE ACCESS EXPRESSIONS */

Index = Expression

/* SEQUENCE OPERATION, REDUCTION AND EXPANSION EXPRESSIONS */

SequenceOperationOrReductionOrExpansion
=
( QualifiedName Tuple
| ( )? QualifiedName
| Name
Expression
)

/* INCREMENT OR DECREMENT EXPRESSIONS */

PostfixExpressionCompletion = PrimaryExpressionCompletion
( PostfixOperation )?

PostfixOperation = AffixOperator

PrefixExpression = AffixOperator PrimaryExpression

AffixOperator = ( | )

/* UNARY EXPRESSIONS */

UnaryExpression = PostfixOrCastExpression


| NonPostfixNonCastUnaryExpression

PostfixOrCastExpression = NonNamePostfixOrCastExpression


| NameOrPrimaryExpression
PostfixExpressionCompletion

NonNameUnaryExpression = NonNamePostfixOrCastExpression


| NonPostfixNonCastUnaryExpression

NonNamePostfixOrCastExpression


=
( CastCompletion
| PotentiallyAmbiguousQualifiedName
( CastCompletion
| NameToExpressionCompletion
PostfixExpressionCompletion
)
| NonNameExpression
PostfixExpressionCompletion
)
| BaseExpression PostfixExpressionCompletion

NonPostfixNonCastUnaryExpression


= PrefixExpression
| NumericUnaryExpression
| BooleanNegationExpression
| BitStringComplementExpression
| IsolationExpression

BooleanNegationExpression = UnaryExpression

BitStringComplementExpression = UnaryExpression

NumericUnaryExpression = NumericUnaryOperator UnaryExpression

NumericUnaryOperator =
|

IsolationExpression = UnaryExpression

CastExpression = TypeName CastCompletion

CastCompletion = PostfixOrCastExpression


| BooleanNegationExpression
| BitStringComplementExpression
| IsolationExpression

/* ARITHMETIC EXPRESSIONS */

MultiplicativeExpression = UnaryExpression
MultiplicativeExpressionCompletion

MultiplicativeExpressionCompletion


= ( MultiplicativeOperator UnaryExpression )*

MultiplicativeOperator = | |

AdditiveExpression = UnaryExpression AdditiveExpressionCompletion

AdditiveExpressionCompletion = MultiplicativeExpressionCompletion


( AdditiveOperator MultiplicativeExpression)*

AdditiveOperator = (


| )

/* SHIFT EXPRESSIONS */

ShiftExpression = UnaryExpression ShiftExpressionCompletion

ShiftExpressionCompletion = AdditiveExpressionCompletion


( ShiftOperator AdditiveExpression )*

ShiftOperator = | |

/* RELATIONAL EXPRESSIONS */

RelationalExpression = UnaryExpression


RelationalExpressionCompletion

RelationalExpressionCompletion


= ShiftExpressionCompletion
( RelationalOperator ShiftExpression )?

RelationalOperator = | | |

/* CLASSIFICATION EXPRESSIONS */

ClassificationExpression = UnaryExpression


ClassificationExpressionCompletion

ClassificationExpressionCompletion


= RelationalExpressionCompletion
( ClassificationOperator QualifiedName )?

ClassificationOperator = |



Download 1.74 Mb.

Share with your friends:
1   ...   54   55   56   57   58   59   60   61   62




The database is protected by copyright ©ininet.org 2024
send message

    Main page