grammar

What is the easiest way of telling whether a BNF grammar is ambiguous or not?

梦想与她 提交于 2019-11-30 23:13:14
问题 Namely, is there a tool out there that will automatically show the full language for a given grammar, including highlighting ambiguities (if any)? 回答1: There might be some peculiarity about BNF-style grammars, but in general, deciding whether a given context-free grammar (such as BNF) is ambiguous is not possible. In short, there does not exist a tool because in general, that tool is mathematically impossible. There might be some special cases that could work for you, though. 回答2: In general,

Why is the separator in a TypeScript TypeMemberList semicolon as opposed to comma?

懵懂的女人 提交于 2019-11-30 22:20:19
问题 This is a typescript interface: interface A { l: { x: string; y:number } } But this (similar thing) produces an error: interface A { l: { x: string, y:number } } // => Error: ';' expected. On p.37 of the spec: http://www.typescriptlang.org/Content/TypeScript%20Language%20Specification.pdf I see that indeed it is specified that a ; should appear there, but coming from JavaScript the semicolon in the middle of the object-literal-ish thing looks wrong. Was this decision made to avoid ambiguity

Parsing a possibly nested braced item using a grammar

白昼怎懂夜的黑 提交于 2019-11-30 21:57:08
I am starting to write BibTeX parser. The first thing I would like to do is to parse a braced item. A braced item could be an author field or a title for example. There might be nested braces within the field. The following code does not handle nested braces: use v6; my $str = q:to/END/; author={Belayneh, M. and Geiger, S. and Matth{\"{a}}i, S.K.}, END $str .= chomp; grammar ExtractBraced { rule TOP { 'author=' <braced-item> .* } rule braced-item { '{' <-[}]>* '}' } } ExtractBraced.parse( $str ).say; Output : 「author={Belayneh, M. and Geiger, S. and Matth{\"{a}}i, S.K.},」 braced-item => 「

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

Is the Python's grammar LL(1)?

笑着哭i 提交于 2019-11-30 18:54:33
问题 Possible duplicate for this question however for me it's not specific enough. The python grammar is claimed to be LL(1), but I've noticed some expressions in the Python grammar that really confuse me, for example, the arguments in the following function call: foo(a) foo(a=a) corresponds to the following grammar: argument: ( test [comp_for] | test '=' test | '**' test | '*' test ) test appears twice in the first position of the grammar. It means that by only looking at test Python cannot

Parse comment line

ⅰ亾dé卋堺 提交于 2019-11-30 18:53:01
Given the following basic grammar I want to understand how I can handle comment lines. Missing is the handling of the <CR><LF> which usually terminates the comment line - the only exception is a last comment line before the EOF, e. g.: # comment abcd := 12 ; # comment eof without <CR><LF> grammar CommentLine1a; //========================================================== // Options //========================================================== //========================================================== // Lexer Rules //========================================================== Int : Digit+ ;

Prolog : Combining DCG grammars with other restrictions

倖福魔咒の 提交于 2019-11-30 18:28:13
I'm very impressed by Prolog's DCG and how quickly I can produce all the possible structures that fit a particular grammar. But I'd like to combine this search with other constraints. For example, define a complex grammar and ask Prolog to generate all sentences with not more than 10 words. Or all sentences that don't repeat the same word twice. Is it possible to add extra constraints like this to a DCG grammer? Or do I basically have to translate the DCG back into normal Prolog clauses and start modifying them? If you only want to see all sentences that are generated, it is very convenient to

Prolog : Combining DCG grammars with other restrictions

拟墨画扇 提交于 2019-11-30 16:51:48
问题 I'm very impressed by Prolog's DCG and how quickly I can produce all the possible structures that fit a particular grammar. But I'd like to combine this search with other constraints. For example, define a complex grammar and ask Prolog to generate all sentences with not more than 10 words. Or all sentences that don't repeat the same word twice. Is it possible to add extra constraints like this to a DCG grammer? Or do I basically have to translate the DCG back into normal Prolog clauses and

Programmatically derive a regular expression from a string

雨燕双飞 提交于 2019-11-30 15:12:06
I would like to input a string and return a regular expression that can be used to describe the string's structure. The regex will be used to find more strings of the same structure as the first. This is intentionally ambiguous because I will certainly miss a case that someone in the SO community will catch. Please post any and all possible ways to do this. The trivial answer, and probably not what you want, is: return the input string (with regex special characters escaped). That is always a regular expression that matches the string. If you wish certain structures to be identified, you have

I wish to create a system where I give a sentence and the system spits out sentences similar in meaning to the input sentence I gave

混江龙づ霸主 提交于 2019-11-30 14:10:55
问题 This is an NLP problem and I was wondering how I should proceed. How difficult is the problem? Could I replace the word with synonyms and check that the grammar is correct? 回答1: Replacing words with synonyms is probably the first thing to try, but be careful not to miss multiple words expressions and idioms. Also, make sure you choose a synonym with the same part of speech. they look for a good solution < ! > they view/stare/... for a good solution they work hard < ! > they job/task/… hard