Click here to Skip to main content
14,495,698 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: CCC- 1/10/20 Pin
OriginalGriff10-Jan-20 5:47
mveOriginalGriff10-Jan-20 5:47 
GeneralI was sent this, and... Pin
OriginalGriff9-Jan-20 20:57
mveOriginalGriff9-Jan-20 20:57 
GeneralRe: I was sent this, and... Pin
musefan9-Jan-20 21:44
Membermusefan9-Jan-20 21:44 
GeneralRe: I was sent this, and... Pin
Joan M9-Jan-20 22:47
professionalJoan M9-Jan-20 22:47 
GeneralRe: I was sent this, and... Pin
Basildane10-Jan-20 1:44
MemberBasildane10-Jan-20 1:44 
QuestionHow much code is too much? Pin
honey the codewitch9-Jan-20 14:36
mvahoney the codewitch9-Jan-20 14:36 
AnswerRe: How much code is too much? Pin
John R. Shaw9-Jan-20 18:23
MemberJohn R. Shaw9-Jan-20 18:23 
GeneralRe: How much code is too much? Pin
honey the codewitch9-Jan-20 18:45
mvahoney the codewitch9-Jan-20 18:45 
Meh - parser generators never generate reviewable code. The exception being those that can do code synthesis, but I can't even name one that does that.

Parsley, being recursive descent, generates more readable code than 90% of the generators out there. You can actually debug it and make sense of it.

However, it doesn't mean it's compact. It's just not. Generated code is generated code, and LL(1) parsing is LL(1) parsing. Being that this is the landscape, my code size is not unreasonable.

As I suggested, in generated code size it compares to ANTLR, which is a much more mature and very popular parser generator.

However, Parsley's code is somewhat readable, whereas ANTLR's isn't.

Here's an excerpt of Parsley's generated code (c# in this case):

internal static ParseNode ParseFactorExpression(ParserContext context) {
    int line = context.Line;
    int column = context.Column;
    long position = context.Position;
    // FactorExpression -> UnaryExpression FactorExpressionPart
    if ((((((((((((((((((((((((((((((((((((ExpressionParser.add == context.SymbolId) 
                || (ExpressionParser.sub == context.SymbolId)) 
                || (ExpressionParser.not == context.SymbolId)) 
                || (ExpressionParser.inc == context.SymbolId)) 
                || (ExpressionParser.dec == context.SymbolId)) 
                || (ExpressionParser.lparen == context.SymbolId)) 
                || (ExpressionParser.nullLiteral == context.SymbolId)) 
                || (ExpressionParser.typeOf == context.SymbolId)) 
                || (ExpressionParser.defaultOf == context.SymbolId)) 
                || (ExpressionParser.verbatimStringLiteral == context.SymbolId)) 
                || (ExpressionParser.characterLiteral == context.SymbolId)) 
                || (ExpressionParser.integerLiteral == context.SymbolId)) 
                || (ExpressionParser.floatLiteral == context.SymbolId)) 
                || (ExpressionParser.stringLiteral == context.SymbolId)) 
                || (ExpressionParser.boolLiteral == context.SymbolId)) 
                || (ExpressionParser.newKeyword == context.SymbolId)) 
                || (ExpressionParser.thisRef == context.SymbolId)) 
                || (ExpressionParser.baseRef == context.SymbolId)) 
                || (ExpressionParser.verbatimIdentifier == context.SymbolId)) 
                || (ExpressionParser.identifier2 == context.SymbolId)) 
                || (ExpressionParser.boolType == context.SymbolId)) 
                || (ExpressionParser.charType == context.SymbolId)) 
                || (ExpressionParser.stringType == context.SymbolId)) 
                || (ExpressionParser.floatType == context.SymbolId)) 
                || (ExpressionParser.doubleType == context.SymbolId)) 
                || (ExpressionParser.decimalType == context.SymbolId)) 
                || (ExpressionParser.sbyteType == context.SymbolId)) 
                || (ExpressionParser.byteType == context.SymbolId)) 
                || (ExpressionParser.shortType == context.SymbolId)) 
                || (ExpressionParser.ushortType == context.SymbolId)) 
                || (ExpressionParser.intType == context.SymbolId)) 
                || (ExpressionParser.uintType == context.SymbolId)) 
                || (ExpressionParser.longType == context.SymbolId)) 
                || (ExpressionParser.ulongType == context.SymbolId)) 
                || (ExpressionParser.objectType == context.SymbolId))) {
        System.Collections.Generic.List<ParseNode> children = new System.Collections.Generic.List<ParseNode>();
        children.Add(ExpressionParser.ParseUnaryExpression(context));
        children.AddRange(ExpressionParser.ParseFactorExpressionPart(context).Children);
        return new ParseNode(121, "FactorExpression", children.ToArray(), line, column, position);
    }
    throw new SyntaxException("Expecting UnaryExpression", line, column, position);
}


Most of the size here is taken up by the FIRST set comparison in the if statement - canonical LL(1). Note that 121 *was* a constant, but since it's only ever used internally by the parser, and never seen outside of it, i removed the constants like this from the list of fields in the class (there can be hundreds of these in a real world grammar). I had to make a call between code size and readability in that instance. The constant is literally "FactorExpression" and always followed by it's string name so I favored size over using a constant here.

Anything seen publicly has constant symbols and when it has constants, the generated code uses the constants.
hack everything.

GeneralRe: How much code is too much? Pin
Stefan_Lang10-Jan-20 1:48
mveStefan_Lang10-Jan-20 1:48 
GeneralRe: How much code is too much? Pin
honey the codewitch10-Jan-20 2:52
mvahoney the codewitch10-Jan-20 2:52 
GeneralRe: How much code is too much? Pin
John R. Shaw17-Jan-20 1:45
MemberJohn R. Shaw17-Jan-20 1:45 
GeneralRe: How much code is too much? Pin
honey the codewitch17-Jan-20 2:22
mvahoney the codewitch17-Jan-20 2:22 
AnswerRe: How much code is too much? Pin
Mark_Wallace9-Jan-20 20:33
MemberMark_Wallace9-Jan-20 20:33 
GeneralRe: How much code is too much? Pin
honey the codewitch9-Jan-20 21:10
mvahoney the codewitch9-Jan-20 21:10 
AnswerRe: How much code is too much? Pin
KarstenK9-Jan-20 20:38
mveKarstenK9-Jan-20 20:38 
GeneralRe: How much code is too much? Pin
honey the codewitch9-Jan-20 21:09
mvahoney the codewitch9-Jan-20 21:09 
AnswerRe: How much code is too much? Pin
Jon McKee9-Jan-20 20:44
professionalJon McKee9-Jan-20 20:44 
GeneralRe: How much code is too much? Pin
honey the codewitch9-Jan-20 21:08
mvahoney the codewitch9-Jan-20 21:08 
GeneralRe: How much code is too much? Pin
Jon McKee9-Jan-20 22:03
professionalJon McKee9-Jan-20 22:03 
GeneralRe: How much code is too much? Pin
honey the codewitch9-Jan-20 22:31
mvahoney the codewitch9-Jan-20 22:31 
GeneralRe: How much code is too much? Pin
Jon McKee9-Jan-20 23:18
professionalJon McKee9-Jan-20 23:18 
GeneralRe: How much code is too much? Pin
honey the codewitch9-Jan-20 23:22
mvahoney the codewitch9-Jan-20 23:22 
GeneralRe: How much code is too much? Pin
Jon McKee9-Jan-20 23:35
professionalJon McKee9-Jan-20 23:35 
GeneralRe: How much code is too much? Pin
honey the codewitch10-Jan-20 2:57
mvahoney the codewitch10-Jan-20 2:57 
GeneralRe: How much code is too much? Pin
Jon McKee10-Jan-20 1:00
professionalJon McKee10-Jan-20 1:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.