lalr

How to solve a shift/reduce conflict?

蹲街弑〆低调 提交于 2019-12-04 04:40:51
I'm using CUP to create a parser that I need for my thesis. I have a shift/reduce conflict in my grammar. I have this production rule: command ::= IDENTIFIER | IDENTIFIER LPAREN parlist RPAREN; and I have this warning: Warning : *** Shift/Reduce conflict found in state #3 between command ::= IDENTIFIER (*) and command ::= IDENTIFIER (*) LPAREN parlist RPAREN under symbol LPAREN Now, I actually wanted it to shift so I'm pretty ok with it, but my professor told me to find a way to solve the conflict. I'm blind. I've always read about the if/else conflict but to me this doesn't seem the case. Can

Performance of parsers: PEG vs LALR(1) or LL(k)

心不动则不痛 提交于 2019-12-03 16:40:49
问题 I've seen some claims that optimized PEG parsers in general cannot be faster than optimized LALR(1) or LL(k) parsers. (Of course, performance of parsing would depend on a particular grammar.) I'd like to know if there are any specific limitations of PEG parsers, either valid in general or for some subsets of PEG grammars that would make them inferior to LALR(1) or LL(k) performance-wise. In particular, I'm interested in parser generators, but assume that their output can be tweaked for

Generate an AST in C++

北城余情 提交于 2019-12-03 08:48:59
I'm making an interpreter in C++, so far I've got my lexer to generate tokens. The problem is I'm not sure how to generate an "walk" a parse tree. I was thinking of making my parse tree using an array of arrays, but I'm not sure how to actually insert the tokens into the parse tree in the correct order. I'm not sure whether or not to go top-down, left-right or bottom-up, right-left. Can anyone provide me with a simple LALR(1) algorithm? I'm going to go against conventional wisdom here and say that you should build your AST manually with natural language-specific data-structures. A generic "AST

What advantages do LL parsers have over LR parsers?

≯℡__Kan透↙ 提交于 2019-12-02 14:30:58
What advantages do LL parsers have over LR parsers to warrant their relative popularity in today's parser generator tools ? According to Wikipedia , LR parsing appears to have advantages over LL: LR parsing can handle a larger range of languages than LL parsing, and is also better at error reporting, i.e. it detects syntactic errors when the input does not conform to the grammar as soon as possible. This is in contrast to an LL(k) (or even worse, an LL(*) parser) which may defer error detection to a different branch of the grammar due to backtracking, often making errors harder to localize

Can parser error recovery be guided automatically by the grammar?

ぐ巨炮叔叔 提交于 2019-11-30 14:17:00
问题 I'm writing an LALR parser generator as a pet project. I'm using the purple dragon book to help me with the design, and what I gather from it is that there are four methods of error recovery in a parser: Panic mode: Start dumping input symbols until a symbol pre-selected by the compiler designer is found Phrase-level recovery: Modify the input string into something that allows the current production to reduce Error productions: Anticipate errors by incorporating them into the grammar Global

Can parser error recovery be guided automatically by the grammar?

本秂侑毒 提交于 2019-11-30 09:55:44
I'm writing an LALR parser generator as a pet project. I'm using the purple dragon book to help me with the design, and what I gather from it is that there are four methods of error recovery in a parser: Panic mode: Start dumping input symbols until a symbol pre-selected by the compiler designer is found Phrase-level recovery: Modify the input string into something that allows the current production to reduce Error productions: Anticipate errors by incorporating them into the grammar Global correction: Way more complicated version of phrase-level recovery (as I understand it) Two of these

Examples of LL(1), LR(1), LR(0), LALR(1) grammars?

依然范特西╮ 提交于 2019-11-29 19:05:09
Is there a good resource online with a collection of grammars for some of the major parsing algorithms (LL(1), LR(1), LR(0), LALR(1))? I've found many individual grammars that fall into these families, but I know of no good resource where someone has written up a large set of example grammars. Does anyone know of such a resource? Parsing Techniques - A Practical Guide has several examples (i.e. probably half a dozen or so per type) of almost every type of grammar. You can purchase the 2nd edition book, although the 1st edition is available for free on the author's website in PDF form (near

Examples of LL(1), LR(1), LR(0), LALR(1) grammars?

六眼飞鱼酱① 提交于 2019-11-28 14:24:57
问题 Is there a good resource online with a collection of grammars for some of the major parsing algorithms (LL(1), LR(1), LR(0), LALR(1))? I've found many individual grammars that fall into these families, but I know of no good resource where someone has written up a large set of example grammars. Does anyone know of such a resource? 回答1: Parsing Techniques - A Practical Guide has several examples (i.e. probably half a dozen or so per type) of almost every type of grammar. You can purchase the

Are C# and Java Grammars LALR(x)?

孤街浪徒 提交于 2019-11-27 21:19:53
I wonder if C# and Java grammars are LALR(x)? If yes, what's the value of x? Edit: After accepting the true answer, I think it is better to change the Q in this way: Is there any LALR(x) parser that could parse current releases of Java (version 7) or C# (version 4)? If yes, what is the value of x? You can't ask this question without first designating a specific grammar for a langauge, as some grammars may be, and some may not. Perhaps you mean the Java grammar as published in recent Java specifications. Do you mean for Java 7? I'm not sure you can designate a specific grammar for C#, at least

Is C#'s lambda expression grammar LALR(1)?

纵饮孤独 提交于 2019-11-27 21:02:06
The question I wish to ask is succintly given in the title. Let me give an example of the grammar in question: identifier_list : identifier | identifier_list identifier; lambda_arguments : '(' identifier_list ')' | identifier; lambda : lambda_arguments '=>' expression Then we add in the normal C expression grammar- particularly, primary_expression : '(' expression ')' | identifier | lambda; The real question is, is this grammar LALR(1) parsable, i.e., capable of being parsed by automated parser generators? Or does it require a hand-rolled or GLR parser? Note that I wish to know specifically