grammar

Boost Spirit: parse boolean expression and reduce to canonical normal form

眉间皱痕 提交于 2021-02-19 08:21:21
问题 I want to parse a common Boolean with just or , and and not operators, which I think I have done using Boost Spirit below. In phase 2 (or perhaps part of the parsing itself), I wish to transform the AST of the Boolean to disjunctive canonical normal form, which essentially "flattens" the expression and removes all grouping operators. In one of my attempts, I created the Boost static_visitor below, named Transformer . I started by trying to eliminate double not operators by just assigning a

Boost Spirit: parse boolean expression and reduce to canonical normal form

狂风中的少年 提交于 2021-02-19 08:21:11
问题 I want to parse a common Boolean with just or , and and not operators, which I think I have done using Boost Spirit below. In phase 2 (or perhaps part of the parsing itself), I wish to transform the AST of the Boolean to disjunctive canonical normal form, which essentially "flattens" the expression and removes all grouping operators. In one of my attempts, I created the Boost static_visitor below, named Transformer . I started by trying to eliminate double not operators by just assigning a

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 |

SRGS - GRXML parsing via text input in java

半城伤御伤魂 提交于 2021-02-10 05:30:46
问题 I have an existing IVR voice application which uses SRGS .grxml grammar files. In the IVR our speech recognizer (Nuance) uses these grammars to take spoken input and return some values based on the particular grammar specified. I'm trying to find a java based tool which would use these same grammar files but allow me to send plain text in to be parsed according to the rules of the grammar. I've seen sphinx4 and they have a recognizer but it only uses microphone input from what I can tell. I'm

Chomsky Language Types

眉间皱痕 提交于 2021-02-05 16:43:05
问题 I'm trying to understand the four different Chomsky language types but the definitions that I have found don't really mean anything to me. I know type 0 is free grammar, type 1 is context sensitive, type 2 is context free whilst type 3 is regular. So, could someone please explain this and put it into context, thanks. 回答1: A language is the set of words that belong to that language. Many times, however, instead of listing each and every word in the language, it is enough to specify the set of

C++ How to specialize a template using vector<T>?

北战南征 提交于 2021-02-05 10:27:19
问题 Basicly ,I want to make a function behave differently for a vector(type) parameter and a non-vector type parameter . #include <vector> using namespace std; template <typename type> struct is_vector { static const bool value = false; }; template <typename type> struct is_vector<vector<type>> { static const bool value = true; }; template <typename type> type read() { if (is_vector<type>::value) { type vec(10); vec.front()=1;//left of '.front' must have class/struct/union return vec; } else {

C++ How to specialize a template using vector<T>?

孤街醉人 提交于 2021-02-05 10:27:00
问题 Basicly ,I want to make a function behave differently for a vector(type) parameter and a non-vector type parameter . #include <vector> using namespace std; template <typename type> struct is_vector { static const bool value = false; }; template <typename type> struct is_vector<vector<type>> { static const bool value = true; }; template <typename type> type read() { if (is_vector<type>::value) { type vec(10); vec.front()=1;//left of '.front' must have class/struct/union return vec; } else {