context-free-grammar Questions

1

This is a Common Lisp data representation question. What is a good way to represent grammars? By "good" I mean a representation that is simple, easy to understand, and I can operate on the represe...
Putrescine asked 23/3, 2016 at 22:1

0

I recently finished writing a recursive-descent parser for this LL(1) grammar (which generates a tiny subset of XML): document ::= element EOF element ::= < elementPrefix elementPrefix ::= NAME...
Cheesy asked 24/10, 2016 at 20:37

1

Solved

I'm about to make a parser for a fictional subset of XML with the following EBNF grammar: DOCUMENT ::= ELEMENT ELEMENT ::= START_TAG (ELEMENT | DATA)* END_TAG | EMPTY_TAG START_TAG ::= < NAME A...
Multiplicand asked 13/10, 2016 at 3:38

1

TL;DR: How does one computationally model a grammar's productions such that an indefinite number of products exist for the same left hand side? I'm working on a project regarding formal language t...

1

import nltk from nltk.parse import ViterbiParser def pcfg_chartparser(grammarfile): f=open(grammarfile) grammar=f.read() f.close() return nltk.PCFG.fromstring(grammar) grammarp = pcfg_chartpa...
Mellott asked 30/1, 2016 at 14:50

1

I use CYK algorithm (already implemented it in Java) to see if a string recognized according to a specific grammar. Now I need to generate a parse tree for the string, is the a way to generate the ...
Genvieve asked 10/4, 2015 at 14:20

2

let's say I had the following context free grammar. S -> A A -> mAn A -> o How would this look in prolog? This is what I tried but it doesn't work. The second line seems to be the issue...
Ecospecies asked 30/11, 2015 at 19:26

6

Solved

It seems that recursive-descent parsers are not only the simplest to explain, but also the simplest to design and maintain. They aren't limited to LALR(1) grammars, and the code itself can be under...
Stellate asked 30/11, 2010 at 17:5

4

Solved

I have trouble understanding how to compute the lookaheads for the LR(1)-items. Lets say that I have this grammar: S -> AB A -> aAb | a B -> d A LR(1)-item is an LR(0) item with a look...
Airdrome asked 31/12, 2012 at 15:12

2

I am currently building a parser by hand. It is a LL(1) parser. At the moment, it is a great recognizer: its function parse(List tokens) decides whether or not tokens is a member of the language or...

3

Solved

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 lo...
Aurelia asked 7/6, 2015 at 18:52

1

Solved

I am reading The Java Language Specification 8. I am trying to understand Chapter 2. Grammars. Here's what I have already learned: Semantics: Semantics is the study of meaning. Meaning: Meani...
Nickens asked 17/5, 2015 at 7:23

8

Solved

I'm studying for my computing languages test, and there's one idea I'm having problems wrapping my head around. I understood that regular grammars are simpler and cannot contain ambiguity, but ca...
Mallory asked 18/2, 2009 at 3:46

1

Solved

CSG is similar to CFG but the reduce symbol is multiple. So, can I just use CFG parser to parse CSG with reducing production to multiple terminals or non-terminals? Like 1. S → a bc 2. S → a S B...

3

Solved

E -> E+T | E-T | T T -> T*F | T/F | F F -> i | (E) How can I modify this grammar to allow an exponentiation operation ^ so that I can write i+i^i*i? Since we know that order of operation...
Quail asked 18/6, 2013 at 7:24

2

Solved

I've been using the following data structure for the representation of propositional logic in Haskell: data Prop = Pred String | Not Prop | And Prop Prop | Or Prop Prop | Impl Prop Prop | E...

4

Solved

I am new to CFG's, Can someone give me tips in creating CFG that generates some language For example L = {am bn | m >= n} What I got is: So -> a | aSo | aS1 | e S1 -> b | bS1 | e bu...

1

Solved

Suppose I have the following CFG. A -> B | Cx | EPSILON B -> C | yA C -> B | w | z Now if I try to find FIRST(C) = FIRST(B) U FIRST(w) U FIRST(z) = FIRST(C) U FIRST(yA) U {w, z} Tha...
Gastineau asked 22/3, 2015 at 17:9

1

Solved

I have generated grammar from atis grammar, now I wanted to add some rules of my own especially terminals from sentence could I do that? import nltk grammar = nltk.data.load('grammars/large_gramma...
Surety asked 9/1, 2015 at 21:18

2

Solved

I'm working on a parser for C. I'm trying to find a list of all of the context-free derivations for C. Ideally it would be in BNF or similar. I'm sure such a thing is out there, but googling around...
Treadmill asked 19/3, 2013 at 6:0

2

Solved

I'm wondering if it's possible to use a CFG or PEG grammar as a basis for code completion directly without modification. I have heard that code completion is in IDE's is sometimes manipulated and m...

1

Solved

How can we know which of the following logical operations ( or, and, not ) in the bellow context free grammar have higher precedence? Is there a general approach to this kind of problems? X → X or...
Eudemonia asked 20/10, 2014 at 17:52

1

Solved

I wrote a project for parsing strings using context-free grammar in Instaparse (Clojure). Now I'd like to test several input-Strings for their parsing results. Some input strings might not fit into...

3

Solved

I'm trying to find a plain (i.e. non-formal) explanation of the 4 levels of formal grammars (unrestricted, context-sensitive, context-free, regular) as set out by Chomsky. It's been an age since I...

2

I am trying to figure out how to construct a CFG (context free grammar) based on a given regular expression. For example, a(ab)*(a|b) I think there is an algorithm to go through, but it is really c...
Lindo asked 3/5, 2014 at 19:13

© 2022 - 2024 — McMap. All rights reserved.