Skip to content

Problem creating parser: "Could not insert reduce in action table for state 14, token -" #34

Description

@siuying

I was creating a parser:

Expression  ::= (<Orientation>)?
        (<Superview><Connection>)?
        <View> (<Connection><View>)*
        (<Connection><Superview>)?;
Connection  ::= '-' | '-' 'Number' '-';
View        ::= '[' 'Identifier' ']';
Superview   ::= '|';
Orientation ::= 'V:' | 'H:';

I encountered error when I try to create parsers (SLR/LR1/LALR1). ("Could not insert reduce in action table for state 14, token -")

Test Case:

    NSError* error;
    NSString* grammarPath = [[NSBundle mainBundle] pathForResource:@"VFL" ofType:@"grammar"];
    NSString* grammarString = [NSString stringWithContentsOfFile:grammarPath
                                                        encoding:NSUTF8StringEncoding
                                                           error:&error];
    CPGrammar* grammar = [[CPGrammar alloc] initWithStart:@"Expression"
                                           backusNaurForm:grammarString
                                                    error:&error];
    NSLog(@"grammar: %@", grammarString);

    CPTokeniser* tokenizer = [[CPTokeniser alloc] init];
    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"V:"]];
    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"H:"]];
    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"|"]];
    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"-"]];
    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@","]];

    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"("]];
    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@")"]];
    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"["]];
    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"]"]];

    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@">="]];
    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"<="]];
    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"=="]];
    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@">"]];
    [tokenizer addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"<"]];
    [tokenizer addTokenRecogniser:[CPIdentifierRecogniser identifierRecogniser]];
    [tokenizer addTokenRecogniser:[CPNumberRecogniser numberRecogniser]];
    [tokenizer addTokenRecogniser:[CPWhiteSpaceRecogniser whiteSpaceRecogniser]];

    CPTokenStream* stream = [tokenizer tokenise:@"H:|-50-[label]-50-|"];
    NSLog(@"stream: %@", stream);

    CPParser* parser = [[CPLALR1Parser alloc] initWithGrammar:grammar];
    CPSyntaxTree* ast = [parser parse:stream];
    NSLog(@"ast: %@", ast);

If I remove (<Connection><View>)* from the grammar it will work, I wonder can I rewrite the grammar such that I can make it work with CoreParse?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions