formal-languages

Distance between regular expression

前提是你 提交于 2019-12-21 04:10:14
问题 Can we compute a sort of distance between regular expressions ? The idea is to mesure in which way two regular expression are similar. 回答1: There are a few of metrics you could use: The length of a valid match. Some regexs have a fixed size, some an upper limit and some a lower limit. Compare how similar their lengths or possible lengths are. The characters that match. Any regex will have a set of characters a match can contain (maybe all characters). Compare the set of included characters.

Is JavaScript a Context Free Language?

半腔热情 提交于 2019-12-20 12:38:50
问题 This article on how browsers work explains how CSS is context free, while HTML is not . But what about JavaScript, is JavaScript context free? I am learning about CFG and formal proofs, but am a long way away from understanding how to figure this out. Does anyone know if JavaScript is context free or not? 回答1: No, JavaScript is not a context-free language. It is very close to one, and the ECMAScript 5 specification does indeed use a context-free grammar 1 to describe the language's syntax

Where can I find a formal grammar for MATLAB?

爷,独闯天下 提交于 2019-12-20 09:06:51
问题 I would like to write a lexer generator to convert a basic subset of the MATLAB language to C#, C++, etc. To help me do this, I would like to find a document containing the formal grammar for MATLAB. Having spent a bit of time investigating this, it seems that Mathworks do not provide one. Does anyone know where I could find such a document? 回答1: Excellent opportunity to write your own formal grammar :) If you should choose to write the grammer your self, I can recommend BNFC which can take a

Creating a separate “boolean expression” rule for a dynamic language

╄→гoц情女王★ 提交于 2019-12-17 20:56:03
问题 I'm creating a grammar in Bison for a simple dynamically-typed language. I have a "general" expression rule, which is somewhat akin to the concept of an rvalue in C; expressions appear on the right-hand side of an assignment, they can also be sent to functions as arguments etc. A greatly simplified version of the rule follows: constantExpression : TOK_INTEGER_CONSTANT | TOK_FLOAT_CONSTANT | stringLiteral ; expression : constantExpression | identifier | booleanExpression | booleanExpression

Example of Non-Linear, UnAmbiguous and Non-Deterministic CFL?

可紊 提交于 2019-12-17 06:51:42
问题 In the Chomsky classification of formal languages, I need some examples of Non-Linear, Unambiguous and also Non-Deterministic Context-Free-Language(N-CFL)? Linear Language : For which Linear grammar is possible( ⊆ CFG) e.g. L 1 = {a n b n | n ≥ 0 } Deterministic Context Free Language(D-CFG) : For which Deterministic Push-Down-Automata(D-PDA) is possible e.g. L 2 = {a n b n c m | n ≥ 0, m ≥ 0 } L 2 is unambiguous. A CF grammar that is not linear is nonlinear. L nl = {w: n a (w) = n b (w)} is

Example of Non-Linear, UnAmbiguous and Non-Deterministic CFL?

别等时光非礼了梦想. 提交于 2019-12-17 06:51:18
问题 In the Chomsky classification of formal languages, I need some examples of Non-Linear, Unambiguous and also Non-Deterministic Context-Free-Language(N-CFL)? Linear Language : For which Linear grammar is possible( ⊆ CFG) e.g. L 1 = {a n b n | n ≥ 0 } Deterministic Context Free Language(D-CFG) : For which Deterministic Push-Down-Automata(D-PDA) is possible e.g. L 2 = {a n b n c m | n ≥ 0, m ≥ 0 } L 2 is unambiguous. A CF grammar that is not linear is nonlinear. L nl = {w: n a (w) = n b (w)} is

Tips for creating “Context Free Grammar”

人盡茶涼 提交于 2019-12-17 06:31:14
问题 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. 回答1: 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: {^

How to prove left-recursive grammar is not in LL(1) using parsing table

血红的双手。 提交于 2019-12-14 00:32:48
问题 I have a grammar and would like to prove that it is not in LL(1): S->SA|A A->a As it is a left-recursive grammarm, to find the first and follow sets I eliminated the left recursion and got: S->AS' S'->AS'|Empty A->a first of A={a} follow of S={$} first of s'={a,ε} follow of S'={$} first of S={a} follow of A={a,$} But when I filled in the parsing table, I did not get any cell with 2 entries. Then how is one to prove that the given grammar is not in LL(1)? 回答1: First of all you are finding

Union in context-free languages

我的未来我决定 提交于 2019-12-13 08:35:40
问题 Is the union of a collection of context-free languages always context-free ? Justify your answer ..... I know that the answer is yes, but how can I prove it ? 回答1: To show that the finite union of context-free languages is context-free you just have to build a context-free grammar for the union language, exactly as you would do to prove that the union of two context-free languages is context-free. If G1,...,GN are the context-free grammars for the N context-free languages you have, rename all

Checking if a string consists of balanced parenthesis

一个人想着一个人 提交于 2019-12-12 08:24:38
问题 I wrote the following program to check strings for balanced parenthesis: isBalanced xs = isBalanced' xs [] isBalanced' [] [] = True isBalanced' [] _ = False isBalanced' ('(':xs) ys = isBalanced' xs (')':ys) isBalanced' ('[':xs) ys = isBalanced' xs (']':ys) isBalanced' ('{':xs) ys = isBalanced' xs ('}':ys) isBalanced' _ [] = False isBalanced' (x:xs) (y:ys) = (x == y) && (isBalanced' xs ys) Here is some example data: positives = [ isBalanced "", isBalanced "()", isBalanced "[]", isBalanced "{}"