context-free-grammar

How to determine if a context-free grammar describes a regular language?

旧时模样 提交于 2021-02-19 07:56:05
问题 Given an arbitrary context-free grammar, how can I check whether it describes a regular language? I'm not looking for exam "tricks". I'm looking for a foolproof mechanical test that I can code. If it helps, here's an example of a CFG that I might receive as an input. Specifically, notice that the answer must be much more complicated than just looking for left- or right-recursion, since the presence of another type of recursion does not automatically imply the grammar is irregular. S: A B C D

Finding First and Follow in Top Down Parsing

冷暖自知 提交于 2021-02-11 14:51:12
问题 I have a set of grammar and I need to find the First and Follow from it. So far I've managed to make the First, but now I'm confused as to how to make the Follow. The set of grammar that I tried to solve: E -> -E | (E) | VT T -> -E | ε V -> id L L -> (E) | ε The First that I've come up with. If something's wrong, please inform me: First (E) = -, (, id First (T) = -, ε First (V) = id First (L) = (, ε Here's the Follow that I've managed to gather up so far: Follow (E) = $, ) Follow (T) = $, )

AttributeError: 'MuParser' object has no attribute 'startRule'

我们两清 提交于 2021-02-11 06:44:54
问题 So I copied this code from an SO answer: grammar Mu; parse : block EOF ; block : stat* ; stat : assignment | if_stat | while_stat | log | OTHER {System.err.println("unknown char: " + $OTHER.text);} ; assignment : ID ASSIGN expr SCOL ; if_stat : IF condition_block (ELSE IF condition_block)* (ELSE stat_block)? ; condition_block : expr stat_block ; stat_block : OBRACE block CBRACE | stat ; while_stat : WHILE expr stat_block ; log : LOG expr SCOL ; expr : expr POW<assoc=right> expr #powExpr |

AttributeError: 'MuParser' object has no attribute 'startRule'

断了今生、忘了曾经 提交于 2021-02-11 06:44:08
问题 So I copied this code from an SO answer: grammar Mu; parse : block EOF ; block : stat* ; stat : assignment | if_stat | while_stat | log | OTHER {System.err.println("unknown char: " + $OTHER.text);} ; assignment : ID ASSIGN expr SCOL ; if_stat : IF condition_block (ELSE IF condition_block)* (ELSE stat_block)? ; condition_block : expr stat_block ; stat_block : OBRACE block CBRACE | stat ; while_stat : WHILE expr stat_block ; log : LOG expr SCOL ; expr : expr POW<assoc=right> expr #powExpr |

Correct way of getting type for a variable declaration in a typescript AST?

非 Y 不嫁゛ 提交于 2021-02-07 19:46:07
问题 Took a look at the declarationEmitter and for variable declarations, it has the function #emitVariableDeclaration which eventually calls #writeTypeOfDeclaration . This code does what is says---it takes a variable declaration and prints the variable and its type---this is exactly what I want to do. The problem is that when I replicate this code, the VariableDeclaration node has no symbol property...and thus, the type is always "any". Is there a missing step to initialize "symbols"? //sample

Troubles using Bison's recursive rules, and storing values using it

旧巷老猫 提交于 2021-01-29 20:02:40
问题 I am trying to make a flex+bison scanner and parser for Newick file format trees in order to do operations on them. The implemented grammar an explanation is based on a simplification of (labels and lengths are always of the same type, returned by flex) this example. This is esentially a parser for a file format which represents a tree with a series of (recursive) subtrees and/or leaves. The main tree will always end on ; and said tree and all subtrees within will contain a series of nodes

Creating a grammar out of a regular language

断了今生、忘了曾经 提交于 2021-01-29 16:03:41
问题 I have some problems to figure out a grammar for this special language, hope you could help: The language is: Σ={x,y,z} A = { w | w ∈ Σ^∗ ∧ |w|_x mod 2 >= |w|_y mod 2 } Because this one is so hard i tried first to put all properties together in one grammar, so |w|_x mod 2 >= |w|_y mod 2 and w ∈ Σ^∗ , but without getting all combination like cacbcacb etc What I get is something like: ccccc...caa...abcbbbcc and than i use ac -> ca etc to change the combination and to get every word I want. But

What is the NLTK FCFG grammar standard/specification?

无人久伴 提交于 2021-01-29 04:55:58
问题 NLTK (Natural Language Toolkit) lets you parse a FCFG grammar using nltk.FCFG.fromstring([grammar string here]). Where is the FCFG grammar format specification*? I googled it to death, but all I could find was this. *i.e. grammar language specification 回答1: From the demo: >>> from nltk import CFG >>> grammar = CFG.fromstring(""" ... S -> NP VP ... PP -> P NP ... NP -> Det N | NP PP ... VP -> V NP | VP PP ... Det -> 'a' | 'the' ... N -> 'dog' | 'cat' ... V -> 'chased' | 'sat' ... P -> 'on' |

LL(1) parser implemented with stack: how to build AST?

纵饮孤独 提交于 2021-01-02 06:08:25
问题 I am currently building a parser by hand. It is a LL(1) parser. At the moment, it is a great recognizer: its function parse(List tokens) decides whether or not tokens is a member of the language or not. Now, I want to build the corresponding AST for that input. However, I know how to implement it in a recursive descent way (already did it). That is, for the challenge, I implement my stack using a stack with the classical algorithm: next <- first token of the input stack <- START_SYMBOL do {

I can't find the leftmost and rightmost derivations of strings because there is no Non-terminal state linked to another non-terminal state

青春壹個敷衍的年華 提交于 2020-08-10 19:58:26
问题 The following grammar generates the language of regular expression S → A | B | C A → 0A1 | 1 | A1 B → 0B1 | 0 | 0B C → D10D D → empty | 0D | 1D Give leftmost and rightmost derivations of the following strings: 010100 000011 来源: https://stackoverflow.com/questions/62273171/i-cant-find-the-leftmost-and-rightmost-derivations-of-strings-because-there-is