grammar

Boost::spirit passing semantic actions in inherited attributes

纵然是瞬间 提交于 2019-12-12 15:08:43
问题 I'm trying to pass semantic action in a grammar's inherited argument. In the very basic example below the grammar parses two numbers and I pass semantic action (in a form of c++ lambda) into it and I'd like this action to be called on parsing of the first number. However it does not called but silently ignored and I'd like to know why is it so and what is the proper way to do such things. #include <iostream> #include <boost/spirit/include/qi.hpp> using namespace std; using namespace boost;

Do I have a bug in my grammar, or the parser-generation tool?

倖福魔咒の 提交于 2019-12-12 13:50:55
问题 The following is an EBNF-format (mostly - the actual syntax is documented here) grammar that I am attempting to generate a parser for: expr = lambda_expr_list $; lambda_expr_list = [ lambda_expr_list "," ] lambda_expr; lambda_expr = conditional_expr [ "->" lambda_expr ]; conditional_expr = boolean_or_expr [ "if" conditional_expr "else" conditional_expr ]; boolean_or_expr = [ boolean_or_expr "or" ] boolean_xor_expr; boolean_xor_expr = [ boolean_xor_expr "xor" ] boolean_and_expr; boolean_and

Can't figure out why Bison is throwing “Rules useless in parser due to conflicts”

一个人想着一个人 提交于 2019-12-12 12:11:42
问题 I'm writing a BNF grammar for a very simple programming language and using Flex and Bison to compile. I only have 3 variable and constant types: real, integer, string . My .l file has a token definition for "ID" as follows: DIGIT [0-9] LETTER [a-zA-Z] ID {LETTER}({LETTER}|{DIGIT})* My .y file has a definition for an identifier like this: identifier: ID; Now, I want to use the identifier definition to build variable and constant names. But I also want to limit assignment to data of the same

Why is “$” a valid function identifier? [duplicate]

不想你离开。 提交于 2019-12-12 11:22:29
问题 This question already has answers here : Closed 8 years ago . Possible Duplicates: Can someone explain the dollar sign in Javascript? Why would a javascript variable start with a dollar sign? Why is it that I can assign a function to $ in Javascript, but not # or ^ ? 回答1: From the ECMA standard (Section 7.6) The dollar sign ($) and the underscore (_) are permitted anywhere in an IdentifierName . 回答2: The reason is because JavaScript is part of the ECMA-262 standard. If you read section 7.6

Is Rust's lexical grammar regular, context-free or context-sensitive?

允我心安 提交于 2019-12-12 10:54:13
问题 The lexical grammar of most programming languages is fairly non-expressive in order to quickly lex it. I'm not sure what category Rust's lexical grammar belongs to. Most of it seems regular, probably with the exception of raw string literals: let s = r##"Hi lovely "\" and "#", welcome to Rust"##; println!("{}", s); Which prints: Hi lovely "\" and "#", welcome to Rust As we can add arbitrarily many # , it seems like it can't be regular, right? But is the grammar at least context-free? Or is

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

给你一囗甜甜゛ 提交于 2019-12-12 08:16:43
问题 %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? 回答1: 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

Why is this valid C? — ({123;}) evaluates to 123 [duplicate]

大憨熊 提交于 2019-12-12 07:58:42
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: in what versions of c is a block inside parenthesis used to return a value valid? The following is a type-safe version of a typical MAX macro (this works on gcc 4.4.5): #define max(a,b) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ _a > _b ? _a : _b; }) Here, we see that this expression, max(a,b) returns the result of the expression _a > _b ? _a : _b; even though this expression is in a block. So, I

Speech Recognition API without Grammar C#

冷暖自知 提交于 2019-12-12 07:08:08
问题 I am developing a program where 99% of the time i can use a set Grammar in the standard Microsoft Speech Recognition to detect words being said. However in a few circumstances, i need the user to say something. This is never going to be predictable. So is there a way to do this with the MS speech recognition? And are there any other speech recognition API's out there (for free), that can handle non-preset words? 回答1: There is a class called DictationGrammar that allows you to recognize

Is it possible to call one yacc parser from another to parse specific token substream?

若如初见. 提交于 2019-12-12 06:26:57
问题 Suppose I already have a complete YACC grammar. Let that be C grammar for example. Now I want to create a separate parser for domain-specific language, with simple grammar, except that it still needs to parse complete C type declarations. I wouldn't like to duplicate long rules from the original grammar with associated handling code, but instead would like to call out to the original parser to handle exactly one rule (let's call it "declarator"). If it was a recursive descent parser, there

EBNF grammar to ANTLR3?

这一生的挚爱 提交于 2019-12-12 05:50:01
问题 I have this EBNF grammar for the Jass scripting language. What needs to be done to convert it to work with ANTLR 3.5? Furthermore, are there any sort of tools available to aid me in doing so? //---------------------------------------------------------------------- // Global Declarations //---------------------------------------------------------------------- program ::= file+ file ::= newline? ( declr newline )* func* declr ::= typedef | globals | native_func typedef ::= 'type' id 'extends' (