2009-12-02 10 views
7

मैं एएनटीएलआर 3.2 को सी ++ में पार्सर/लेक्सर उत्पन्न करने के लिए कड़ी मेहनत कर रहा था। यह फलहीन था। हालांकि जावा & सी के साथ चीजें अच्छी तरह से चली गईं।क्या एएनटीएलआर 3.2 में सी ++ कोड पीढ़ी तैयार है?

मैं इस ट्यूटोरियल उपयोग कर रहा था आरंभ करने के लिए: http://www.ibm.com/developerworks/aix/library/au-c_plusplus_antlr/index.html

जब मैं * .stg फ़ाइलों की जाँच की, मैंने पाया कि:

सीपीपी केवल

./tool/src/main/resources/org/antlr/codegen/templates/CPP/CPP.stg 

सी है तो कई फाइलों है :

./tool/src/main/resources/org/antlr/codegen/templates/C/AST.stg 
./tool/src/main/resources/org/antlr/codegen/templates/C/ASTDbg.stg 
./tool/src/main/resources/org/antlr/codegen/templates/C/ASTParser.stg 
./tool/src/main/resources/org/antlr/codegen/templates/C/ASTTreeParser.stg 
./tool/src/main/resources/org/antlr/codegen/templates/C/C.stg 
./tool/src/main/resources/org/antlr/codegen/templates/C/Dbg.stg 

और अन्य भाषाओं।

मेरे C.g फ़ाइल:

grammar C; 

options { language='CPP'; } 

/** Match things like "call foo;" */ 
r : 'call' ID ';' {System.out.println("invoke "+$ID.text);} ; 
ID: ('a'..'z'|'A'..'Z'|'_')('0'..'9'|'a'..'z'|'A'..'Z'|'_')* ; 
WS: (' ' |'\n' |'\r')+ {$channel=HIDDEN;} ; // ignore whitespace 

त्रुटियाँ:

error(10): internal error: group Cpp does not satisfy interface ANTLRCore: missing templates [lexerRuleRefAndListLabel, parameterSetAttributeRef, scopeSetAttributeRef, returnSetAttributeRef, lexerRulePropertyRef_text, lexerRulePropertyRef_type, lexerRulePropertyRef_line, lexerRulePropertyRef_pos, lexerRulePropertyRef_index, lexerRulePropertyRef_channel, lexerRulePropertyRef_start, lexerRulePropertyRef_stop, ruleSetPropertyRef_tree, ruleSetPropertyRef_st] 

error(10): internal error: group Cpp does not satisfy interface ANTLRCore: mismatched arguments on these templates [outputFile(LEXER, PARSER, TREE_PARSER, actionScope, actions, docComment, recognizer, name, tokens, tokenNames, rules, cyclicDFAs, bitsets, buildTemplate, buildAST, rewriteMode, profile, backtracking, synpreds, memoize, numRules, fileName, ANTLRVersion, generatedTimestamp, trace, scopes, superClass, literals), optional headerFile(LEXER, PARSER, TREE_PARSER, actionScope, actions, docComment, recognizer, name, tokens, tokenNames, rules, cyclicDFAs, bitsets, buildTemplate, buildAST, rewriteMode, profile, backtracking, synpreds, memoize, numRules, fileName, ANTLRVersion, generatedTimestamp, trace, scopes, superClass, literals), lexer(grammar, name, tokens, scopes, rules, numRules, labelType, filterMode, superClass), rule(ruleName, ruleDescriptor, block, emptyRule, description, exceptions, finally, memoize), alt(elements, altNum, description, autoAST, outerAlt, treeLevel, rew), tokenRef(token, label, elementIndex, hetero), tokenRefAndListLabel(token, label, elementIndex, hetero), listLabel(label, elem), charRangeRef(a, b, label), ruleRef(rule, label, elementIndex, args, scope), ruleRefAndListLabel(rule, label, elementIndex, args, scope), lexerRuleRef(rule, label, args, elementIndex, scope), lexerMatchEOF(label, elementIndex), tree(root, actionsAfterRoot, children, nullableChildList, enclosingTreeLevel, treeLevel)] 

error(10): internal error: C.g : java.lang.IllegalArgumentException: Can't find template actionGate.st; group hierarchy is [Cpp] 

... और इतने पर।

कृपया कृपया सलाह दें। धन्यवाद! मैं तेंदुए 10.5.8 का उपयोग कर रहा

CLASSPATH=:/Users/vietlq/projects/antlr-3.2.jar:/Users/vietlq/projects/stringtemplate-3.2.1/lib/stringtemplate-3.2.1.jar:/Users/vietlq/projects/stringtemplate-3.2.1/lib/antlr-2.7.7.jar 

उत्तर

9

साथ ऐसा लगता है कि आप अपने खुद के प्रश्न का उत्तर दिया: ANTLR के सी ++ lexer/पार्सर जनरेटर अभी तक कार्यात्मक नहीं हैं।

इसके लायक होने के लिए, सी लक्ष्य के माध्यम से सी ++ से पार्सिंग के लिए एएनटीएलआर का उपयोग करना अभी भी संभव है। मैं एक सी भाषा भाषा लेजर और पार्सर उत्पन्न करने के लिए एएनटीएलआर का उपयोग करता हूं, जिसे मैं संकलित करता हूं और अपने सी ++ कोड से लिंक करता हूं।

मेरे पास एक सी ++ फ़ाइल है जो एक एएनटीएलआर पार्स पेड़ को मेरे लक्षित अमूर्त वाक्यविन्यास पेड़ वर्गों में अनुवाद करती है, और मेरे बाकी कोड परवाह नहीं है कि एएसटी कहां से आता है। यह अभ्यास में बहुत अच्छी तरह से काम करता है! एएनटीएलआर को एक अलग पार्सर जनरेटर के साथ प्रतिस्थापित करना आसान होगा, और मुझे लगता है कि अलगाव क्लीनर एएनटीएलआर व्याकरण की ओर जाता है।

+0

हाय बेन, क्या आप ओपन सोर्स लाइसेंस के तहत अपना सी ++ टूल जारी करेंगे? धन्यवाद! – Viet

4

मैंने एएनटीएलआर के लिए सी ++ लक्ष्य पोस्ट किया है। कृपया यह देखें।

+0

क्या आप लिंक पोस्ट कर सकते हैं? धन्यवाद! – Viet

+1

http://www.antlr.org/wiki/pages/viewpage.action?pageId=29130826 – Gokul

+0

+1 शानदार! साझा करने के लिए धन्यवाद! – Viet

संबंधित मुद्दे