grammar

Is My Lambda Calculus Grammar Unambiguous?

时光总嘲笑我的痴心妄想 提交于 2019-12-22 00:49:47
问题 I am trying to write a small compiler for a language that handles lambda calculus. Here is the ambiguous definition of the language that I've found: E → ^ v . E | E E | ( E ) | v The symbols ^, ., (, ) and v are tokens. ^ represents lambda and v represents a variable. An expression of the form ^v.E is a function definition where v is the formal parameter of the function and E is its body. If f and g are lambda expressions, then the lambda expression fg represents the application of the

What is wrong with this grammar? (ANTLRWorks 1.4)

感情迁移 提交于 2019-12-21 22:15:06
问题 I have the following code written in ANTLRWorks 1.4 grammar hmm; s : (put_a_in_b)|(put_out_a)|(drop_kick)|(drop_a)|(put_on_a); put_a_in_b : (PUT_SYN)(ID)(IN_SYN)(ID); put_out_a : (PUT2_SYN)(OUT_SYN)(ID) | (E1)(ID); drop_kick : ('drop')('kick')(ID); drop_a : (DROP_SYN)(ID); put_on_a : (E2)(ID); PUT_SYN : 'put' | 'place' | 'drop'; PUT2_SYN : 'put' | 'douse'; IN_SYN : 'in' | 'into' | 'inside' | 'within'; OUT_SYN : 'out'; E1 : 'extinguish'|'douse'; DROP_SYN : 'drop' | 'throw' | 'relinquish'; WS :

Parsing with incomplete grammars

点点圈 提交于 2019-12-21 17:14:43
问题 Are there any common solutions how to use incomplete grammars? In my case I just want to detect methods in Delphi (Pascal)-files, that means procedures and functions . The following first attempt is working methods : ( procedure | function | . )+ ; but is that a solution at all? Are there any better solutions? Is it possible to stop parsing with an action (e. g. after detecting implementation ). Does it make sense to use a preprocessor? And when yes - how? 回答1: If you're only looking for

Understanding precedence of assignment and logical operator in Ruby

▼魔方 西西 提交于 2019-12-21 12:30:11
问题 I can't understand precedence of Ruby operators in a following example: x = 1 && y = 2 Since && has higher precedence than = , my understanding is that similarly to + and * operators: 1 + 2 * 3 + 4 which is resolved as 1 + (2 * 3) + 4 it should be equal to: x = (1 && y) = 2 However, all Ruby sources (including internal syntax parser Ripper ) parse this as x = (1 && (y = 2)) Why? EDIT [08.01.2016] Let's focus on a subexpression: 1 && y = 2 According to precedence rules, we should try to parse

Using precedence in Bison for unary minus doesn't solve shift/reduce conflict

断了今生、忘了曾经 提交于 2019-12-21 06:00:45
问题 I'm devising a very simple grammar, where I use the unary minus operand. However, I get a shift/reduce conflict. In the Bison manual, and everywhere else I look, it says that I should define a new token and give it higher precedence than the binary minus operand, and then use "%prec TOKEN" in the rule. I've done that, but I still get the warning. Why? I'm using bison (GNU Bison) 2.4.1. The grammar is shown below: %{ #include <string> extern "C" int yylex(void); %} %union { std::string token;

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

爷,独闯天下 提交于 2019-12-21 04:00:34
问题 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

Where can I find a formal grammar for the Perl programming language?

a 夏天 提交于 2019-12-21 03:22:52
问题 I understand that the Perl syntax is ambiguous and that its disambiguation is non-trivial (sometimes involving execution of code during the compile phase). Regardless, does Perl have a formal grammar (albeit ambiguous and/or context-sensitive)? 回答1: From perlfaq7 Can I get a BNF/yacc/RE for the Perl language? There is no BNF, but you can paw your way through the yacc grammar in perly.y in the source distribution if you're particularly brave. The grammar relies on very smart tokenizing code,

POSIX sh EBNF grammar

寵の児 提交于 2019-12-20 14:21:45
问题 Is there an existing POSIX sh grammar available or do I have to figure it out from the specification directly? Note I'm not so much interested in a pure sh; an extended but conformant sh is also more than fine for my purposes. 回答1: The POSIX standard defines the grammar for the POSIX shell. The definition includes an annotated Yacc grammar. As such, it can be converted to EBNF more or less mechanically. If you want a 'real' grammar, then you have to look harder. Choose your 'real shell' and

BNF vs EBNF vs ABNF: which to choose?

有些话、适合烂在心里 提交于 2019-12-20 09:48:35
问题 I want to come up with a language syntax. I have read a bit about these three, and can't really see anything that one can do that another can't. Is there any reason to use one over another? Or is it just a matter of preference? 回答1: You have to think about EBNF and ABNF as extensions that help you just to be more concise and expressive while developing your grammars. For example think about an optional non-terminal symbol, in a BNF grammar you would define it by using intermediate symbols

Where can I find a formal grammar for MATLAB?

爷,独闯天下 提交于 2019-12-20 09:06:51
问题 I would like to write a lexer generator to convert a basic subset of the MATLAB language to C#, C++, etc. To help me do this, I would like to find a document containing the formal grammar for MATLAB. Having spent a bit of time investigating this, it seems that Mathworks do not provide one. Does anyone know where I could find such a document? 回答1: Excellent opportunity to write your own formal grammar :) If you should choose to write the grammer your self, I can recommend BNFC which can take a