grammar

Generate BNF diagrams from an antlr grammar?

拈花ヽ惹草 提交于 2019-12-06 11:54:31
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. ANTLRWorks 1 works for generating diagrams, one at a time, for rule. for v4, ANTLRWorks 2 also generates them though I'm not sure it can save them to disk. Ter If it is an ANTLR 3 grammar, you could

Access “this” inside of static codeblocks

僤鯓⒐⒋嵵緔 提交于 2019-12-06 11:24:22
Lately I've found myself writing alot of classes similar to: public class MyTypeCodes { public static MyTypeCode E = new MyTypeCode{ Desc= "EEE", Value = "E" }; public static MyTypeCode I = new MyTypeCode { Desc= "III", Value = "I" }; private static readonly Lazy<IEnumerable<MyTypeCode>> AllMyTypeCodes = new Lazy<IEnumerable<MyTypeCode>>(() => { var typeCodes = typeof(MyTypeCodes) .GetFields(BindingFlags.Static | BindingFlags.Public) .Where(x => x.FieldType == typeof (MyTypeCode)) .Select(x => (MyTypeCode) x.GetValue(null)) .ToList(); return typeCodes; }); public static IEnumerable<MyTypeCode>

Class with no name

半腔热情 提交于 2019-12-06 11:03:11
问题 I read this about class in the C++ standard document: A class is a type. Its name becomes a class-name (9.1) within its scope. class-name: identifier template-id I found this grammar for an identifier in the C++ Standard: 2.10 Identifiers identifier: nondigit identifier nondigit identifier digit nondigit: one of universal-character-name _ a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z digit: one of 0 1 2 3 4 5 6 7 8 9 Now I tried doing

How do I best do balanced quoting with Perl's Regexp::Grammars?

℡╲_俬逩灬. 提交于 2019-12-06 09:51:58
Using Damian Conway's Regexp::Grammars , I'm trying to match different balanced quoting ( 'foo' , "foo" , but not 'foo" ) mechanisms -- such as parens, quotes, double quotes, and double dollars. This is the code I'm currently using. <token: pair> \'<literal>\'|\"<literal>\"|\$\$<literal>\$\$ <token: literal> [\S]+ This generally works fine and allows me to say something like: <rule: quote> QUOTE <.as>? <pair> My question is how do I reform the output, to exclude the needles notation for the pair token? { '' => 'QUOTE AS \',\'', 'quote' => { '' => 'QUOTE AS \',\'', 'pair' => { 'literal' => ',',

What's the goto methodolgy of building out a parser in .NET

落花浮王杯 提交于 2019-12-06 08:16:23
A grammar as well. If one were to approach a generic parser from the ground up how would one go about it? I've looked at ANTLR and Irony, but they are more tools than methodologies. What are the steps one should tackle and the milestones for accomplishment? Large topic my friend. If you want to learn about the theory the best place to go is 'the Dragon Book': http://www.amazon.com/Compilers-Principles-Techniques-Tools-Gradiance/dp/0321547985/ref=sr_1_2?s=books&ie=UTF8&qid=1297801900&sr=1-2 Another good place to look if you want to devlope for .Net is the F# power pack. THis contains fsLex and

Add error checking via production rules to LALR(1) grammar to handle all inputs

北慕城南 提交于 2019-12-06 08:05:58
I have a grammar that represents expressions. Let's say for simplicity it's: S -> E E -> T + E | T T -> P * T | P P -> a | (E) With a , + , * , ( and ) being the letters in my alphabet. The above rules can generate valid arithmetic expressions containing parenthesis, multiplication and addition using proper order of operations and associativity. My goal is to accept every string, containing 0 or more of the letters of my alphabet. Here are my constraints: The grammar must "accept" all strings contained 0 or more letters of my alphabet. New terminals may be introduced and inserted into the

How can i implement const in Boost Spirit?

亡梦爱人 提交于 2019-12-06 05:58:30
I am interested in Boost Spirit nowadays and trying to build something. Can we implement something like a const in C++ using Spirit? For instance, user will define an item like; constant var PROG_LANG="Java"; "constant var" seems weird, I accept but you got the idea. I searched the internet but can't found anything about it. sehe What the BigBoss said :) Only I'd do without the semantic actions - making it far less... verbose (See also Boost Spirit: "Semantic actions are evil"? ): vdef = ("constant" >> attr(true) | attr(false)) >> "var" >> identifier >> '=' >> identifier_value >> ';' ; That's

How does Swift disambiguate Type Arguments in Expression Contexts?

拈花ヽ惹草 提交于 2019-12-06 04:28:23
Take a look at the following two expressions: baz(Foo<Bar, Bar>(0)) baz(Foo < Bar, Bar > (0)) Without knowing what, baz , Foo and Bar are ( baz can be a type or a method, Foo and Bar can be types or variables), there is no way of disambiguating whether the < represents a type argument list or a less-than operator. // two different outcomes, difference shown with parentheses baz((Foo<Bar,Bar>(0))) // generics baz((Foo < Bar), (Bar > 0)) // less-than Any sane programming language should not rely on what baz , Foo and Bar are when parsing an expression like this. Yet, Swift manages to

ANTLR syntax error unexpected token: +

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 04:24:14
Hi I have a small problem in my ANTLR tree grammar. I am using ANTLRWorks 1.4. In parser grammar I have the rule like this: declaration : 'variable' IDENTIFIER ( ',' IDENTIFIER)* ':' TYPE ';' -> ^('variable' IDENTIFIER TYPE)+ So I wanted one tree per each IDENTIFIER. And in the tree grammar I left only rewrite rules: declaration : ^('variable' IDENTIFIER TYPE)+ But when I check grammar I got syntax error unexpected token +. And it is this + sign at the end of the declaration rule in the tree grammar. So what I am doing wrong? Parser grammar works fine and builds AST tree as expected. I

How to debug an invalid ParseKit Grammar?

烂漫一生 提交于 2019-12-06 04:12:36
I am trying to write a grammar for ParseKit so that it matches basic propositional logic sentences in an iphone app. Can someone please tell me where im going wrong. @start = wff; wff = disjunction (implies disjunction)?; disjunction = conjuction (or conjuction)*; conjunction = notExpression (and notExpression)*; notExpression = (not | not primaryExpression); primaryExpression = variable | lbracket wff rbracket; variable = p | q | r; p = 'P'; q = 'Q'; r = 'R'; implies = '→'; and = '∧'; or = '∨'; not = '¬'; lbracket = '('; rbracket = ')'; Also how would i go about adding some extra call backs