grammar

Context-free grammars versus context-sensitive grammars?

怎甘沉沦 提交于 2019-11-29 19:14:24
Can someone explain to me why grammars [context-free grammar and context-sensitive grammar] of this kind accepts a String? What I know is Context-free grammar is a formal grammar in which every production(rewrite) rule is a form of V→w Where V is a single nonterminal symbol and w is a string of terminals and/or non-terminals. w can be empty Context-sensitive grammar is a formal grammar in which left-hand sides and right hand sides of any production (rewrite) rules may be surrounded by a context of terminal and nonterminal symbols. But how can i explain why these grammar accepts a String? An

Examples of LL(1), LR(1), LR(0), LALR(1) grammars?

依然范特西╮ 提交于 2019-11-29 19:05:09
Is there a good resource online with a collection of grammars for some of the major parsing algorithms (LL(1), LR(1), LR(0), LALR(1))? I've found many individual grammars that fall into these families, but I know of no good resource where someone has written up a large set of example grammars. Does anyone know of such a resource? Parsing Techniques - A Practical Guide has several examples (i.e. probably half a dozen or so per type) of almost every type of grammar. You can purchase the 2nd edition book, although the 1st edition is available for free on the author's website in PDF form (near

Difference between an LL and Recursive Descent parser?

房东的猫 提交于 2019-11-29 18:41:36
I've recently being trying to teach myself how parsers (for languages/context-free grammars) work, and most of it seems to be making sense, except for one thing. I'm focusing my attention in particular on LL(k) grammars , for which the two main algorithms seem to be the LL parser (using stack/parse table) and the Recursive Descent parser (simply using recursion). As far as I can see, the recursive descent algorithm works on all LL(k) grammars and possibly more, whereas an LL parser works on all LL(k) grammars. A recursive descent parser is clearly much simpler than an LL parser to implement,

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

时光毁灭记忆、已成空白 提交于 2019-11-29 17:05:18
问题 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

ANTLR4 mutual left recursion grammar

房东的猫 提交于 2019-11-29 16:44:31
I have read many questions here on StackOverflow about mutual left-recursion issues in LL(k) parsers. I found the general algorithm for removing left-recursion: A : Aa | b ; becomes A : bR ; R : (aA)? ; However, I cannot figure out how to apply it to my situation. I have left_exp: IDENT | exp DOT IDENT ; exp : handful | of | other rules | left_exp ; The "handful of other rules" all contain regular recursion, such as exp : exp PLUS exp , etc. and have no issues. The issue is with left_exp and exp being mutually recursive. I thought about just adding IDENT and exp DOT IDENT to the exp rules, but

Is there a way to generate unit test to test my grammar

点点圈 提交于 2019-11-29 16:00:26
I created my grammar using antlr4 but I want to test robustess is there an automatic tool or a good way to do that fast Thanks :) The only way I found to create unit tests for a grammar is to create a number of examples from a written spec of the given language. This is neither fast, nor complete, but I see no other way. You could be tempted to create test cases directly from the grammar (writing a tool for that isn't that hard). But think a moment about this. What would you test then? Your unit tests would always succeed, unless you use generated test cases from an earlier version of the

Island grammar antlr3

大城市里の小女人 提交于 2019-11-29 15:44:06
What are and how to use the "island grammar" in antlr3? An island grammar is one that treats most of a language as a blob of text ("water") and picks out the part of the langauge of interest to parse using grammar rules ("island"). For instance, you might choose to build an island grammar to pick out all the expressions found in a C# program, and ignore the variable/method/class declarations and the statement syntax (if, while, ...). The real question is, "Should you use island grammars at all?". The positive benefits: you don't have to write a full, complete grammar for the language you want

Can we define a non context-free grammar with ANTLR?

夙愿已清 提交于 2019-11-29 15:19:55
I'm pretty new to ANTLR4 and now I'm trying to undertand which kind of grammars we might define with it. As far as I got, there're two kind of rules in ANTLR: parser rules (lower case words) and lexer rules (upper-case words). Example: grammar Test; init: prog(','prog)*; prog: A | prog ; A: [a-z]+; Form the grammar production rule standpoint I would say that parser rules are NON-TERMINAL symbols which can be replaced with a sequence of tokens defined by a lexer rules. So, it's perfectly clear that the grammar is context-free by the definition . The alpahbet of the language generated by the

ARM Unified Assembler Language grammar and parser?

回眸只為那壹抹淺笑 提交于 2019-11-29 15:18:15
问题 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

ANTLR Grammar for expressions

牧云@^-^@ 提交于 2019-11-29 15:10:17
I'm trying to implement a expression handling grammar (that deals with nested parenthesis and stuff). I have the following so far, but they can't deal with some cases (successful/failure cases appear after the following code block). Anyone know what's going on? Note: The varname += and varname = stuff are just some additional AST generation helper stuff in XText. Don't worry about them for now. ... NilExpression returns Expression: 'nil'; FalseExpression returns Expression: 'false'; TrueExpression returns Expression: 'true'; NumberExpression returns Expression: value=Number; StringExpression