context-free-grammar

Are there tools to convert between ANTLR and other forms of BNF?

可紊 提交于 2019-12-01 00:34:59
问题 Are there any tools to convert ANTLR grammar syntax to and from other BNF syntaxes? There are several forms Backus-Naur Form (BNF, EBNF, ABNF, W3C-BNF, XBNF...) with specification, e.g. see this list. The ANTLR grammar syntax only seems to be described by examples. I know that ANTLR grammar files contain more than the specification of a context-free syntax, but you should be able to convert at least the common subset - has anyone done yet automatically? 回答1: Jakob wrote: The ANTLR grammar

What do square brackets in Java method declarations mean?

陌路散爱 提交于 2019-11-30 21:51:49
The grammar for method declarations in Java is something like the following: Java method declaration BNF: method_declaration ::= { modifier } type identifier "(" [ parameter_list ] ")" { "[" "]" } ( statement_block | ";" ) And I am wondering what do the square brackets mean. Can anyone give me an example? Is method declarations in Java looks like above (What about generics)? Where can I find complete and actual BNF grammar for Java? The square brackets are to indicate the method returns an array. For example, you can write a method that returns an array of int as: int method()[] { … } Many

Checking English Grammar with NLTK [closed]

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 20:39:32
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I'm starting to use the NLTK library, and I want to check whether a sentence in English is correct or not. Example: "He see Bob" - not

Extension to CFG, what is it?

耗尽温柔 提交于 2019-11-30 19:44:15
Consider the following extension to context-free grammars that permits rules to have in the left-hand side, one (or more) terminal on the right side of the non-terminal. That is, rules of the form: A b -> ... The right-hand side may be anything, like in context-free grammars. In particular, it is not required, that the right-hand side will have exactly the same terminal symbol at the end. In that case, this extension would be context-sensitive. But the terminal is not just a context. Sometimes, this terminal is called "pushback". Clearly, this is no longer CFG (type-2). It includes type-1. But

Converting grammar to Chomsky Normal Form?

这一生的挚爱 提交于 2019-11-30 12:42:31
Convert the grammar below into Chomsky Normal Form. Give all the intermediate steps. S -> AB | aB A -> aab|lambda B -> bbA Ok so the first thing I did was add a new start variable S0 so now I have S0 -> S S -> AB | aB A -> aab|lambda B -> bbA then I removed all of the lambda rules: S0 -> S S -> AB | aB | B A -> aab B -> bbA | bb Then I checked for S->S and A->B type rules which did not exist. And that was the answer I came up with, do I need to do anything further or did I do anything wrong? Wikipedia says: In computer science, a context-free grammar is said to be in Chomsky normal form if all

Converting ambiguous grammar to unambiguous

江枫思渺然 提交于 2019-11-30 12:33:59
问题 I did not understand how a unambiguous grammar is derived from a ambiguous grammar? Consider the example on site: Example. How was the grammar derived is confusing to me. Can anyone please guide me ? 回答1: The example has two grammars: Ambiguous: E → E + E | E ∗ E | (E) | a Unambiguous: E → E + T | T T → T ∗ F | F F → (E) | a The unambiguous grammar was derived from the ambiguous one using information not specified in the ambiguous grammar: The operator '*' binds tighter than the operator '+'.

bison/yacc - limits of precedence settings

不打扰是莪最后的温柔 提交于 2019-11-30 09:55:31
问题 So I've been trying to parse a haskell-like language grammar with bison. I'll omit the standard problems with grammars and unary minus (like, what is (-5) from -5 and \x->x-5 or if a-b is a-(b) or apply a (-b) which itself can still be apply a \x->x-b , haha.) and go straight to the thing that suprised me. To simplify the whole thing to the point where it matters, consider following situation: expression: '(' expression ')' | expression expression /* lambda application */ | '\\' IDENTIFIER "-

How can I add parentheses as the highest level of precedence in a simple grammar?

别等时光非礼了梦想. 提交于 2019-11-30 09:34:18
问题 I'm trying to add 2 things to my grammar: Unary minus sign, i.e. '-', and Parentheses Here's my grammar so far: <comp> ::= <expr> | <comp> <op0> <expr> <expr> ::= <term> | <expr> <op1> <term> <term> ::= <darg> | <term> <op2> <darg> <darg> ::= <digit> | <darg> <digit> <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 <op0> ::= > | < | =< | => | = <op1> ::= + | - <op2> ::= * | / I've tried everything and can't figure this out. How can I make the unary minus sign be at the highest level of

Is “regex” in modern programming languages really “context sensitive grammar”?

我只是一个虾纸丫 提交于 2019-11-30 08:22:26
问题 Over the years, "regex" pattern matching has been getting more and more powerful to the point where I wonder: is it really just context-sensitive-grammar matching? Is it a variation/extension of context-free-grammar matching? Where is it right now and why don't we just call it that instead of the old, restrictive "regular expression"? 回答1: In particular backreferences to capturing parentheses make regular expressions more complex than regular, context-free, or context-sensitive grammars. The

Construct grammar given the following language {a^n b^m | n,m = 0,1,2,…,n <= 2m} [closed]

我的未来我决定 提交于 2019-11-30 07:46:13
I just took my midterm but couldn't answer this question. Can someone please give a couple of examples of the language and construct a grammar for the language or at least show me how i will go about it? Also how to write grammar for L : L = {a n b m | n,m = 0,1,2,..., n <= 2m } ? Thanks in advance. Grijesh Chauhan How to write grammar for formal language? Before read my this answer you should read first: Tips for creating Context free grammars . Grammar for {a n b m | n,m = 0,1,2,..., n <= 2m } What is you language L = {a n b m | n,m = 0,1,2,..., n <= 2m } description? Language description :