Grammar mn8Parser ANTLR-generated HTML file from mn8.g
Terence Parr, MageLang Institute
|
package org.media.mn8.parser; import org.media.mn8.*; import org.media.mn8.concepts.*; import java.util.Vector; import antlr.CommonAST; /** * The parser for mn8.
* This class is automaticaly generated by * ANTLR. * @author Remus Pereni * @version $Revision: 1.78 $ $Date: 2002/10/22 19:22:41 $ */ class mn8Parser extends LLkParser imaginaryTokens : CONCEPT_DEFINITION METHOD_DEFINITION IMPLEMENTS_CLAUSE BLOCK ARRAY_DECLARATOR TYPE UNARY_MINUS UNARY_PLUS ATTRIDENT ELMETIDENTIFIER EXPR ELIST OLIST METHOD_CALL POST_INC POST_DEC CONDITION IF_BLOCK ELSE_BLOCK ELIF_BLOCK FIND_FIRST FIND_LAST SOURCE ELEM METH VARIABLE PARAMETER PAREN_EXPR PRINT ELEM_VALREF DEBUG_INFO ; mn8ScriptFile returns [String conceptName] : ( eol | ) ( ( DEFINE ) => ( conceptDefinition )* | ( statement )* ) ; eol : ( EOL )+ ; conceptDefinition : DEFINE IDENT ( labelDeclaration | ) ( extendsDeclaration | ) LBRACK eol ( conceptBodyComponent )* RBRACK eol ; statement : ( expression TO ) => toStatement | ( VARIABLE TYPEOF ) => typeofStatement | expression eol | fromStatement | printStatement | statementBlock | caseBlock | exitStatement | whileDoLoopBlock | doWhileLoopBlock | ifThenBlock | findStatement | returnStatement | eachBlock ; labelDeclaration[String label] : LABEL STRING_LITERAL ; extendsDeclaration[Vector extendsList] : EXTENDS extendedConceptsList ; conceptBodyComponent : ( STATIC | ) ( attributeDeclaration[sta] | elementDeclaration[sta, _conceptDef] | methodDeclaration[sta] ) ; extendedConceptsList[Vector extendsList] : IDENT ( COMMA IDENT )* ; attributeDeclaration[mn8ScriptAttribute attribute] returns [Token isStatic] : ATTR IDENT ( NOT | QUESTION | ) ( ASSIGN primaryExpression | ) ( TYPEOF IDENT | ) ( LABEL STRING_LITERAL | ) eol ; elementDeclaration[mn8ScriptElement element] returns [Token isStatic, ConceptDefinition conceptDef] : IDENT ( STAR | ) ( NOT | QUESTION | ) ( ASSIGN primaryExpression | ) ( TYPEOF IDENT | ) ( LABEL STRING_LITERAL | ) ( LBRACK eol ( attributeDeclaration[isStatic] | elementDeclaration[isStatic, conceptDef] )* RBRACK | ) eol ; methodDeclaration returns [Token isStatic] : COLON ( IDENT | operator ) ( LPAREN | ) ( parameterList[paramNames, paramTypes] | ) ( RPAREN | ) block ( TYPEOF IDENT | ) eol ; primaryExpression : ( ( identOrLiteral ) => ( basicExpressionComponents ( postfixExpression )* ) ( INC | DEC | ) | ( postfixExpression )+ ( INC | DEC | ) ) | ( LPAREN assignmentExpression RPAREN ) ( postfixExpression )* ( INC | DEC | ) ; operator[String operation] : PLUS | MINUS | EQUAL | GT | LT | PLUS_ASSIGN | MINUS_ASSIGN | DIV_ASSIGN | DIV | NOT_EQUAL | NOT | STAR_ASSIGN | INC | DEC | GE | LE | STAR ; parameterList returns [Vector paramNames, Vector paramTypes] : parameter[paramNames, paramTypes] ( COMMA parameter[paramNames, paramTypes] )* ; block : LBRACK ( eol | ) ( statement )* RBRACK ; parameter returns [Vector paramName, Vector paramType] : VARIABLE TYPEOF IDENT ; expression : assignmentExpression ; toStatement : expression TO additiveExpression ( optionsBlock | ) eol ; typeofStatement : VARIABLE TYPEOF assignmentExpression eol ; fromStatement : VARIABLE fromExpression eol ; printStatement : PRINT expressionList ( SEMI | ) eol ; statementBlock : block eol ; caseBlock : SWITCH expression LBRACK ( eol | ) ( caseItem )+ ( elseBlock | ) RBRACK eol ; exitStatement : ( EXIT LPAREN ) => EXIT LPAREN expression RPAREN eol | EXIT eol ; whileDoLoopBlock : WHILE expression DO statementBlock ; doWhileLoopBlock : DO block WHILE expression eol ; ifThenBlock : ( ( ifBlock elseBlock ) => ifBlock elseBlock | ( ifBlock elifBlock ) => ifBlock ( elifBlock )* ( eol | ) ( elseBlock | ) | ifBlock eol ) ; findStatement : FIND ( FIRST | LAST ) VARIABLE sourceExpression ( WHERE expression | ) ( breakExpression | ) eol ; returnStatement : RETURN expression eol ; eachBlock : EACH VARIABLE sourceExpression ( WHERE expression | ) ( breakExpression | ) DO statementBlock ; caseItem : CASE expression statementBlock ; elseBlock : ELSE statementBlock ; sourceExpression : IN expression | fromExpression ; breakExpression : BREAK byExpression ( byExpression )* ; fromExpression : FROM additiveExpression ( optionsBlock | ) ; byExpression : BY primaryExpression ( ASCENDING | DESCENDING | ) ; ifBlock : IF expression THEN block ; elifBlock : ELIF expression THEN block ; expressionList : expression ( COMMA expression )* ; additiveExpression : multiplicativeExpression ( ( PLUS | MINUS ) multiplicativeExpression )* ; optionsBlock : OPTIONS optionList ; optionList : optionItem ( COMMA optionItem )* ; optionItem : STRING_LITERAL ASSIGN expression ; assignmentExpression : logicalOrExpression ( ( ASSIGN | PLUS_ASSIGN | MINUS_ASSIGN | STAR_ASSIGN | DIV_ASSIGN ) assignmentExpression | ) ; logicalOrExpression : logicalAndExpression ( LOR logicalAndExpression )* ; logicalAndExpression : equalityExpression ( LAND equalityExpression )* ; equalityExpression : relationalExpression ( ( NOT_EQUAL | EQUAL ) relationalExpression )* ; relationalExpression : additiveExpression ( ( ( LT | GT | LE | GE ) additiveExpression )* ) ; multiplicativeExpression : unaryExpression ( ( STAR | DIV ) unaryExpression )* ; unaryExpression : INC unaryExpression | DEC unaryExpression | MINUS unaryExpression | PLUS unaryExpression | LNOT unaryExpression | FIRST primaryExpression | LAST primaryExpression | seriesExpression ; seriesExpression : ( ( literals | VARIABLE ) RANGE ( literals | VARIABLE ) ( COLON ( literals | VARIABLE ) | ) ) | primaryExpression ; literals : NUM_INT | CHAR_LITERAL | STRING_LITERAL | NUM_REAL ; identOrLiteral : literals | identifier ; basicExpressionComponents : identOrLiteral | constants ; postfixExpression : attributeReference | elementReference | methodReference ; postDecInc : DEC | INC ; attributeReference : ATTR identOrLiteral ; elementReference : SEP ( identOrLiteral | ) ; methodReference : DOT identOrLiteral ( parameterDeclaration | ) ; parameterDeclaration : LPAREN argList RPAREN ; argList : ( expressionList | ) ; constants : logicalConstants | SUPER | NIL | THIS ; identifier : IDENT | VARIABLE ; logicalConstants : TRUE | FALSE ;