lexical-analysis

Tips for creating “Context Free Grammar”

荒凉一梦 提交于 2019-11-27 00:29:01
I am new to CFG's, Can someone give me tips in creating CFG that generates some language For example L = {a m b n | m >= n} What I got is: S o -> a | aS o | aS 1 | e S 1 -> b | bS 1 | e but I think this area is wrong, because there is a chance that the number of b 's can be greater than a 's. Grijesh Chauhan How to write CFG with example a m b n L = {a m b n | m >= n}. Language description: a m b n consist of a followed by b where number of a are equal or more then number of b . some example strings: {^, a, aa, aab, aabb, aaaab, ab......} So there is always one a for one b but extra a are

Practical difference between parser rules and lexer rules in ANTLR?

非 Y 不嫁゛ 提交于 2019-11-26 13:22:17
I understand the theory behind separating parser rules and lexer rules in theory, but what are the practical differences between these two statements in ANTLR: my_rule: ... ; MY_RULE: ... ; Do they result in different AST trees? Different performance? Potential ambiguities? Jen wrote : ... what are the practical differences between these two statements in ANTLR ... MY_RULE will be used to tokenize your input source. It represents a fundamental building block of your language. my_rule is called from the parser, it consists of zero or more other parser rules or tokens produced by the lexer. That

Python regular expressions - how to capture multiple groups from a wildcard expression?

 ̄綄美尐妖づ 提交于 2019-11-26 11:52:43
I have a Python regular expression that contains a group which can occur zero or many times - but when I retrieve the list of groups afterwards, only the last one is present. Example: re.search("(\w)*", "abcdefg").groups () this returns the list ('g',) I need it to return ('a','b','c','d','e','f','g',) Is that possible? How can I do it? Tomalak In addition to Douglas Leeder's solution , here is the explanation: In regular expressions the group count is fixed. Placing a quantifier behind a group does not increase group count (imagine all other group indexes increment because an eralier group

Practical difference between parser rules and lexer rules in ANTLR?

落爺英雄遲暮 提交于 2019-11-26 03:34:28
问题 I understand the theory behind separating parser rules and lexer rules in theory, but what are the practical differences between these two statements in ANTLR: my_rule: ... ; MY_RULE: ... ; Do they result in different AST trees? Different performance? Potential ambiguities? 回答1: Jen wrote : ... what are the practical differences between these two statements in ANTLR ... MY_RULE will be used to tokenize your input source. It represents a fundamental building block of your language. my_rule is