//Based on Dr. Palsberg's MiniX10 grammar at UCLA //Using the JavaScript_Compiler project as a template ometa MiniX10Parser <: Parser { File = TopLevelDeclaration* spaces end, TopLevelDeclaration = MainClass | ClassDeclaration, MainClass = "public" "class" Identifier "{" "public" "static" "void" "main" "(" "String" "[" "]" Identifier ")" "{" Statement "}" "}", ClassDeclaration = "class" Identifier "{" ClassMember* "}", ClassMember = MethodDeclaration | ConstantDeclaration | UpdatableFieldDeclaration, ConstantDeclaration = "public" "static" "final" Type Identifier "=" Expression ";", UpdatableFieldDeclaration = "public" Type Identifier ";", MethodDeclaration = "public" ReturnType Identifier "(" (FormalParameterList | empty ) ")" Block, FormalParameterList = FormalParameter FormalParameterRest*, FormalParameter = FinalFormalParameter | UpdatableFormalParameter, FinalFormalParameter = "final" Type Identifier, UpdatableFormalParameter = Type Identifier, FormalParameterRest = "," FormalParameter, ReturnType = VoidType | Type, VoidType = "void", Type = UpdatableArrayType | NonArrayType, UpdatableArrayType = NonArrayType "[" ":" RankEquation "]", RankEquation = "rank" "==" IntegerLiteral, NonArrayType = BooleanType | IntegerType | DoubleType | StringType | PlaceType | DistType | RegionType | PointType | ClassNameType, BooleanType = "boolean", IntegerType = "int", DoubleType = "double", StringType = "String", PlaceType = "place", DistType = "dist" "(" ":" RankEquation ")", RegionType = "region" "(" ":" RankEquation ")", PointType = "point" "(" ":" RankEquation ")", ClassNameType = Identifier, Identifier = letter (letter | digit | '_')*, // ~isKeyword(n), Statement = Assignment | AsyncStatement | Block | FinishStatement | IfStatement | LoopStatement | PostfixStatement | PrintlnStatement | ReturnStatement | ThrowStatement | WhileStatement, Assignment = Expression "=" Expression ";", AsyncStatement = "async" "(" Expression ")" Block, Block = "{" BlockStatement* "}", BlockStatement = FinalVariableDeclaration | UpdatableVariableDeclaration | Statement, FinalVariableDeclaration = "final" Type Identifier "=" Expression ";", UpdatableVariableDeclaration = Type Identifier "=" Expression ";", FinishStatement = "finish" Statement, IfStatement = "if" "(" Expression ")" Statement ( ElseClause | empty), ElseClause = "else" Statement, LoopStatement = "for" "(" PointType ExplodedSpecification ":" Expression ")" Statement, ExplodedSpecification = IdentifierList, PointName = Identifier, IdentifierList = "[" Identifier IdentifierRest* "]", IdentifierRest = "," Identifier, PostfixStatement = Expression ";", PrintlnStatement = "System.out.println" "(" Expression ")" ";", ReturnStatement = "return" ( Expression | empty ) ";", ThrowStatement = "throw" "new" "RuntimeException" "(" Expression ")" ";", WhileStatement = "while" "(" Expression ")" Statement, Expression = InclusiveOrExpression | EqualsExpression | NotEqualsExpression | GreaterThanExpression | PlusExpression | MinusExpression | TimesExpression | DivideExpression | SinExpression | CosExpression | PowExpression | AbsExpression | MapExpression | RegionConstant | UnaryMinusExpression | CoercionToIntExpression | CoercionToDoubleExpression | TypeAnnotatedExpression | FactoryBlock | ArrayAccess | DotDistribution | DotIsFirst | DotMethodCall | DotIdentifier | PrimaryExpression, InclusiveOrExpression = PrimaryExpression "|" Expression, EqualsExpression = PrimaryExpression "==" Expression, NotEqualsExpression = PrimaryExpression "!=" Expression, GreaterThanExpression = PrimaryExpression ">" Expression, PlusExpression = PrimaryExpression "+" Expression, MinusExpression = PrimaryExpression "-" Expression, TimesExpression = PrimaryExpression "*" Expression, DivideExpression = PrimaryExpression "/" Expression, SinExpression = "Math" "." "sin" "(" Expression ")", CosExpression = "Math" "." "cos" "(" Expression ")", PowExpression = "Math" "." "pow" "(" Expression "," Expression ")", AbsExpression = "Math" "." "abs" "(" Expression ")", MapExpression = PrimaryExpression "->" PrimaryExpression, RegionConstant = "[" ColonExpression ( ColonRest | empty ) "]", ColonRest = "," ColonExpression, ColonExpression = ColonPair | Expression, ColonPair = Expression ":" Expression, UnaryMinusExpression = "-" PrimaryExpression, CoercionToIntExpression = "(" "int" ")" Expression, CoercionToDoubleExpression = "(" "double" ")" Expression, TypeAnnotatedExpression = "(" TypeAnnotation ")" Expression, TypeAnnotation = UpdatableArrayType | DistType, PrimaryExpression = Literal | This | AllocationExpression | Identifier, This = "this", FactoryBlock = "dist.factory.block" "(" Expression ")", ArrayAccess = PrimaryExpression "[" ExpressionList "]", DotMethodCall = PrimaryExpression "." Identifier "(" ( ExpressionList | empty ) ")", DotDistribution = PrimaryExpression "." "distribution", DotIsFirst = PrimaryExpression "." "isFirst" "(" ")", DotIdentifier = PrimaryExpression "." Identifier, AllocationExpression = NewObject | NewUpdatableArray, NewObject = "new" Identifier "(" ( ExpressionList | empty ) ")", NewUpdatableArray = "new" NonArrayType "[" Identifier "]" ( ArrayInitializer | empty ), Literal = IntegerLiteral | FloatingPointLiteral | StringLiteral | HereLiteral | DistUnique, IntegerLiteral = digit+, FloatingPointLiteral = digit+ ('.' digit+), StringLiteral = '"' ('\\' char | ~'"' char)* '"', HereLiteral = "here", DistUnique = "dist.UNIQUE", ExpressionList = Expression ( ArgumentRest )*, ArgumentRest = "," Expression, ArrayInitializer = "(" PointType ExplodedSpecification ")" Block } MiniX10Parser.keywords = { } keywords = ["break", "case", "catch", "continue", "default", "delete", "do", "else", "finally", "for", "function", "if", "in", "instanceof", "new", "return", "switch", "this", "throw", "try", "typeof", "var", "void", "while", "with", "ometa"] for (var idx = 0; idx < keywords.length; idx++) MiniX10Parser.keywords[keywords[idx]] = true MiniX10Parser._isKeyword = function(k) { return this.keywords.hasProperty(k) && !Object.prototype.hasProperty(k) }