Yacc Form of grammar AQL.grm


Copyright © 2012 by Hassan Aït-Kaci; All Rights Reserved.

This yacc grammar was generated on Fri Oct 19 10:29:57 PDT 2012 from the annotated Jacc grammar file AQL.grm.


Statements_opt
	: /* empty */
	| Statements_opt Statement 
	;

Statement
	: '#' Pragma PragmaArgument_opt EOS 
	| DefinitionStatement 
	| '?' Expression EOS 
	| Expression EOS 
	| error EOS 
	| ';' 
	;

DefinitionStatement
	: 'define' DefinitionKind EOS 
	| StructureOrClassDeclaration 
	;

DefinitionKind
	: 'operator' Operator SPECIFIER INT 
	| 'signature' Operator Typing 
	| 'type' 'alias' ID TypeParameters_opt '=' Type 
	| 'type' 'name' ID TypeParameters_opt '=' Type 
	| 'value' Definition 
	| Definition 
	;

StructureOrClassDeclaration
	: 'structure' ID TypeParameters_opt '{' NamedTupleTypeComponents '}' 
	| 'class' ID TypeParameters_opt Interface Implementation_opt 
	;

Pragma
	: ID 
	;

PragmaArgument_opt
	: /* empty */
	| STRING 
	;

EOS
	: ';' 
	;

Typing_opt
	: /* empty */
	| Typing 
	;

Typing
	: ':' Type 
	;

Type_opt
	: /* empty */
	| Type 
	;

Type
	: TypeConstant 
	| FunctionType 
	| TupleType 
	| ArrayType 
	| CollectionType 
	| IntRangeType 
	| RealRangeType 
	| TypeTerm 
	| '(' Type_opt ')' 
	| '[' PrimitiveType ']' 
	| 'forall' TypeParameters '.' Type 
	;

TypeConstant
	: PrimitiveType 
	| 'string' 
	;

PrimitiveType
	: 'void' 
	| 'int' 
	| 'boolean' 
	| 'char' 
	| 'real' 
	;

FunctionType
	: Type '->' Type 
	| '(' Types_opt ')' '->' Type 
	;

TupleType
	: '<' TupleTypeComponents '>' 
	;

TupleTypeComponents
	: Types_opt 
	| NamedTupleTypeComponents 
	;

NamedTupleTypeComponents
	: NamedTupleTypeComponent 
	| NamedTupleTypeComponents ',' NamedTupleTypeComponent 
	;

NamedTupleTypeComponent
	: ID Typing 
	;

ArrayType
	: Type '[' IndexType ']' 
	;

IndexType
	: IntType_opt 
	| MapIndexType 
	;

IntType_opt
	: /* empty */
	| 'int' 
	;

MapIndexType
	: SetType 
	| IntRangeType 
	;

CollectionType
	: SetType 
	| NonSetKind '{' Type_opt '}' 
	;

CollectionKind
	: SetKind 
	| NonSetKind 
	;

SetKind
	: 'set' 
	;

NonSetKind
	: 'bag' 
	| 'list' 
	;

SetKind_opt
	: /* empty */
	| SetKind 
	;

SetType
	: SetKind_opt '{' Type_opt '}' 
	;

IntRangeType
	: 'int' '..' 'int' 
	;

RealRangeType
	: 'real' '..' 'real' 
	;

TypeTerm
	: ID 
	| ID '(' Types ')' 
	;

Types_opt
	: /* empty */
	| Types 
	;

Types
	: Type 
	| Types ',' Type 
	;

TypeParameters_opt
	: /* empty */
	| '(' TypeParameters ')' 
	;

TypeParameters
	: ID 
	| TypeParameters ',' ID 
	;

Interface
	: '{' MemberDeclarations_opt '}' 
	;

MemberDeclarations_opt
	: /* empty */
	| MemberDeclarations_opt MemberDeclaration 
	;

MemberDeclaration
	: ID Typing Initialization_opt ';' 
	| 'method' Operator Typing ';' 
	;

Initialization_opt
	: /* empty */
	| '=' Expression 
	;

Implementation_opt
	: /* empty */
	| '{' Definitions_opt '}' 
	;

Definitions_opt
	: /* empty */
	| Definitions_opt Definition ';' 
	;

Definition
	: Operator FunctionParameters_opt Typing_opt '=' Expression 
	;

FunctionParameters_opt
	: /* empty */
	| FunctionParameters 
	;

FunctionParameters
	: '(' Parameters_opt ')' 
	;

Parameters_opt
	: /* empty */
	| Parameters 
	;

Parameters
	: Parameter 
	| Parameters ',' Parameter 
	;

Parameter
	: ID Typing_opt 
	;

Expression_opt
	: /* empty */
	| Expression 
	;

Expression
	: UntypedExpression Typing_opt 
	| Allocation 
	| Expression 'as' Type 
	| '$' Expression 
	| '(' Expression_opt ')' 
	;

Allocation
	: 'new' Type Dimensions_opt 
	| 'new' Type Dimensions '=' Expression 
	;

Dimensions_opt
	: /* empty */
	| Dimensions 
	;

Dimensions
	: Dimension 
	| Dimensions Dimension 
	;

Dimension
	: '[' UntypedExpression ']' 
	;

UntypedExpression
	: Literal 
	| CollectionKind '{' Expressions_opt '}' 
	| TupleExpression 
	| Expression '!' Expression 
	| '#[' ArrayExtension ']#' 
	| ArraySlotExpression 
	| OperatorExpression 
	| 'function' FunctionParameters Expression 
	| Expression Arguments 
	| 'return' Expression_opt 
	| 'if' UntypedExpression 'then' Expression 'else' Expression 
	| 'while' UntypedExpression 'do' Expression 
	| 'let' Locals 'in' Expression 
	| Location '=' Expression 
	| Expression '.' Member 
	| Sequence 
	| '(' UntypedExpression ')' 
	| Comprehension 
	| 'foreach' '(' Qualifiers_opt ')' Expression_opt 
	| 'hom' '(' Expression ',' Expression ',' Expression ',' Expression ')' 
	;

Literal
	: INT 
	| CHAR 
	| REAL 
	| STRING 
	| 'true' 
	| 'false' 
	| 'null' 
	;

TupleExpression
	: '<' TupleComponents '>' 
	| TupleProjection 
	;

TupleComponents
	: Expressions_opt 
	| NamedTupleComponents 
	;

NamedTupleComponents
	: NamedTupleComponent 
	| NamedTupleComponents ',' NamedTupleComponent 
	;

NamedTupleComponent
	: ID ':=' Expression 
	;

TupleProjection
	: UntypedExpression '@' TupleSelector 
	;

TupleSelector
	: INT 
	| ID 
	;

ArrayExtension
	: Expressions 
	| IndexedExpressions 
	;

IndexedExpressions
	: IndexedExpression 
	| IndexedExpressions ',' IndexedExpression 
	;

IndexedExpression
	: UntypedExpression ':' Expression 
	;

ArraySlotExpression
	: Expression '[' Expression ']' 
	;

OperatorExpression
	: Operator 
	| OPERATOR_ Expression 
	| Expression _OPERATOR 
	| Expression _OPERATOR_ Expression 
	;

Arguments
	: '(' Expressions_opt ')' 
	;

Expressions_opt
	: /* empty */
	| Expressions 
	;

Expressions
	: Expression 
	| Expressions ',' Expression 
	;

Locals
	: Local ';' 
	| Locals Local ';' 
	;

Local
	: Parameter Initialization_opt 
	;

Location
	: ID 
	| TupleProjection 
	| ArraySlotExpression 
	| Expression '.' ID 
	;

Member
	: ID 
	| Operator Arguments 
	;

Sequence
	: '{' ExpressionSequence_opt '}' 
	;

ExpressionSequence_opt
	: /* empty */
	| Expression ';' 
	| ExpressionSequence_opt Expression ';' 
	;

Comprehension
	: Monoid '{' Expression '|' Qualifiers_opt '}' 
	;

Monoid
	: '[' Expression ',' Expression ']' InPlace_opt 
	;

InPlace_opt
	: /* empty */
	| '<' 
	| '>' 
	;

Qualifiers_opt
	: /* empty */
	| Qualifiers 
	;

Qualifiers
	: Qualifier 
	| Qualifiers ',' Qualifier 
	;

Qualifier
	: Expression 
	| Expression '<-' Expression 
	;

Operator
	: OPERATOR_ 
	| _OPERATOR_ 
	| _OPERATOR 
	| ID 
	;


Copyright © 2012 by Hassan Aït-Kaci; All Rights Reserved.