grammar

recognize Ruby code in Treetop grammar

我是研究僧i 提交于 2019-12-04 03:13:02
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: rule erb_tag "<%" ruby_code "%>" { def content ... end } end Where ruby_code is handled by some rules

Is there an existing ANTLR or IRONY grammar for R?

故事扮演 提交于 2019-12-04 02:24:14
Does anyone know if there is an existing existing ANTLR or IRONY grammar for R? Many thanks. I've built an R grammar for the early access "Honey Badger" ANTLR v4 release, if you'd like to give it a look. See the ANTLR v4 Examples page . Source for v4 is https://github.com/antlr/antlr4 . binary jar here: http://antlr.org/download/antlr-4.0ea-complete.jar For R you want http://www.antlr.org/wiki/download/attachments/28049418/R.g4 I'd guess a good place to look would be R to C Compiler (RCC) that was developed by John Garvin at Rice 来源: https://stackoverflow.com/questions/5705564/is-there-an

Context-sensitivity vs Ambiguity

核能气质少年 提交于 2019-12-03 23:48:41
I'm confused about how context-sensitivity and ambiguity influence each other. What i think is correct is: Ambiguity: An ambiguous grammar leads to the construction of more than one parse-tree using either left or right derivation. A language where all possible grammars are ambiguous is an ambiguous language. For instance C++ is an ambiguous language because x * y always can mean two different things as discussed in: Why can't C++ be parsed with a LR(1) parser? . Context-sensitivity: A context-sensitive grammar has rules where the left hand side of these rules may contain (non)terminal symbols

Using declaration for type-dependent template name

丶灬走出姿态 提交于 2019-12-03 23:41:11
When CRTP is used inside a template, (or generally when a template parameter is passed as a base class template argument), is it impossible to name the base's member templates in a using declaration? template< typename d > struct base { template< typename > struct ct {}; template< typename > void ft() {} }; template< typename x > struct derived : base< derived< x > > { using derived::base::template ct; // doesn't work using derived::base::ft; // works but can't be used in a template-id }; It seems to me that this is a hole in the language, simply because the using-declaration grammar

Why does this simple grammar have a shift/reduce conflict?

房东的猫 提交于 2019-12-03 20:26:01
%token <token> PLUS MINUS INT %left PLUS MINUS THIS WORKS: exp : exp PLUS exp; exp : exp MINUS exp; exp : INT; THIS HAS 2 SHIFT/REDUCE CONFLICTS: exp : exp binaryop exp; exp : INT; binaryop: PLUS | MINUS ; WHY? This is because the second is in fact ambiguous. So is the first grammar, but you resolved the ambiguity by adding %left . This %left does not work in the second grammar, because associativity and precedence are not inherited from rule to rule. I.e. the binaryop nonterminal does not inherit any such thing even though it produces PLUS and MINUS . Associativity and predecence are

Haskell Precedence: Lambda and operator

▼魔方 西西 提交于 2019-12-03 16:34:45
问题 I found precedence and associativity is a big obstacle for me to understand what the grammar is trying to express at first glance to haskell code. For example, blockyPlain :: Monad m => m t -> m t1 -> m (t, t1) blockyPlain xs ys = xs >>= \x -> ys >>= \y -> return (x, y) By experiment, I finally got it means, blockyPlain xs ys = xs >>= (\x -> (ys >>= (\y -> return (x, y)))) instead of blockyPlain xs ys = xs >>= (\x -> ys) >>= (\y -> return (x, y)) Which works as: *Main> blockyPlain [1,2,3] [4

POSIX shell like implementation in Java

。_饼干妹妹 提交于 2019-12-03 15:23:50
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 party Media Asset Management system. I would like to run things like: ls | grep "something" > output

ANTLR: call a rule from a different grammar

安稳与你 提交于 2019-12-03 13:04:05
问题 is it possible to invoke a rule from a different grammar? the purpose is to have two languages in the same file, the second language starting by an (begin ...) where ... is in the second language. the grammar should invoke another grammar to parse that second language. for example: grammar A; start_rule : '(' 'begin' B.program ')' //or something like that ; grammar B; program : something* EOF ; something : ... ; 回答1: Your question could be interpreted in (at least) two ways: separate rules

ANSI-C grammar - array declarations like [*] et alii

故事扮演 提交于 2019-12-03 11:53:32
The ANSI C grammar from -link- give me the following rules for array declarations: (1) | direct_declarator '[' type_qualifier_list assignment_expression ']' (2) | direct_declarator '[' type_qualifier_list ']' (3) | direct_declarator '[' assignment_expression ']' (4) | direct_declarator '[' STATIC type_qualifier_list assignment_expression ']' (5) | direct_declarator '[' type_qualifier_list STATIC assignment_expression ']' (6) | direct_declarator '[' type_qualifier_list '*' ']' (7) | direct_declarator '[' '*' ']' (8) | direct_declarator '[' ']' Now I have a some questions about these: Can I use

Is “Implicit token definition in parser rule” something to worry about?

微笑、不失礼 提交于 2019-12-03 11:39:29
问题 I'm creating my first grammar with ANTLR and ANTLRWorks 2. I have mostly finished the grammar itself (it recognizes the code written in the described language and builds correct parse trees), but I haven't started anything beyond that. What worries me is that every first occurrence of a token in a parser rule is underlined with a yellow squiggle saying "Implicit token definition in parser rule". For example, in this rule, the 'var' has that squiggle: variableDeclaration: 'var' IDENTIFIER ('='