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

Open
siuying opened this Issue Feb 23, 2014 · 0 comments

Comments

Projects
None yet
1 participant
@siuying
Contributor

siuying commented Feb 23, 2014

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment