我编写了以下语法文件,并收到以下错误。我做过很多谷歌搜索,有些回答说语法有问题。但是以下错误消息并未指明具体位置,可能是错误消息的位置。你能否告诉我,为什么我会收到错误,如下所述。
grammar ArchSpec;
options {
language = Java;
}
@lexer::header {
package iotsuite.parser;
}
@parser::header {
package iotsuite.parser;
import iotsuite.compiler.*;
import iotsuite.semanticmodel.*;
}
@members {
private SymbolTable context;
}
archSpec :
('structs' ':' struct_def)*
'softwarecomponents' ':' (component_def)+
;
component_def :
'computationalService' ':' (cs_def)+
;
struct_def:
CAPITALIZED_ID
(structField_def ';')+
;
structField_def:
lc_id ':' dataType
;
cs_def:
CAPITALIZED_ID
(csGeneratedInfo_def ';')+
(csConsumeInfo_def ';')*
(csRequest_def ';')*
(cntrlCommand_def ';')*
(partition_def ';')+
;
csGeneratedInfo_def:
'generate' lc_id ':' CAPITALIZED_ID
;
csConsumeInfo_def:
'consume' lc_id ('from' 'region-hops' ':' INT ':' CAPITALIZED_ID )?
;
csRequest_def :
'request' lc_id
;
cntrlCommand_def :
'command' name = CAPITALIZED_ID '(' (cntrlParameter_def)? ')' 'to' 'region-hops' ':' INT ':' CAPITALIZED_ID
;
cntrlParameter_def :
lc_id (',' parameter_def )?
;
partition_def:
csDeploymentConstraint='partition-per' ':' CAPITALIZED_ID
;
lc_id: ID
;
dataType:
primitiveType
;
primitiveType:
(id='Integer' | id='Boolean' | id='String' | id = 'double' | id = 'long' | id='boolean' )
;
ID : 'a'..'z' ('a'..'z' | 'A'..'Z' )*
;
INT : '0'..'9'('0'..'9')* ;
CAPITALIZED_ID: 'A'..'Z' ('a'..'z' | 'A'..'Z' )*;
WS: ('\t' | ' ' | '\r' | '\n' | '\u000C')+ {$channel = HIDDEN;};
我在控制台上收到的错误消息如下。
java.lang.NoSuchFieldError: offendingToken
at org.deved.antlride.runtime.AntlrErrorListener.extractToken(AntlrErrorListener.java:111)
at org.deved.antlride.runtime.AntlrErrorListener.report(AntlrErrorListener.java:79)
at org.deved.antlride.runtime.AntlrErrorListener.message(AntlrErrorListener.java:63)
at org.deved.antlride.runtime.AntlrErrorListener.error(AntlrErrorListener.java:53)
at org.antlr.tool.ErrorManager.grammarError(ErrorManager.java:742)
at org.antlr.tool.ErrorManager.grammarError(ErrorManager.java:750)
at org.antlr.tool.NameSpaceChecker.lookForReferencesToUndefinedSymbols(NameSpaceChecker.java:133)
at org.antlr.tool.NameSpaceChecker.checkConflicts(NameSpaceChecker.java:72)
at org.antlr.tool.Grammar.checkNameSpaceAndActions(Grammar.java:804)
at org.antlr.tool.CompositeGrammar.defineGrammarSymbols(CompositeGrammar.java:374)
at org.antlr.Tool.process(Tool.java:484)
at org.deved.antlride.runtime.Tool2.main(Tool2.java:24)
我解析的输入实例如下:
softwarecomponents:
computationalService:
RoomAvgTemp
generate roomAvgTempMeasurement:TempStruct;
consume tempMeasurement from region-hops:0:Room;
partition-per : Room;
RoomController
consume roomAvgTempMeasurement from region-hops:0:Room;
command SetTemp(setTemp) to region-hops:0:Room;
partition-per : Room;