grammar

Build parser from grammar at runtime

左心房为你撑大大i 提交于 2019-12-18 12:27:14
问题 Many (most) regular expression libraries for C++ allow for creating the expression from a string during runtime. Is anyone aware of any C++ parser generators that allow for feeding a grammar (preferably BNF) represented as a string into a generator at runtime? All the implementations I've found either require an explicit code generator to be run or require the grammar to be expressed via clever template meta-programming. 回答1: It should be pretty easy to build a recursive descent, backtracking

Any differences between terms parse trees and derivation trees?

断了今生、忘了曾经 提交于 2019-12-18 12:25:15
问题 The terms AST (Abstract Syntax Tree), parse tree and derivation tree are bandied about by different people when referring to the result of parsing texts conforming to a grammar. Assuming we are talking about parsing computer languages, are their differences minute enough that we can use these terms interchangeably ? If not, how do we use the terms correctly ? 回答1: AFAIK, "derivation tree" and "parse tree" are the same. Abstract syntax tree In computer science, an abstract syntax tree (AST),

How to control error handling and synchronization in Antlr 4 / c#

岁酱吖の 提交于 2019-12-18 07:14:31
问题 I'm using Antlr 4 with c# target. Here is a subset of my grammar: /* * Parser Rules */ text : term+ EOF; term : a1 a2 a3; a1: .... ... ... I want to accept valid data blocks as (term)s, when error exists I want to search for the next valid term and print out the whole text which caused the error for user to analyze manually. How to synchronize input to the next valid term? and How to get the ignored text? 回答1: You will need to create your own implementation of IAntlrErrorStrategy for this,

Finding meaningful sub-sentences from a sentence

一个人想着一个人 提交于 2019-12-17 22:35:10
问题 Is there a way to to find all the sub-sentences of a sentence that still are meaningful and contain at least one subject, verb, and a predicate/object? For example, if we have a sentence like "I am going to do a seminar on NLP at SXSW in Austin next month". We can extract the following meaningful sub-sentences from this sentence: "I am going to do a seminar", "I am going to do a seminar on NLP", "I am going to do a seminar on NLP at SXSW", "I am going to do a seminar at SXSW", "I am going to

Creating a separate “boolean expression” rule for a dynamic language

╄→гoц情女王★ 提交于 2019-12-17 20:56:03
问题 I'm creating a grammar in Bison for a simple dynamically-typed language. I have a "general" expression rule, which is somewhat akin to the concept of an rvalue in C; expressions appear on the right-hand side of an assignment, they can also be sent to functions as arguments etc. A greatly simplified version of the rule follows: constantExpression : TOK_INTEGER_CONSTANT | TOK_FLOAT_CONSTANT | stringLiteral ; expression : constantExpression | identifier | booleanExpression | booleanExpression

Dynamically create lexer rule

偶尔善良 提交于 2019-12-17 19:48:09
问题 Here is a simple rule: NAME : 'name1' | 'name2' | 'name3'; Is it possible to provide alternatives for such rule dynamically using an array that contains strings? 回答1: Yes, dynamic tokens match IDENTIFIER rule In that case, simply do a check after the Id has matched completely to see if the text the Id matched is in a predefined collection. If it is in the collection (a Set in my example) change the type of the token. A small demo: grammar T; @lexer::members { private java.util.Set<String>

Ruby Grammar

[亡魂溺海] 提交于 2019-12-17 10:21:43
问题 I'm looking for Ruby grammar in BNF form. Is there an official version? 回答1: Yes, there is one Ruby BNF syntax by the University of buffalo. Edit: I've also found this alternate Ruby BNF syntax. 回答2: The YACC syntax is in the Ruby source. Download it and run the bundled utiliy to get the readable syntax. wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p195.tar.gz tar xvzf ruby-2.0.0-p195.tar.gz cd ruby-2.0.0-p195 ruby sample/exyacc.rb < parse.y Output sample (total 918 lines for the v2.0

Build symbol table from grammar [closed]

依然范特西╮ 提交于 2019-12-17 07:54:10
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I am trying to build a symbol table from my grammar (done with antlr) by using eclipse. However I don't know by what to begin. I think I read somewhere that you would need the parser and lexer generated by antlr to do that. Does someone know an easy example so that I can

How do I do dependency parsing in NLTK?

懵懂的女人 提交于 2019-12-17 07:08:34
问题 Going through the NLTK book, it's not clear how to generate a dependency tree from a given sentence. The relevant section of the book: sub-chapter on dependency grammar gives an example figure but it doesn't show how to parse a sentence to come up with those relationships - or maybe I'm missing something fundamental in NLP? EDIT: I want something similar to what the stanford parser does: Given a sentence "I shot an elephant in my sleep", it should return something like: nsubj(shot-2, I-1) det

How to get all captures of subgroup matches with preg_match_all()? [duplicate]

好久不见. 提交于 2019-12-17 06:46:45
问题 This question already has answers here : Get repeated matches with preg_match_all() (6 answers) Closed 10 months ago . Update/Note: I think what I'm probably looking for is to get the captures of a group in PHP. Referenced: PCRE regular expressions using named pattern subroutines. (Read carefully:) I have a string that contains a variable number of segments (simplified): $subject = 'AA BB DD '; // could be 'AA BB DD CC EE ' as well I would like now to match the segments and return them via