Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

@siuying
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant