formal-languages

Formal grammar of XML

陌路散爱 提交于 2019-12-12 05:12:16
问题 Im trying to build small parser for XML files in C. I know, i could find some finished solutions but, i need just some basic stuff for embedded project. I`m trying to create grammar for describing XML without attributes, just tags, but it seems it is not working and i was not able to figure out why. Here is the grammar: XML : FIRST_TAG NIZ NIZ : VAL NIZ | eps VAL : START VAL END | STR | eps Here is part of C code that implement this grammar : void check() { getSymbol(); if( sym == FIRST_LINE

What is the intersection of two languages with different alphabets? [closed]

馋奶兔 提交于 2019-12-11 13:44:08
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I did some googling on this and nothing really definitive popped up. Let's say I have two languages A and B. A = { w is a subset of {a,b,c}* such that the second to the last character of w is b } B = { w is a subset of {b,d}* such that the last character is b } How would one define this? I think the alphabet

LR(1) - Items, Look Ahead

女生的网名这么多〃 提交于 2019-12-10 13:39:08
问题 I am having difficulties understanding the principle of lookahead in LR(1) - items. How do I compute the lookahead sets? Say for an example that I have the following grammar: S -> AB A -> aAb | b B -> d Then the first state will look like this: S -> .AB , {look ahead} A -> .aAb, {look ahead} A -> .b, {look ahead} I know what look aheads are, but I don't know how to compute them. I have googled for answers but couldn't find a webpage which explains this in a simple manner. Thanks in advance

PDA to accept a language of strings containing more a's than b's

纵饮孤独 提交于 2019-12-09 06:54:34
问题 Produce a PDA to recognise the following language : the language of strings containing more a's than b's I have been struggling with this question for several days now, I seem to have hit a complete mental block. Would any one be able to provide some guidance or direction to how I can solve this problem? 回答1: Your problem of "more a's than b's" can be solved by PDA. All you have to do is: When input is a and the stack is either empty or has an a on the top, push a on the stack; pop b , if b

NPDA with exactly 2 states that might need 3 transitions to final state

孤街醉人 提交于 2019-12-08 09:10:00
问题 Let's say we want to draw the transition graph with two states of a NPDA that accepts that language L. And let's also say that this NPDA will have exactly 2 states. My thinking on this would be to do everything in the first state then use the second state as the grand finale. Like so: But I'm not sure that the lambda transitions will result in q1 or if there is a better way to do this, which there likely is a better way since I'm trying to teach this to myself. Perhaps someone can get me back

Pumping lemma (Regular language)

余生颓废 提交于 2019-12-07 05:04:05
问题 I need some help with a pumping lemma problem. L = { {a,b,c}* | #a(L) < #b(L) < #c(L) } This is what I got so far: y = uvw is the string from the pumping lemma. I let y = abbc^n, n is the length from the pumping lemma. y is in L because the number of a:s is less than the number of b:s, and the number of b:s is less than the number of c:s. I let u = a, v = bb and w = c^n. |uv| < y, as stated in pumping lemma. If I "pump" (bb)^2 then i get y = abbbbc^n which violates the rule #b(L) < #c(L). Is

Recursive Sets vs Recursive Functions

偶尔善良 提交于 2019-12-06 09:49:20
问题 What s the difference between a recursive set and recursive function? 回答1: Recursive functions and recursive sets are terms used in computability theory. Wikipedia defines them as follows: A set of natural numbers is said to be a computable set (also called a decidable, recursive, or Turing computable set) if there is a Turing machine that, given a number n, halts with output 1 if n is in the set and halts with output 0 if n is not in the set. A function f from the natural numbers to

Shift-reduce: when to stop reducing?

做~自己de王妃 提交于 2019-12-05 11:41:16
I'm trying to learn about shift-reduce parsing. Suppose we have the following grammar, using recursive rules that enforce order of operations, inspired by the ANSI C Yacc grammar : S: A; P : NUMBER | '(' S ')' ; M : P | M '*' P | M '/' P ; A : M | A '+' M | A '-' M ; And we want to parse 1+2 using shift-reduce parsing. First, the 1 is shifted as a NUMBER. My question is, is it then reduced to P, then M, then A, then finally S? How does it know where to stop? Suppose it does reduce all the way to S, then shifts '+'. We'd now have a stack containing: S '+' If we shift '2', the reductions might

Pumping lemma (Regular language)

浪尽此生 提交于 2019-12-05 09:08:56
I need some help with a pumping lemma problem. L = { {a,b,c}* | #a(L) < #b(L) < #c(L) } This is what I got so far: y = uvw is the string from the pumping lemma. I let y = abbc^n, n is the length from the pumping lemma. y is in L because the number of a:s is less than the number of b:s, and the number of b:s is less than the number of c:s. I let u = a, v = bb and w = c^n. |uv| < y, as stated in pumping lemma. If I "pump" (bb)^2 then i get y = abbbbc^n which violates the rule #b(L) < #c(L). Is this right ? Am I on the "right path" ? Thanks The main idea of the pumping lemma is to tell you that

Recursive Sets vs Recursive Functions

北慕城南 提交于 2019-12-04 17:16:05
What s the difference between a recursive set and recursive function? Josef Grahn Recursive functions and recursive sets are terms used in computability theory. Wikipedia defines them as follows: A set of natural numbers is said to be a computable set (also called a decidable, recursive, or Turing computable set) if there is a Turing machine that, given a number n, halts with output 1 if n is in the set and halts with output 0 if n is not in the set. A function f from the natural numbers to themselves is a recursive or (Turing) computable function if there is a Turing machine that, on input n,