What’s a valid left-hand-side expression in JavaScript grammar?

To concisely answer your question, everything beneath the LeftHandSideExpression production is a valid LeftHandSideExpression. I think the question you are really asking is: What is a valid LeftHandSideExpression and also assignable? The answer to that is anything that resolves to a Reference which is a well defined concept in the specification. In your example new … Read more

Which type of quotes we should use in css background url (“….”)? Single, double or no quote needed? [duplicate]

The URL bits of all three of your examples are valid CSS, according to the CSS specification. Note that the spec identifies some characters in a URL which will need to be escaped with a backslash if present in an unquoted URI, such as parentheses, commas, white space characters, single quotes (‘) and double quotes … Read more

How to identify whether a grammar is LL(1), LR(0) or SLR(1)?

To check if a grammar is LL(1), one option is to construct the LL(1) parsing table and check for any conflicts. These conflicts can be FIRST/FIRST conflicts, where two different productions would have to be predicted for a nonterminal/terminal pair. FIRST/FOLLOW conflicts, where two different productions are predicted, one representing that some production should be … Read more

Programmatically determine whether to describe an object with “a” or “an”?

I needed this for a C# project so here’s the C# port of the Python code mentioned above. Make sure to include using System.Text.RegularExpressions; in your source file. private string GetIndefiniteArticle(string noun_phrase) { string word = null; var m = Regex.Match(noun_phrase, @”\w+”); if (m.Success) word = m.Groups[0].Value; else return “an”; var wordi = word.ToLower(); foreach … Read more

What is a Context Free Grammar?

A context free grammar is a grammar which satisfies certain properties. In computer science, grammars describe languages; specifically, they describe formal languages. A formal language is just a set (mathematical term for a collection of objects) of strings (sequences of symbols… very similar to the programming usage of the word “string”). A simple example of … Read more

Build symbol table from grammar [closed]

A symbol table is just a versioned map of id’s to values. This is one solution, using a push and pop of scopes as the versioning mechanism — push a scope on entry of a scope defining rule and pop on exit. package net.certiv.metal.symbol; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; import net.certiv.metal.types.ScopeType; import net.certiv.metal.util.Strings; public … Read more

How to get all captures of subgroup matches with preg_match_all()? [duplicate]

Similar thread: Get repeated matches with preg_match_all() Check the chosen answer plus mine might be useful I will duplicate there: From http://www.php.net/manual/en/regexp.reference.repetition.php : When a capturing subpattern is repeated, the value captured is the substring that matched the final iteration. I personally give up and going to do this in 2 steps. EDIT: I see … Read more