grammar

Converting grammar to Chomsky Normal Form?

这一生的挚爱 提交于 2019-11-30 12:42:31
Convert the grammar below into Chomsky Normal Form. Give all the intermediate steps. S -> AB | aB A -> aab|lambda B -> bbA Ok so the first thing I did was add a new start variable S0 so now I have S0 -> S S -> AB | aB A -> aab|lambda B -> bbA then I removed all of the lambda rules: S0 -> S S -> AB | aB | B A -> aab B -> bbA | bb Then I checked for S->S and A->B type rules which did not exist. And that was the answer I came up with, do I need to do anything further or did I do anything wrong? Wikipedia says: In computer science, a context-free grammar is said to be in Chomsky normal form if all

Converting ambiguous grammar to unambiguous

江枫思渺然 提交于 2019-11-30 12:33:59
问题 I did not understand how a unambiguous grammar is derived from a ambiguous grammar? Consider the example on site: Example. How was the grammar derived is confusing to me. Can anyone please guide me ? 回答1: The example has two grammars: Ambiguous: E → E + E | E ∗ E | (E) | a Unambiguous: E → E + T | T T → T ∗ F | F F → (E) | a The unambiguous grammar was derived from the ambiguous one using information not specified in the ambiguous grammar: The operator '*' binds tighter than the operator '+'.

Perl6 : What is the best way for dealing with very big files?

随声附和 提交于 2019-11-30 11:26:21
Last week I decided to give a try to Perl6 and started to reimplement one of my program. I have to say, Perl6 is so the easy for object programming, an aspect very painfull to me in Perl5. My program have to read and store big files, such as whole genomes (up to 3 Gb and more, See example 1 below) or tabulate data. The first version of the code was made in the Perl5 way by iterating line by line ("genome.fa".IO.lines). It was very slow and unsable for a correct execution time. my class fasta { has Str $.file is required; has %!seq; submethod TWEAK() { my $id; my $s; for $!file.IO.lines ->

ARM Unified Assembler Language grammar and parser?

狂风中的少年 提交于 2019-11-30 10:37:58
Is there a publicly available grammar or parser for ARM's Unified Assembler Language as described in ARM Architecture Reference Manual A4.2 This document uses the ARM Unified Assembler Language (UAL). This assembly language syntax provides a canonical form for all ARM and Thumb instructions. UAL describes the syntax for the mnemonic and the operands of each instruction. Simply I'm interested in the code for parsing mnemonic and the operands of each instruction. For example how you could define a grammar for these lines? ADC{S}{<c>}{<q>} {<Rd>,} <Rn>, <Rm>, <type> <Rs> IT{<x>{<y>{<z>}}}{<q>}

bison/yacc - limits of precedence settings

不打扰是莪最后的温柔 提交于 2019-11-30 09:55:31
问题 So I've been trying to parse a haskell-like language grammar with bison. I'll omit the standard problems with grammars and unary minus (like, what is (-5) from -5 and \x->x-5 or if a-b is a-(b) or apply a (-b) which itself can still be apply a \x->x-b , haha.) and go straight to the thing that suprised me. To simplify the whole thing to the point where it matters, consider following situation: expression: '(' expression ')' | expression expression /* lambda application */ | '\\' IDENTIFIER "-

How can I add parentheses as the highest level of precedence in a simple grammar?

别等时光非礼了梦想. 提交于 2019-11-30 09:34:18
问题 I'm trying to add 2 things to my grammar: Unary minus sign, i.e. '-', and Parentheses Here's my grammar so far: <comp> ::= <expr> | <comp> <op0> <expr> <expr> ::= <term> | <expr> <op1> <term> <term> ::= <darg> | <term> <op2> <darg> <darg> ::= <digit> | <darg> <digit> <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 <op0> ::= > | < | =< | => | = <op1> ::= + | - <op2> ::= * | / I've tried everything and can't figure this out. How can I make the unary minus sign be at the highest level of

I wish to create a system where I give a sentence and the system spits out sentences similar in meaning to the input sentence I gave

三世轮回 提交于 2019-11-30 09:25:27
This is an NLP problem and I was wondering how I should proceed. How difficult is the problem? Could I replace the word with synonyms and check that the grammar is correct? Replacing words with synonyms is probably the first thing to try, but be careful not to miss multiple words expressions and idioms. Also, make sure you choose a synonym with the same part of speech. they look for a good solution < ! > they view/stare/... for a good solution they work hard < ! > they job/task/… hard More complicated rephrasing is only possible if you use some level of grammatical analysis. You should at

ANTLR Parse tree modification

允我心安 提交于 2019-11-30 09:17:11
I'm using ANTLR4 to create a parse tree for my grammar, what I want to do is modify certain nodes in the tree. This will include removing certain nodes and inserting new ones. The purpose behind this is optimization for the language I am writing. I have yet to find a solution to this problem. What would be the best way to go about this? While there is currently no real support or tools for tree rewriting, it is very possible to do. It's not even that painful. The ParseTreeListener or your MyBaseListener can be used with a ParseTreeWalker to walk your parse tree. From here, you can remove nodes

Removing left recursion

百般思念 提交于 2019-11-30 08:41:32
问题 The following grammar has left recursion E= E+T|T T= T*F|F F= a|b|c How to remove it? Is there any general procedure for it? 回答1: Yes, there is a general procedure, see e.g. wikipedia. E = TE' E'= (e) | +TE' T = FT' T'= (e) | *FT' F = a | b | c It should be mentioned that this alters the associativity of + and * from left to right. That is, where before a + b + c was parsed as (a + b) + c , it is now parsed as a + (b + c) . This is not a problem for addition and multiplication, but it would

Construct grammar given the following language {a^n b^m | n,m = 0,1,2,…,n <= 2m} [closed]

我的未来我决定 提交于 2019-11-30 07:46:13
I just took my midterm but couldn't answer this question. Can someone please give a couple of examples of the language and construct a grammar for the language or at least show me how i will go about it? Also how to write grammar for L : L = {a n b m | n,m = 0,1,2,..., n <= 2m } ? Thanks in advance. Grijesh Chauhan How to write grammar for formal language? Before read my this answer you should read first: Tips for creating Context free grammars . Grammar for {a n b m | n,m = 0,1,2,..., n <= 2m } What is you language L = {a n b m | n,m = 0,1,2,..., n <= 2m } description? Language description :