Tuesday 15 September 2015

Is C++ code generation in ANTLR 3.2 ready? -


I was trying to create ANTLR 3.2 parser / lexer generated in C ++ it was in vain Java & amp; C. However

I was using this tutorial to get started:

When I checked * .stg files then I found that:

CPP There are only so many files in

./tou/ 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

and in other languages ​​as well.

My CG file:

  Grammar C; Option {language = 'CPP'; } / ** things like "call fu;" * / 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;}; // Error:  

Errors:

  Error (10): Internal Error: Group CPP Interface ANTLRCore does not satisfy: 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 interface does not satisfy ANTLRCore: these templates mismatched argument [outputfile ( Lexer, PARSER, TREE_PARSER, exc No scope, action, dock comment, identifier, name, token, Toknnam, rules, cyclic DFA, bits, build template, build AST, rewrite mode, Profile, backtracking, Sinkrad, Memoaijh, Numul, filename, Aantielarwarsian, Jenaretmstamp, trace , Scopes, superclass, Litrl), optional Hederfail (LEXER, PARSER, TREE_PARSER, ActionScope, functions, DocComment, identifier, name, token, TokenNames, rules, cyclicDFAs, bitsets, buildTemplate, buildAST, rewriteMode, profile, contrary finding And returning, synpreds, memoize, numRules, filename, ANTLRVersion, generatedTimestamp, detection, scope, superclass, literal), lexer (grammar, name, token, scope, rule, numRules, labelType, filterMode, superclass) rule (RuleName, RuleDescriptor, block, EmptyRule, details, exceptions, finally, memoize), ALT (element, AltNum, details, autoAST, outerAlt, treeLevel, rew), tokenRef (token label, ElementIndex, Hetero), tokenRefAndListLabel (token label, elementIndex, Hetero), listLabel (labels, ELEM), charRangeRef (A, B, label), ruleRef (rules, labels, elementIndex, args, scope), ruleRefAndListLabel (rules, labels, elementIndex , Args, scope), LexerRuleRef (rules, labels, args, ElementIndex, scope), LexerMatchEOF (labels, ElementIndex), tree (root, ActionsAfterRoot, children, taps qualified Chaildlist, gaps, tree level)] Error (10): Interior Arro R: CG: java.lang.IllegalArgumentException: The template action can not be found; gate. Group hierarchy [CPP]  

... and so on.

Please advise. Thanks! I am using Leopard 10.5.8

  CLASSPATH =: / user / merge / project / anther-3.2.jor: / users / vivalent / project / strimentplate-3.2.2 / lee / Stringtemplate-3.2.1.jar: / Users / Vivelt / Project / StringTamplate-3.2.1 / Lib / antlr-2.7.7.jar  

It looks like you have answered your question: ANTLR's C ++ laser / parser generator is not yet functional Yes.

What is the value for it, it is still possible to use ANLR to parse C ++ through C target. I use the ANTLR to generate C-language lexers and parsers. I am compiling it, and then I link it to my C ++ code.

I have a C ++ file which translates into my target abstract syntax tree sections of an ATLR payse tree, and does not care about the rest of the code that where AST comes from. It works very well in practice! It would be easy to replace the ANLR with a different parser generator, and I think the separation cleaner leads to ANLR grammar.


1 comment: