[antlr-interest] C++ Grammars

Ludwig Maes ludwig.maes at gmail.com
Fri Mar 9 17:14:09 PST 2012


OK the error message was just because of not escaping the backslash in
"\u" and "\U" instead of "\\u" and "\\U" in the very first or second
rule, now im just getting some remaining mutual recursion etc... which
ill try debug tomorrow

On 10 March 2012 00:47, Ludwig Maes <ludwig.maes at gmail.com> wrote:
> By the way, the errors I get when performing "check grammar" in antlrworks
> (I created an empty rule for alignment_expression)
>
> [00:45:29] Checking Grammar cpp.g...
> [00:45:30] java.lang.StringIndexOutOfBoundsException: String index out
> of range: 7
>        at java.lang.String.substring(String.java:1946)
>        at org.antlr.tool.Grammar.getUnescapedStringFromGrammarStringLiteral(Grammar.java:2183)
>        at org.antlr.grammar.v3.ANTLRLexer.mCHAR_LITERAL(ANTLRLexer.java:1483)
>        at org.antlr.grammar.v3.ANTLRLexer.mTokens(ANTLRLexer.java:3077)
>        at org.antlr.runtime.Lexer.nextToken(Lexer.java:89)
>        at org.antlr.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:133)
>        at org.antlr.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:127)
>        at org.antlr.runtime.CommonTokenStream.consume(CommonTokenStream.java:70)
>        at org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:106)
>        at org.antlr.grammar.v3.ANTLRParser.rule(ANTLRParser.java:2783)
>        at org.antlr.grammar.v3.ANTLRParser.rules(ANTLRParser.java:2405)
>        at org.antlr.grammar.v3.ANTLRParser.grammar_(ANTLRParser.java:702)
>        at org.antlr.tool.Grammar.parseAndBuildAST(Grammar.java:644)
>        at org.antlr.tool.Grammar.setGrammarContent(Grammar.java:604)
>        at org.antlr.works.grammar.antlr.ANTLRGrammarEngineImpl.createNewGrammar(ANTLRGrammarEngineImpl.java:192)
>        at org.antlr.works.grammar.antlr.ANTLRGrammarEngineImpl.createParserGrammar(ANTLRGrammarEngineImpl.java:225)
>        at org.antlr.works.grammar.antlr.ANTLRGrammarEngineImpl.createCombinedGrammar(ANTLRGrammarEngineImpl.java:203)
>        at org.antlr.works.grammar.antlr.ANTLRGrammarEngineImpl.createGrammars(ANTLRGrammarEngineImpl.java:165)
>        at org.antlr.works.grammar.antlr.ANTLRGrammarEngineImpl.analyze(ANTLRGrammarEngineImpl.java:272)
>        at org.antlr.works.grammar.engine.GrammarEngineImpl.analyze(GrammarEngineImpl.java:325)
>        at org.antlr.works.grammar.CheckGrammar.run(CheckGrammar.java:70)
>        at java.lang.Thread.run(Thread.java:636)
>
> On 10 March 2012 00:38, Ludwig Maes <ludwig.maes at gmail.com> wrote:
>> Yes, I have
>>
>> I found 2 lineages: the one from sun and the much more recent one.
>> The last one has actions in C++, and the mixture of grammar and
>> actions is still quite confusing for me beyond basic examples...
>> (pretty new to both formal language grammars and parsing and antlr)
>>
>> I have converted the xml from http://savannah.nongnu.org/projects/hcb/
>>
>> which is also prettyfied on http://www.nongnu.org/hcb/
>>
>> and seems to stem from http://www.open-std.org/jtc1/sc22/open/n2356/
>> (this is very useful for me in the complementary sense, but I am not
>> that acquainted with how compilers work)
>> also for example there are no rules for comments in the grammar above,
>> this text explains the comment skipping in words, as being during the
>> preprocessing phase,... but the grammar contains preprocessor rules,
>> so Im not completely satisfied (its not clear to me when exactly the
>> rules for comments are used in perspective with the specific
>> preprocessing rules... or rather why some preprocessing rules are
>> present and others are not)
>>
>> I converted the xml to antlr grammar notation a few hours ago (mostly
>> by hand/ text editor replace all commands, I did not have the heart to
>> write an xml parser that would deal with ">" 's within content etc). I
>> turned the hyphens into underscores, and resolved the simpler left
>> recursions... theres still some problems though (right now every rule
>> is lowercase parser rule, Im still a bit confused on the 2x2 double
>> dichotomy of terminals/nonterminals and lexer/parser rules and perhaps
>> literals/nonliterals); then theres an undefined rule in the xml:
>> alignment-expression (or alignment_expression in the .g); a few more
>> complex left recursions; and errors when I try to check the grammar
>> (im using the antlrworks IDE). Right now I have not yet added any
>> actions.
>>
>> Some of the rules are described as a sentence instead of a grammar
>> rule, as per the source.
>>
>> I should probably add a GPLv2+ header as the xml was under such
>> license, I have no experience with licensing stuff so if anyone knows
>> how to properly include the header that would be welcome.
>>
>> I have 1 strange error and 6 warnings in the IDE, any help would be appreciated!
>>
>> See cpp.g in attachment
>>
>> Friendly regards
>>
>> On 9 March 2012 21:37, David Wigg <wiggjd at bcs.org.uk> wrote:
>>> In response to this message, has Ludwig looked at the C++ grammars
>>> already on the antlr website?
>>>
>>> Message: 1
>>> Date: Fri, 9 Mar 2012 04:10:16 +0100
>>> From: Ludwig Maes <ludwig.maes at gmail.com>
>>> Subject: [antlr-interest] found a c++ grammar xml, convert to antlr
>>>       grammar?
>>>
>>> David Wigg
>>>
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list