Sorry - I actually am using a real grammar with parser and lexer rules. I'll paste the grammar at the end of this message, it is pretty long. I just thought I'd see if Bernt figured out the issue, because I am getting the exact same error with the same version of Antlrworks - 1.2.2
I do not get the error at all when I generate the Python code with Antlrworks 1.4. However, the the latest Python runtime seems to be 3.1.2, and Antlrworks 1.4 generates code for the 3.2 runtime. If there is a Python runtime for 3.2, that would probably solve my problem. Can someone point me to it? Thanks! -Art > From: "Kevin J. Cummings" <[email protected]> > In Bernt's example below, prog is an empty rule. Not a good idea. > Probably deserving of a better error message though. > > If this is specific to the python project, you'd have to get an answer > from one of the Python maintainers. > From: "Jim Idle" <[email protected]> > You have no lexer rules. It is just a syntax error in your .g file. These > will be better reported in ANTLR 4 > > Jim > grammar PricingP; options { language=Python;} @members { pricingHelper = "" } pricingScript : (condCase | clauseCase)+ 'endCase:'? EOF ; condCase : {self.pricingHelper.incrementIndent()} 'condCase:' condExpr 'then:' ((condCase | clauseCase)+ 'endCase:' | pcTypeExpr ) {self.pricingHelper.decrementIndent()} ; condExpr : { self.pricingHelper.resetIntermediateBuffer() } ((dateRange | finRatio | extRating | balCond | hlt | outsideCondition ) (andOr=STRING { self.pricingHelper.addLineToResult(self.pricingHelper.intermediateBuffer.toString() + " " + self.pricingHelper.trimColon($andOr.text)) self.pricingHelper.resetIntermediateBuffer() } )? )+ {self.pricingHelper.addLineToResult(self.pricingHelper.intermediateBuffer.toString()); } ; outsideCondition : 'OUT:' outsideConditionCode=RIDSTRING outsideConditionValue=STRING { self.pricingHelper.getIntermediateBuffer().append( "If( " + self.pricingHelper.getNot($outsideConditionValue.text) + " " + self.pricingHelper.lookupOutsideCondition(self.pricingHelper.trimCurlies($outsideConditionCode.text)) + " )") } ; balCond : 'balCond:' pricingOptionOrAmount=RIDSTRING balanceType=RIDSTRING facOrDeal=RIDSTRING minBalOp=STRING (('mn:' minBalValue=RIDSTRING) | minBalValue=STRING) maxBalOp=STRING (('mn:' maxBalValue=RIDSTRING ) | maxBalValue=STRING) { balType = "" if self.pricingHelper.trimCurlies($pricingOptionOrAmount.text).equalsIgnoreCase("AVG") : balType = self.pricingHelper.lookupBalanceType(self.pricingHelper.trimCurlies($balanceType.text)) else : balType = self.pricingHelper.lookupPricingOption(self.pricingHelper.trimCurlies($balanceType.text)) self.pricingHelper.getIntermediateBuffer().append("( " + self.pricingHelper.lookupFacOrDeal(self.pricingHelper.trimCurlies($facOrDeal.text)) + " " + balType + " ) From: ( " + $minBalOp.text + " ): " + self.pricingHelper.formatCurrency($minBalValue.text) + " To ( " + $maxBalOp.text + " ): " + self.pricingHelper.formatCurrency($maxBalValue.text)) } ; hlt : 'HLT:' hltValue=STRING { self.pricingHelper.getIntermediateBuffer().append( "If( " + self.pricingHelper.getNot($hltValue.text) + " HLT )")} ; dateRange : 'dateRange:' minDateOp=STRING 'mn:'? minDateValue=RIDSTRING maxDateOp=STRING 'mn:'? maxDateValue=RIDSTRING {self.pricingHelper.getIntermediateBuffer().append("From ( " + $minDateOp.text + " ): " + self.pricingHelper.formatDate(self.pricingHelper.trimCurlies($minDateValue.text)) + " To ( " + $maxDateOp.text + " ): " + self.pricingHelper.formatDate(self.pricingHelper.trimCurlies($maxDateValue.text)))}; finRatio : 'finRatio:' finRatioType=RIDSTRING minFinRatioOp=STRING (('mn:' minFinRatioValue=RIDSTRING) | minFinRatioValue=STRING) maxFinRatioOp=STRING (('mn:' maxFinRatioValue=RIDSTRING) | maxFinRatioValue=STRING) {self.pricingHelper.getIntermediateBuffer().append("( Financial Ratio - " + self.pricingHelper.lookupFinancialRatio(self.pricingHelper.trimCurlies($finRatioType.text)) + " ) From ( " + $minFinRatioOp.text + " ): " + $minFinRatioValue.text + " To ( " + $maxFinRatioOp.text + " ): " + $maxFinRatioValue.text)}; extRating : 'extRating:' extRatingType=RIDSTRING extRatingRID=RIDSTRING minRatingOp=STRING minRatingValue=RIDSTRING maxRatingOp=STRING maxRatingValue=RIDSTRING { self.pricingHelper.getIntermediateBuffer().append("( " + self.pricingHelper.trimCurlies(self.pricingHelper.lookupCustomer($extRatingRID.text)) + " - " + self.pricingHelper.trimCurlies(self.pricingHelper.lookupExternalRatingCode($extRatingType.text)) + " ) From ( " + $minRatingOp.text + " ): " + self.pricingHelper.trimCurlies($minRatingValue.text) + " To ( " + $maxRatingOp.text + " ): " + self.pricingHelper.trimCurlies($maxRatingValue.text)) }; clauseCase : {self.pricingHelper.incrementIndent()} 'clauseCase:' (fee | option) 'then:' ((condCase | clauseCase)+ 'endCase:'| pcTypeExpr) {self.pricingHelper.decrementIndent()} ; fee : 'feeType:' feeTypeCode=RIDSTRING feeCategory=RIDSTRING bankCode=RIDSTRING { self.pricingHelper.addLineToResult(self.pricingHelper.lookupPricingFeeCategory(self.pricingHelper.trimCurlies($feeCategory.text)) + " - " + self.pricingHelper.lookupFeeTypeCode(self.pricingHelper.trimCurlies($feeTypeCode.text)))} ; option : 'optName:' optname=RIDSTRING optOption=RIDSTRING { self.pricingHelper.addLineToResult(self.pricingHelper.lookupPricingOptionName(self.pricingHelper.trimCurlies($optname.text))+":")} ; pcTypeExpr : { self.pricingHelper.incrementIndent() self.pricingHelper.resetIntermediateBuffer() } 'pcType:' pcType=RIDSTRING ('minAmt:' minAmtValue=STRING)?',' rateExpr { self.pricingHelper.addLineToResult(self.pricingHelper.getIntermediateBuffer().toString()) self.pricingHelper.decrementIndent() }; rateExpr : (rate | bal) (op (spread|cdsrate))? ; bal : 'bal:' balType=RIDSTRING { self.pricingHelper.getIntermediateBuffer().append(self.pricingHelper.lookupFeeBalanceType(self.pricingHelper.trimCurlies($balType.text))) } ; rate : ((compareExpr | baseRate)) ; compareExpr : rateCompare=('HO' | 'LO' | 'AO' | 'BP' ) '(' { self.pricingHelper.getIntermediateBuffer().append(self.pricingHelper.lookupRateCompare($rateCompare.text) + " ( ") } ((baseRate|floorCeiling) ','{self.pricingHelper.getIntermediateBuffer().append(", ")} )+ (baseRate|floorCeiling) ')' { self.pricingHelper.getIntermediateBuffer().append(" ) ") } (baseSpread)?; baseRate : 'baseRate:' rateName=RIDSTRING { self.pricingHelper.getIntermediateBuffer().append(" ( " + self.pricingHelper.lookupBaseRate(self.pricingHelper.trimCurlies($rateName.text))) } (baseSpread)? { self.pricingHelper.getIntermediateBuffer().append(" )") } ; baseSpread : { values = [] } (op1=STRING spreadValueType1=STRING spreadValue1=STRING { val = [$op1.text, $spreadValue1.text, $spreadValueType1.text ] values.append(val) } )+ { if len(values)<2: val = values[0] self.pricingHelper.getIntermediateBuffer().append(" " + val[0] + " " + self.pricingHelper.calculateSpreadValue(val[1], val[2]) + self.pricingHelper.lookupSpreadValueType(val[2])) else : self.pricingHelper.getIntermediateBuffer().append(" " + values[0][0] + " (") i = 0 for val in values: if i > 0: self.pricingHelper.getIntermediateBuffer().append(" " + val[0] + " ") self.pricingHelper.getIntermediateBuffer().append(self.pricingHelper.calculateSpreadValue(val[1], val[2]) + self.pricingHelper.lookupSpreadValueType(val[2])) i = i+1 self.pricingHelper.getIntermediateBuffer().append(")") }; floorCeiling : spreadValueType2=STRING spreadValue2=STRING { self.pricingHelper.getIntermediateBuffer().append(" " + self.pricingHelper.calculateSpreadValue($spreadValue2.text, $spreadValueType2.text) + self.pricingHelper.lookupSpreadValueType($spreadValueType2.text)) } ; op : 'op:' opValue=STRING { if $opValue.text == "*" : self.pricingHelper.getIntermediateBuffer().append(" X Rate " ) elif $opValue.text == "+" : self.pricingHelper.getIntermediateBuffer().append(" " + ($opValue.text) + " Spread " ) }; spread : 'spread:' spreadValueType=RIDSTRING spreadValue=STRING { self.pricingHelper.getIntermediateBuffer().append( "(" + self.pricingHelper.calculateSpreadValue($spreadValue.text, $spreadValueType.text) + self.pricingHelper.lookupSpreadValueType($spreadValueType.text) + ") ") }; cdsrate : 'cdsRate:(' ((STRING|RIDSTRING)(',')?)+ ')' { self.pricingHelper.getIntermediateBuffer().append( "(FLOATING)" ) }; RIDSTRING : '{'('a'..'z' | 'A'..'Z' | '0'..'9' | '.'| '<'| '('| '+'| '!'| '*'| ')'| ';'| '>'| '?'| ':'| '#'| '@'| '=' | '/' | '-' | ',' |'$')+'}'; STRING : ('a'..'z' | 'A'..'Z' | '0'..'9' | '.' | '=' | '<' | '>' | ':' | '/' | '+' | '-' | '{' | '}' | '*'| '!' | ';'| '?' | '@')+ ; // | '(' | ')' | ',' WS : (' ' |'\t' | '\r' | '\n')+ {self.skip()} ; List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
