/* BSD-style license; for more info see http://pmd.sourceforge.net/license.html Based on Antlr4 Modelica grammar downloaded from https://github.com/antlr/grammars-v4 License of the original modelica.g4: [The "BSD licence"] Copyright (c) 2012 Tom Everett All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ options { CACHE_TOKENS=true; STATIC = false; USER_CHAR_STREAM = true; JDK_VERSION = "1.5"; MULTI = true; VISITOR = true; NODE_USES_PARSER = true; TRACK_TOKENS = false; SUPPORT_CLASS_VISIBILITY_PUBLIC=false; NODE_PACKAGE="net.sourceforge.pmd.lang.modelica.ast"; UNICODE_INPUT = true; } PARSER_BEGIN(ModelicaParserImpl) package net.sourceforge.pmd.lang.modelica.ast; class ModelicaParserImpl { } PARSER_END(ModelicaParserImpl) TOKEN: { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | " > | =" > | | " > | | | | | | | | | | } TOKEN: { ( | )*) | > | <#Q_IDENT: "\'" ( | )+ "\'"> | <#S_CHAR: ~["\"", "\\"] > | <#NONDIGIT: [ "_", "a" - "z", "A" - "Z" ]> | | )* "\""> | <#Q_CHAR: | | [ "!", "#", "$", "%", "&", "(", ")", "*", "+", ",", "-", ".", "/", ":", ";", "<", ">", "=", "?", "@", "[", "]", "^", "{", "}", "|", "~" ] > | <#S_ESCAPE: "\\" [ "\u2019", "\'", "\"", "?", "\\", "a", "b", "f", "n", "r", "t", "v" ] > | <#DIGIT: ["0" - "9"]> | <#UNSIGNED_INTEGER: ()+ > | ("." ()?)? (["e", "E"] (["+", "-"])? )?> } SKIP: { | } // Copyed from cpp.jj MORE: { "/*" : IN_MULTI_LINE_COMMENT } SPECIAL_TOKEN: { : DEFAULT } MORE: { < ~[] > } ASTStoredDefinition StoredDefinition(): {} { ( {jjtThis.markHasBOM(); } )? (( (Name())? ) #WithinClause)* (()? ClassDefinition() )* { return jjtThis; } } void ClassDefinition(): {} { ( #EncapsulatedClause)? ClassPrefixes() ClassSpecifier() } void ClassSpecifier(): {} { LOOKAHEAD(2) LongClassSpecifier() | LOOKAHEAD(3) DerClassSpecifier() | ShortClassSpecifier() } void ClassPrefixes(): {} { ( #PartialClause)? ( #ClassClause | #ModelClause | #RecordClause | LOOKAHEAD(2) ( #OperatorRecordClause) | #BlockClause | LOOKAHEAD(2) ( #ExpandableConnectorClause) | #ConnectorClause | #TypeClause | #PackageClause | LOOKAHEAD(3) (( #PureClause | #ImpureClause)? ( #OperatorClause)? ) #FunctionClause | #Operator ) } void LongClassSpecifier() #void: {} { ( SimpleName() StringComment() Composition() SimpleName() ) #SimpleLongClassSpecifier | ( SimpleName() (ClassModification())? StringComment() Composition() SimpleName() ) #ExtendingLongClassSpecifier } void ShortClassSpecifier() #void: {} { LOOKAHEAD(3) ( SimpleName() BasePrefix() Name() (ArraySubscripts())? (ClassModification())? Comment() ) #SimpleShortClassSpecifier | ( SimpleName() ( | (EnumList())? ) Comment() ) #EnumerationShortClassSpecifier } void DerClassSpecifier(): {} { SimpleName() ( Name() ( SimpleName() )* ) #DerClause Comment() } void BasePrefix(): {} { TypePrefix() } void EnumList(): {} { EnumerationLiteral() ( EnumerationLiteral() )* } void EnumerationLiteral(): {} { SimpleName() Comment() } void Composition(): {} { ElementList(Visibility.UNSPEC) ( ( ElementList(Visibility.PUBLIC)) | ( ElementList(Visibility.PROTECTED)) | LOOKAHEAD(2) EquationSection() | LOOKAHEAD(2) AlgorithmSection() )* (( (LanguageSpecification())? (ExternalFunctionCall())? (Annotation())? ) #ExternalClause)? ( Annotation() )? } void LanguageSpecification(): { Token t; } { t = { jjtThis.setExternalLanguage(t.getImage()); } } void ExternalFunctionCall(): {} { ( LOOKAHEAD(2) ComponentReference() )? SimpleName() (ExpressionList())? } void ElementList(Visibility v): {} { { jjtThis.setVisibility(v); } ( Element() )* } void Element() #void: {} { ImportClause() | ExtendsClause() | ( ( #RedeclareClause)? ( #FinalClause)? ( #InnerClause)? ( #OuterClause)? ( (ClassDefinition() | ComponentClause()) | ( (ClassDefinition() | ComponentClause()) (ConstrainingClause() Comment())?) #ReplaceableClause ) ) #RegularElement } void ImportClause(): {} { ( LOOKAHEAD(2) (SimpleName() Name()) #RenamingImportClause | LOOKAHEAD(Name() (( ) | )) (Name() (( ) | )) #UnqualifiedImportClause | LOOKAHEAD(Name() ) ((Name() ImportList()) ) #MultipleDefinitionImportClause | Name() #SingleDefinitionImportClause ) Comment() } void ImportList(): {} { SimpleName() ( SimpleName() )* } void ExtendsClause(): {} { Name() (ClassModification())? (Annotation())? } void ConstrainingClause(): {} { Name() (ClassModification())? } void ComponentClause(): {} { TypePrefix() TypeSpecifier() (ArraySubscripts())? ComponentList() } void TypePrefix(): {} { ( #FlowClause | #StreamClause)? ( #DiscreteClause | #ParameterClause | #ConstantClause)? ( #InputClause | #OutputClause)? } void TypeSpecifier(): {} { Name() } void ComponentList(): {} { ComponentDeclaration() ( ComponentDeclaration() )* } void ComponentDeclaration(): {} { Declaration() (ConditionAttribute())? Comment() } void ConditionAttribute(): {} { Expression() } void Declaration(): {} { SimpleName() (ArraySubscripts())? (Modification())? } void Modification() #void: {} { ( ClassModification() ( Expression() )? ) #LongModification | ( Expression() ) #ShortModification | ( Expression() ) #AssignmentModification } void ClassModification(): {} { (ArgumentList())? } void ArgumentList(): {} { Argument() ( Argument() )* } void Argument(): {} { ElementModificationOrReplaceable() | ElementRedeclaration() } void ElementModificationOrReplaceable(): {} { ( #EachClause)? ( #FinalClause)? ( ElementModification() | ElementReplaceable() ) } void ElementModification(): {} { Name() (Modification())? StringComment() } void ElementRedeclaration(): {} { ( #EachClause)? ( #FinalClause)? ( (ShortClassDefinition() | ComponentClause1()) | ElementReplaceable() ) } void ElementReplaceable(): {} { (ShortClassDefinition() | ComponentClause1()) (ConstrainingClause())? } void ComponentClause1(): {} { TypePrefix() TypeSpecifier() ComponentDeclaration1() } void ComponentDeclaration1(): {} { Declaration() Comment() } void ShortClassDefinition(): {} { ClassPrefixes() ShortClassSpecifier() } void EquationSection(): {} { ( #InitialClause)? ( LOOKAHEAD(2) Equation() )* } void AlgorithmSection(): {} { ( #InitialClause)? ( Statement() )* } void Equation(): {} { ( LOOKAHEAD (SimpleExpression() Expression() /* TODO */) (SimpleExpression() Expression()) #RegularEquation | IfEquation() | ForEquation() | ConnectClause() | WhenEquation() | (Name() FunctionCallArgs()) #FunctionCallEquation ) Comment() } void Statement(): {} { ( LOOKAHEAD(ComponentReference() ) (ComponentReference() Expression()) #AssignmentStatement | (ComponentReference() FunctionCallArgs()) #FunctionCallStatement | ( OutputExpressionList() ComponentReference() FunctionCallArgs()) #AssignmentFromMultiResultFunctionCall | #BreakStatement | #ReturnStatement | IfStatement() | ForStatement() | WhileStatement() | WhenStatement() ) Comment() } void IfEquation(): {} { ( Expression() #IfClause) ( EquationList() #ThenClause) (( Expression() EquationList()) #ElseIfClause)* ( EquationList() #ElseClause)? } void IfStatement(): {} { ( Expression() #IfClause) ( StatementList() #ThenClause) (( Expression() StatementList()) #ElseIfClause)* ( StatementList() #ElseClause)? } void ForEquation(): {} { ForIndices() EquationList() } void EquationList(): {} { (LOOKAHEAD(Equation() /* TODO */) Equation() )* } void StatementList(): {} { (Statement() )* } void ForStatement(): {} { ForIndices() StatementList() } void ForIndices(): {} { ForIndex() ( ForIndex())* } void ForIndex(): {} { SimpleName() ( Expression() )? } void WhileStatement(): {} { Expression() StatementList() } void WhenEquation(): {} { ( Expression() #WhenClause) ( EquationList() #ThenClause) (( Expression() EquationList()) #ElseWhenClause)* } void WhenStatement(): {} { ( Expression() #WhenClause) ( StatementList() #ThenClause) (( Expression() StatementList()) #ElseWhenClause)* } void ConnectClause(): {} { ComponentReference() ComponentReference() } void Expression() #void: {} { SimpleExpression() | IfExpression() } void IfExpression(): {} { (( Expression()) #IfClause) (( Expression()) #ThenClause) (( Expression() Expression()) #ElseIfClause)* (( Expression()) #ElseClause) } void SimpleExpression() #SimpleExpression(>1): {} { LogicalExpression() ( LogicalExpression() ( LogicalExpression() )? )? } void LogicalExpression() #LogicalExpression(>1): {} { LogicalTerm() ( LogicalTerm() )* } void LogicalTerm() #LogicalTerm(>1): {} { LogicalFactor() ( LogicalFactor() )* } void LogicalFactor() #void: {} { ( Relation()) #Negated | Relation() } void Relation() #Relation(>1): {} { ArithmeticExpression() ( RelOp() ArithmeticExpression() )? } void RelOp(): {} { { jjtThis.setOperator("<"); } | { jjtThis.setOperator("<="); } | { jjtThis.setOperator(">"); } | { jjtThis.setOperator(">="); } | { jjtThis.setOperator("=="); } | { jjtThis.setOperator("<>"); } } void ArithmeticExpression() #ArithmeticExpression(>1): {} { (AddOp())? Term() ( AddOp() Term() )* } void AddOp(): {} { { jjtThis.setOperator("+"); } | { jjtThis.setOperator("-"); } | { jjtThis.setOperator(".+"); } | { jjtThis.setOperator(".-"); } } void Term() #Term(>1): {} { Factor() ( MulOp() Factor() )* } void MulOp(): {} { { jjtThis.setOperator("*"); } | { jjtThis.setOperator("/"); } | { jjtThis.setOperator(".*"); } | { jjtThis.setOperator("./"); } } void Factor() #Factor(>1): {} { Primary() ( ( { jjtThis.setOperator("^"); } | { jjtThis.setOperator(".^"); } ) Primary() )? } void Primary() #void: {} { NumberLiteral() | StringLiteral() | #FalseLiteral | #TrueLiteral | LOOKAHEAD((((Name() | | ) FunctionCallArgs())) /* TODO */) (((Name() | #DerClause | #InitialClause) FunctionCallArgs())) #FunctionInvocation | ComponentReference() | ( OutputExpressionList() ) | ( ExpressionList() ( ExpressionList())* ) #ListOfExpressionLists | ( FunctionArguments() ) | } void NumberLiteral(): { Token t; } { t = { jjtThis.setValue(t.getImage()); } } void StringLiteral(): { Token t; } { t = { jjtThis.setValue(t.getImage()); } } void Name(): {} { ( { jjtThis.markAbsolute(); } )? SimpleName() (LOOKAHEAD(2) ( SimpleName() ))* } void SimpleName(): { Token t; } { t = { jjtThis.setName(t.getImage()); } } void SubscriptedName(): {} { SimpleName() (ArraySubscripts())? } void ComponentReference(): {} { ( { jjtThis.markAbsolute(); } )? SubscriptedName() ( SubscriptedName() )* } void FunctionCallArgs(): {} { (FunctionArguments())? } void FunctionArguments(): {} { LOOKAHEAD(2) NamedArguments() | (FunctionArgument() ( FunctionArguments() | ( ForIndices()))?) } void NamedArguments(): {} { NamedArgument() ( NamedArguments() )? } void NamedArgument(): {} { SimpleName() FunctionArgument() } void FunctionArgument(): {} { ( Name() (NamedArguments())? ) | ( Expression() ) } void OutputExpressionList(): {} { (Expression())? ( (Expression())? )* } void ExpressionList(): {} { Expression() ( Expression() )* } void ArraySubscripts(): {} { Subscript() ( Subscript() )* } void Subscript(): {} { ( #ColonSubsript) | Expression() } void Comment(): {} { StringComment() (Annotation())? } void StringComment() #StringComment(!skip): { boolean skip = true; StringBuilder sb = new StringBuilder(); Token t; } { (( t = { sb.append(t); } ( t = { sb.append(t); } )* ) { skip = false; }) ? { jjtThis.setComment(sb.toString()); } } void Annotation(): {} { ClassModification() }