grammar

Generate BNF diagrams from an antlr grammar?

家住魔仙堡 提交于 2019-12-10 10:41:34
问题 I may well be asking something not achievable here.. Maybe someone can point out either (a) What would be some steps (/tools?) to at least partially achieve creation of bnf diagrams from a (rather complex) antlr grammar (b) why (if it were the case) this simply can not be achieved. E.g. maybe since antlr is extended BNF and its recursive structure differs from bnf requirements.. Along those lines. 回答1: ANTLRWorks 1 works for generating diagrams, one at a time, for rule. for v4, ANTLRWorks 2

Recognize A^n B^n language in Prolog with no arithmetics

可紊 提交于 2019-12-10 10:07:55
问题 How to recognize A^n B^n language in Prolog without arithmetics and for any A, B where A != B? With known A = a and B = b we could write % For each 'a' save 'b' in a list, then check % whether constructed list is equal to the rest of input list anbn(L) :- anbn(L, []). anbn(L, L). anbn([a|L],A) :- anbn(L, [b|A]). For any A and B I was thinking of a solution starting with anbn(L) :- anbn(L, []). anbn([H|L],[]) :- anbn(L,[H]). % save an element anbn([H|L], [H|A]) :- anbn(L, [H,H|A]). % make sure

Perl 6 Grammar doesn't match like I think it should

…衆ロ難τιáo~ 提交于 2019-12-10 04:26:46
问题 I'm doing Advent of Code day 9: You sit for a while and record part of the stream (your puzzle input). The characters represent groups - sequences that begin with { and end with } . Within a group, there are zero or more other things, separated by commas: either another group or garbage. Since groups can contain other groups, a } only closes the most-recently-opened unclosed group - that is, they are nestable. Your puzzle input represents a single, large group which itself contains many

Call Method from Constructor: Error: Uncaught TypeError: undefined is not a function

柔情痞子 提交于 2019-12-10 03:36:44
问题 Task: I need to build a class in Typescript that calls some of it's own methods in it's own Constructor. Problem: The Actual Code that the following Sample Code represents will Compile Successfully, but upon testing in the Javascript Console, it does not. Sample: export class volumeEQ { constructor(ctx:any) { this.ctx = ctx; // Audio context saved into member variable of class this.setupAudioNodes(); // Sets up nodes made out of audio } setupAudioNodes() { this.sourceNode.connect(this.ctx

Why is this c# snippet legal?

余生长醉 提交于 2019-12-10 02:41:55
问题 Silly question, but why does the following line compile? int[] i = new int[] {1,}; As you can see, I haven't entered in the second element and left a comma there. Still compiles even though you would expect it not to. 回答1: I suppose because the ECMA 334 standard say: array-initializer: { variable-initializer-list(opt) } { variable-initializer-list , } variable-initializer-list: variable-initializer variable-initializer-list , variable-initializer variable-initializer: expression array

What are the rules of semicolon inference?

无人久伴 提交于 2019-12-10 02:02:30
问题 Kotlin provides “semicolon inference”: syntactically, subsentences (e.g., statements, declarations etc) are separated by the pseudo-token SEMI, which stands for “semicolon or newline”. In most cases, there’s no need for semicolons in Kotlin code. This is what the grammar page says. This seems to imply that there is a need to specify semicolons in some cases, but it doesn't specify them, and the grammar tree below doesn't exactly make this obvious. Also I have suspicions that there are some

recognize Ruby code in Treetop grammar

…衆ロ難τιáo~ 提交于 2019-12-09 16:39:08
问题 I'm trying to use Treetop to parse an ERB file. I need to be able to handle lines like the following: <% ruby_code_here %> <%= other_ruby_code %> Since Treetop is written in Ruby, and you write Treetop grammars in Ruby, is there already some existing way in Treetop to say "hey, look for Ruby code here, and give me its breakdown" without me having to write out separate rules to handle all parts of the Ruby language? I'm looking for a way, in my .treetop grammar file, to have something like:

How to solve a shift/reduce conflict?

两盒软妹~` 提交于 2019-12-09 16:15:48
问题 I'm using CUP to create a parser that I need for my thesis. I have a shift/reduce conflict in my grammar. I have this production rule: command ::= IDENTIFIER | IDENTIFIER LPAREN parlist RPAREN; and I have this warning: Warning : *** Shift/Reduce conflict found in state #3 between command ::= IDENTIFIER (*) and command ::= IDENTIFIER (*) LPAREN parlist RPAREN under symbol LPAREN Now, I actually wanted it to shift so I'm pretty ok with it, but my professor told me to find a way to solve the

POSIX shell like implementation in Java

老子叫甜甜 提交于 2019-12-09 13:07:21
问题 Does anybody know of an implementation of POSIX shell like language for scripting things in Java? If this is not available, does anybody know if there is a ANTLR or JavaCC grammar available somewhere which I might have missed? edit: I know that I have Jython, JRuby, Groovy, JavaScript available for scripting, but none of them have bash like syntax. This would not be used for scripting together Java code, but to allow people to run predefined commands which would manipulate with a big third

Using Parsec to parse regular expressions

。_饼干妹妹 提交于 2019-12-09 06:12:30
问题 I'm trying to learn Parsec by implementing a small regular expression parser. In BNF, my grammar looks something like: EXP : EXP * | LIT EXP | LIT I've tried to implement this in Haskell as: expr = try star <|> try litE <|> lit litE = do c <- noneOf "*" rest <- expr return (c : rest) lit = do c <- noneOf "*" return [c] star = do content <- expr char '*' return (content ++ "*") There are some infinite loops here though (e.g. expr -> star -> expr without consuming any tokens) which makes the