grammar

Is Rust's syntactical grammar context-free or context-sensitive?

家住魔仙堡 提交于 2019-12-23 12:54:51
问题 The syntactical grammar of hardly any programming language is regular, as they allow arbitrarily deeply nested parenthesis. Rust does, too: let x = ((((())))); But is Rust's syntactical grammar at least context-free? If not, what element makes the grammar context-sensitive? Or is the grammar even recursively enumerable, like C++'s syntactical grammar? Related : Is Rust's lexical grammar regular, context-free or context-sensitive? 回答1: Rust includes a macro processor, whose operation is highly

boolean and arithmetic expression grammar in ANTLR

夙愿已清 提交于 2019-12-23 11:11:47
问题 I'm trying to write a grammar for arithmetic and boolean expressions. I don't understand what I'm doing wrong. For my grammar, ANTLR says: [fatal] rule logic_atom has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option. But I can't do a left-factoring. And I don't want to touch arith_expr , because for this I have a code. Error in logic_atom : LBR logic_expr RBR | cmp_expr ; My

When is white space really important in Perl6 grammars?

早过忘川 提交于 2019-12-23 10:54:12
问题 can someone clarify when white space is significant in rules in Perl 6 grammars? I am learning some by trial and error, but can't seem to find the actual rules in the documentation. Example 1: rule number { <pm> \d '.'? \d*[ <pm> \d* ]? } rule pm { [ '+' || '-' ]? } Will match a number 2.68156e+154 , and not care about the spaces that are present in rule number . However, if I add a space after \d* , it will fail. (i.e. <pm> \d '.'? \d* [ <pm> \d* ]? fails). Example 2: If I am trying to find

<.ident> function/capture in perl6 grammars

六眼飞鱼酱① 提交于 2019-12-23 10:25:57
问题 While reading the Xml grammar for perl6 (https://github.com/supernovus/exemel/blob/master/lib/XML/Grammar.pm6), I am having some difficulties understanding the following token. token pident { <!before \d> [ \d+ <.ident>* || <.ident>+ ]+ % '-' } More specifically <.ident>, there are no other definitions of ident, so I am assuming it is a reserved term. Though i cant find find a proper definition on perl6.org. Does anyone know what this means? 回答1: Does anyone know what [ <.ident> ] means?

Colour instead of color?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 06:56:51
问题 I'm working on a game engine in C++ and I have methods like setColour and things that use British grammar. While I was thinking how C++ compilers mostly use the English language (correct me if I'm wrong) and how most APIs use American grammar, should I go with the flow and continue the unofficial standard in the grammar programmer high council or be a rebel? I'm not sure which. 回答1: You should use the American spelling of color . 99% of code out there uses this, even including much of the

NLTK Chart Parser is not printing [duplicate]

余生长醉 提交于 2019-12-23 04:28:53
问题 This question already has answers here : Python and NLTK: How to analyze sentence grammar? (2 answers) Closed 2 years ago . Here is the code: groucho_grammar = nltk.CFG.fromstring(""" S -> V NP PP CONJ V NP PP PP -> PRP NP NP -> Det N | PRP N |DET ADJ CONJ ADJ N P Det -> 'a' | 'every' | 'all' N -> 'work' | 'Word Document' | 'results' | 'step' ADJ -> 'intermediate' | 'final' V -> 'Describe' | 'present' P -> 'of' | 'in' CONJ -> 'and' PRP -> 'your' """) sent = ['Describe', 'every', 'step' ,'of',

xtext: expression/factor/term grammar

怎甘沉沦 提交于 2019-12-23 02:01:29
问题 This has got to be one of those well-known examples that's somewhere on the internet, but I can't seem to find it. I'm trying to learn XText and I figured a calculator expression parser would be a good start. But I'm getting syntax errors in my grammar: Expression: Term (('+'|'-') Term)*; Term: Factor (('*'|'/') Factor)*; Factor: number=Number | variable=ID | ('(' expression=Expression ')'); I get this error in the Expression and Term lines: Multiple markers at this line - Cannot change type

CFG for python-style tuples

蹲街弑〆低调 提交于 2019-12-23 00:24:47
问题 After having read for the zillionth time a question about "How do I parse HTML with Regex" on Stackoverflow, I got myself interested again in grammars, grabbed my university scripts and after a few minutes I wondered how I've ever passed my exams. As a simple (well, "simple" I expected it to be) exercise I tried to write a CFG that produces valid python tuples (for simplicity's sake only using the identifiers a , b and c ). After some good time I now came up with this: G = ( {Tuple, TupleItem

Access “this” inside of static codeblocks

半世苍凉 提交于 2019-12-22 17:04:11
问题 Lately I've found myself writing alot of classes similar to: public class MyTypeCodes { public static MyTypeCode E = new MyTypeCode{ Desc= "EEE", Value = "E" }; public static MyTypeCode I = new MyTypeCode { Desc= "III", Value = "I" }; private static readonly Lazy<IEnumerable<MyTypeCode>> AllMyTypeCodes = new Lazy<IEnumerable<MyTypeCode>>(() => { var typeCodes = typeof(MyTypeCodes) .GetFields(BindingFlags.Static | BindingFlags.Public) .Where(x => x.FieldType == typeof (MyTypeCode)) .Select(x =

Why are these conflicts appearing in the following yacc grammar for XML

隐身守侯 提交于 2019-12-22 13:07:51
问题 I have the following XML grammar which works fine: program : '<' '?'ID attribute_list '?''>' root ; root : '<' ID attribute_list '>' node_list '<''/'ID'>' ; node_list : node_s | node_list node_s ; node_s : node | u_node | ID ; node : '<' ID attribute_list '/''>' ; u_node :'<' ID attribute_list '>' node_list '<''/'ID'>' |'<' ID attribute_list '>' '<''/'ID'>' ; attribute_list : attributes | ; attributes : attribute | attributes attribute ; attribute : ID ASSIGNOP '"' ID '"' | ID ASSIGNOP '"'