context-free-grammar

Detect tokens triggering rules in ANTLR4

雨燕双飞 提交于 2019-12-12 03:13:45
问题 I have this very simple grammar: grammar DLR; dlr : c 'sub' c ; c : CN | 'not' c | c 'and' c | c 'or' c ; CN : [A-Z]+ ; WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines When I generate the java code with antlr4 command, I got the java interface DLRBaseListener: public class DLRBaseListener implements DLRListener { @Override public void enterDlr(DLRParser.DlrContext ctx) { } @Override public void exitDlr(DLRParser.DlrContext ctx) { } @Override public void enterC(DLRParser.CContext ctx)

Regex-like syntax or CFG for generating cartesian product of concatenated string variables and literals

别说谁变了你拦得住时间么 提交于 2019-12-12 01:26:18
问题 I am writing a simulator, and would like to run studies by invoking a lot of instances of the simulator, using different sets of command-line arguments. I have read this question and several others, and they seem close, but I'm actually not looking for random data fulfilling a particular regex, I would like the set of all strings that match the regex. An example input file would look something like this: myprogram.{version1|version2} -arg1 {1|2|4} {-arg2|} or: myprogram.{0} -arg1 {1} {2} 0:

verifier of addition… not-regular, but is it context-free? [closed]

天大地大妈咪最大 提交于 2019-12-12 01:16:05
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . How can I show that the following language is (not) context-free? The argument that it's not regular goes as follows. I suspect this language to be context-free... The reason why I think this, is because L = {a n b m c {n+m} | n,m >= 0} is context-free. A proof for this can be found at http://cg.scs.carleton.ca/

Parse Tree Of Context Free Grammar

馋奶兔 提交于 2019-12-11 20:26:08
问题 I'm trying to figure out how to do parse trees correctly to show whether a grammar is ambiguous or not. my grammar is S -> xSy | ySx | SS | e any help would be great. thanks in advance below is my crack at it... S / \ / \ x y / \ / \ x x y y 回答1: As a hint, pretty much any grammar with a production of the form S → SS will be ambiguous, because if you want to produce three S nonterminals you can do so in two ways: S S / \ / \ S S S S / \ / \ S S S S Assuming those S's can actually produce

What is a Context Free Grammar?

前提是你 提交于 2019-12-11 14:52:35
问题 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

Regexp parse type-3 grammar

两盒软妹~` 提交于 2019-12-11 14:39:33
问题 Reading Chomsky hierarchy ... ... I know regexp can't parse type-2 grammars (context-free grammars), and also type-1 and type-0. Can regular expressions parse/catch ALL type-3 grammars (regular grammars)? 回答1: Yes, provided they support alternation, concatenation, and the Kleene star. This is the case for regexes of the PCRE (Perl/Java/JavaScript/PHP/...) type: alternation is implemented by ((...)|(...)) , concatenation by (...)(...) , and the Kleene star by (...)* . (There are a few other

Theory of computation - Using the pumping lemma for context free languages

房东的猫 提交于 2019-12-11 14:18:18
问题 I'm reviewing my notes for my course on theory of computation and I'm having trouble understanding how to complete a certain proof. Here is the question: A = {0^n 1^m 0^n | n>=1, m>=1} Prove that A is not regular. It's pretty obvious that the pumping lemma has to be used for this. So, we have |vy| >= 1 |vxy| <= p (p being the pumping length, >= 1) uv^ixy^iz exists in A for all i >= 0 Trying to think of the correct string to choose seems a bit iffy for this. I was thinking 0^p 1^q 0^p, but I

Issues of Error handling with ANTLR3

独自空忆成欢 提交于 2019-12-11 12:04:34
问题 I tried error reporting in following manner. @members{ public String getErrorMessage(RecognitionException e,String[] tokenNames) { List stack=getRuleInvocationStack(e,this.getClass().getName()); String msg=null; if(e instanceof NoViableAltException){ <some code> } else{ msg=super.getErrorMessage(e,tokenNames); } String[] inputLines = e.input.toString().split("\r\n"); String line = ""; if(e.token.getCharPositionInLine()==0) line = "at \"" + inputLines[e.token.getLine() - 2]; else if(e.token

Is there a regular language to represent regular expressions?

半城伤御伤魂 提交于 2019-12-11 07:48:27
问题 Specifically, I noticed that the language of regular expressions itself isn't regular. So, I can't use a regular expression to parse a given regular expression. I need to use a parser since the language of the regular expression itself is context free. Is there any way regular expressions can be represented in a way that the resulting string can be parsed using a regular expression? Note: My question isn't about whether there is a regexp to match the current syntax of regexes, but whether

Java CFG parser that supports ambiguities

橙三吉。 提交于 2019-12-11 06:16:14
问题 I'm looking for a CFG parser implemented with Java. The thing is I'm trying to parse a natural language. And I need all possible parse trees (ambiguity) not only one of them. I already researched many NLP parsers such as Stanford parser. But they mostly require statistical data (a treebank which I don't have) and it is rather difficult and poorly documented to adapt them in to a new language. I found some parser generators such as ANTRL or JFlex but I'm not sure that they can handle