grammar

How to determine whether a language is LL(1) LR(0) SLR(1)

放肆的年华 提交于 2019-11-28 05:23:35
Is there a simple way to determine whether a grammar is LL(1), LR(0), SLR(1)... just from looking on the grammar without doing any complex analysis? For instance: To decide whether a BNF Grammar is LL(1) you have to calculate First and Follow sets - which can be time consuming in some cases. Has anybody got an idea how to do this faster? Any help would really be appreciated! First off, a bit of pedantry. You cannot determine whether a language is LL(1) from inspecting a grammar for it, you can only make statements about the grammar itself. It is perfectly possible to write non-LL(1) grammars

Grammar inference library?

余生长醉 提交于 2019-11-28 05:09:02
问题 What are the best (or any) open source libraries for regular or context-free grammar inference from a set of examples believed to be generated by a common grammar? I'd prefer a good library in Java, Python or Ruby, but of course beggars can't be choosers. I did some googling, but couldn't find any actual implementations, though I did find plenty of interesting references. This library looks interesting, but I couldn't find it available for download anywhere. Edit (2011-11-14): For clarity

How to match any symbol in ANTLR parser (not lexer)?

痞子三分冷 提交于 2019-11-28 04:06:14
问题 How to match any symbol in ANTLR parser (not lexer)? Where is the complete language description for ANTLR4 parsers? UPDATE Is the answer is "impossible"? 回答1: You first need to understand the roles of each part in parsing: The lexer: this is the object that tokenizes your input string. Tokenizing means to convert a stream of input characters to an abstract token symbol (usually just a number). The parser: this is the object that only works with tokens to determine the structure of a language.

Is HTML a context-free language?

一世执手 提交于 2019-11-28 03:39:52
Reading some related questions made me think about the theoretical nature of HTML. I'm not talking about XHTML-like code here. I'm talking about stuff like this crazy piece of markup, which is perfectly valid HTML(!) <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html<head> <title// <p ltr<span id=p></span</p> </> So given the enormous complexity that SGML injects here, is HTML a context-free language? Is it a formal language anyway? With a grammar? What about HTML5? I'm new to the concept of formal languages, so please bear with me. And yes, I have read the wikipedia article ;) Context

C11 grammar ambiguity between _Atomic type specifier and qualifier

故事扮演 提交于 2019-11-28 03:02:27
问题 I'm trying to write a lex/yacc grammar for C11 based off of N1570. Most of my grammar is copied verbatim from the informative syntax summary, but some yacc conflicts arose. I've managed to resolve all of them except for one: there seems to be some ambiguity between when '_Atomic' is used as a type specifier and when it's used as a type qualifier. In the specifier form, _Atomic is followed immediately by parentheses, so I'm assuming it has something to do with C's little-used syntax which

What is a Context Free Grammar?

大兔子大兔子 提交于 2019-11-28 02:49:48
Can someone explain to me what a context free grammar is? After looking at the Wikipedia entry and then the Wikipedia entry on formal grammar, I am left utterly and totally befuddled. Would someone be so kind as to explain what these things are? I am wondering this because I wish to investigate parsing, and also on the side, the limitation of a regex engine. I'm not sure if these terms are directly programming related, or if they are related more to linguistics in general. If that is the case, I apologize, perhaps this could be moved if so? aegrisomnia A context free grammar is a grammar which

Programmatically determine whether to describe an object with “a” or “an”?

﹥>﹥吖頭↗ 提交于 2019-11-27 23:44:35
I have a database of nouns (ex "house", "exclamation point", "apple") that I need to output and describe in my application. It's hard to put together a natural-sounding sentence to describe an item without using "a" or "an" - "a house is BIG", "an exclamation point is SMALL", etc. Is there any function, library, or hack i can use in PHP to determine whether it is more appropriate to describe any given noun with A or AN? What you want is to determine the appropriate indefinite article. Lingua::EN::Inflect is a Perl module that does an great job. I've extracted the relevant code and pasted it

Regex Grammar

一曲冷凌霜 提交于 2019-11-27 18:49:03
Is there any BNF grammar for regular expression? VonC You can see one for Perl regexp (displayed a little more in detail here , as posted by edg ) To post them on-site: CMPT 384 Lecture Notes Robert D. Cameron November 29 - December 1, 1999 BNF Grammar of Regular Expressions Following the precedence rules given previously, a BNF grammar for Perl-style regular expressions can be constructed as follows. <RE> ::= <union> | <simple-RE> <union> ::= <RE> "|" <simple-RE> <simple-RE> ::= <concatenation> | <basic-RE> <concatenation> ::= <simple-RE> <basic-RE> <basic-RE> ::= <star> | <plus> |

Repository of BNF Grammars?

送分小仙女□ 提交于 2019-11-27 18:01:43
Is there a place I can find Backus–Naur Form or BNF grammars for popular languages? Whenever I do a search I don't turn up much, but I figure they must be published somewhere. I'm most interested in seeing one for Objective-C and maybe MySQL. Gene T you have to search on tools used to create grammars: "lex/yacc grammar", "antlr grammar" "railroad diagram" http://www.antlr3.org/grammar/list.html Here's some grammar files objective-c http://www.omnigroup.com/mailman/archive/macosx-dev/2001-March/022979.html http://www.cilinder.be/docs/next/NeXTStep/3.3/nd/Concepts/ObjectiveC/B_Grammar/Grammar

How to identify whether a grammar is LL(1), LR(0) or SLR(1)?

99封情书 提交于 2019-11-27 16:54:33
How do you identify whether a grammar is LL(1), LR(0), or SLR(1)? Can anyone please explain it using this example, or any other example? X → Yz | a Y → bZ | ε Z → ε To check if a grammar is LL(1), one option is to construct the LL(1) parsing table and check for any conflicts. These conflicts can be FIRST/FIRST conflicts, where two different productions would have to be predicted for a nonterminal/terminal pair. FIRST/FOLLOW conflicts, where two different productions are predicted, one representing that some production should be taken and expands out to a nonzero number of symbols, and one