grammar

Separation of Concerns: when is it best to disassociate semantics from syntax?

萝らか妹 提交于 2019-12-05 02:00:23
问题 Choices Typeclasses are brilliant in that they allow us to adjoin extra structure to existing types. Thereby allowing us to defer some design decisions rather than making rushed decision at the time of conception. On the other hand, in object oriented programming, for example, we are forced to consider what a type needs to do immediately and any additional structure that is apparent, or needed, at a later time would be incorporated into a subtype. Everything has its purposes. I'm wondering

Resolving reduce/reduce conflict in yacc/ocamlyacc

ぐ巨炮叔叔 提交于 2019-12-05 01:24:43
I'm trying to parse a grammar in ocamlyacc (pretty much the same as regular yacc) which supports function application with no operators (like in Ocaml or Haskell), and the normal assortment of binary and unary operators. I'm getting a reduce/reduce conflict with the '-' operator, which can be used both for subtraction and negation. Here is a sample of the grammar I'm using: %token <int> INT %token <string> ID %token MINUS %start expr %type <expr> expr %nonassoc INT ID %left MINUS %left APPLY %% expr: INT { ExprInt $1 } | ID { ExprId $1 } | expr MINUS expr { ExprSub($1, $3) } | MINUS expr {

How can i see the live parse tree using Antlr4 Ide in Eclipse?

て烟熏妆下的殇ゞ 提交于 2019-12-05 00:45:38
I'm new using Antlr4 but I know that exist a plugin for Eclipse. I have a simple question...After I created the g4 file how can I visualize the live parse tree in order to see the tree of an input expression? Thanks Currently there is no provision for viewing live parse tree in ANTLR 4 IDE for Eclipse . Meanwhile, you can see the parse tree using -gui switch in the command line. It also provides a feature of saving the parse tree as PNG. After installing Antlr4Ide plugin in Eclipse: Window>Show View>Other, Antlr4>Parse tree Activate g4 file Click parsing rule in g4 file, Parse tree now shows

Is My Lambda Calculus Grammar Unambiguous?

北慕城南 提交于 2019-12-04 18:17:49
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 function f to the argument g. I'm trying to write an unambiguous grammar for this language, under the

Class with no name

╄→гoц情女王★ 提交于 2019-12-04 17:43:52
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 this: class { public: int i; }; and it compiles fine without any name. Can anyone give me an

What is wrong with this grammar? (ANTLRWorks 1.4)

心已入冬 提交于 2019-12-04 16:20:27
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 : ( ' ' | '\t' | '\r' | '\n' ) {$channel=HIDDEN;}; ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..

Separate word lists for nouns, verbs, adjectives, etc

放肆的年华 提交于 2019-12-04 07:39:49
问题 Usually word lists are 1 file that contains everything, but are there separately downloadable noun list, verb list, adjective list, etc? I need them for English specifically. 回答1: See Kevin's word lists. Particularly the "Part Of Speech Database." You'll have to do some minimal text-processing on your own, in order to get the database into multiple files for yourself, but that can be done very easily with a few grep commands. The license terms are available on the "readme" page. 回答2: If you

How to enumerate the strings of a context-free grammar?

瘦欲@ 提交于 2019-12-04 07:19:42
What algorithm do you use to enumerate the strings generated by a context-free grammar? It seems doable when there is no recursion, but I can't figure out how to do it in the general case, which might contain all kinds of (possibly indirect) recursion. (I'm not looking for an esoteric solution like the one on this page ; I'm looking for an algorithm that I could map to standard imperative code.) Here's an obvious but somewhat inefficient algorithm: Construct R, the Earley parser for the grammar. For each string S in A* (A is the alphabet for the grammar): If R recognizes S: Output S Here I

BibTex grammar for ANTLR

时光总嘲笑我的痴心妄想 提交于 2019-12-04 05:51:07
I'm looking for a bibtex grammar in ANTLR to use in a hobby project. I don't want to spend my time for writing ANTLR grammar (this may take some time for me because it will involve a learning curve). So I'd appreciate for any pointers. Note: I've found bibtex grammars for bison and yacc but couldn't find any for antlr. Edit: As Bart pointed the I don't need to parse the preambles and tex in the quoted strings. Here's a (very) rudimentary BibTex grammar that emits an AST (contrary to a simple parse tree): grammar BibTex; options { output=AST; ASTLabelType=CommonTree; } tokens { BIBTEXFILE; TYPE

How to solve a shift/reduce conflict?

蹲街弑〆低调 提交于 2019-12-04 04:40:51
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 conflict. I'm blind. I've always read about the if/else conflict but to me this doesn't seem the case. Can