grammar

javascript grammar and automatic semocolon insertion

主宰稳场 提交于 2019-12-11 08:05:17
问题 I'm trying to implement javascript parser and I stuck in a problem. Javascript has a technique called "semicolon insertion". So what is a common way to deal with automatic semicolon insertion in js parsers? Should I rewrite original grammar to make it be able to deal with auto semicolons? Is it possible? Or should I implement parser for original grammar and then use some tricky technique to deal with semicolons ? All suggestions are welcome. 来源: https://stackoverflow.com/questions/14295850

C# SAPI - Recognizing phrases without pre-defined condition statements

∥☆過路亽.° 提交于 2019-12-11 08:00:42
问题 Scenario : I have 2 commands. 1) Search Google for "any word here" 2) Open application "any word here" Problem : Since the word after "Search Google for" can be anything, how am I suppose to know what am I going to write for my IF statements? With pre-defined sentences, I can do it easily like void Engine_SpeechRecognized (object sender, SpeechRecognizedEventsArgs e) { if (e.Result.Text == "Search Google Stackoverflow") { Search("Stackoverflow"); } } But since now it's not pre-defined, what

How to transform nested arrays string in json like string to structured object using parslet

萝らか妹 提交于 2019-12-11 06:47:46
问题 I have a problem with transforming parsed JSON-like string, which contains nested arrays, to structured object. I am using parslet to do this. I created parser and transformer, presented below. But I can't handle nested arrays situation. require 'parslet' class JSONLikeDataParser < Parslet::Parser rule(:l_map_paren) {str('{')} rule(:r_map_paren) {str('}')} rule(:l_list_paren) {str('[')} rule(:r_list_paren) {str(']')} rule(:map_entry_delimiter) {str(':')} rule(:val_delimiter) {str(',')} rule(

JavaScript grammar: indexing object literals syntactically forbidden?

爷,独闯天下 提交于 2019-12-11 05:33:10
问题 In Chrome 63.0 and Firefox 58.0, it appears that adding an index to an object literal prevents the object from being parsed as an object. {"a":"b"} 17:37:32.246 {a: "b"} {"a":"b"}["a"] 17:37:36.578 VM288:1 Uncaught SyntaxError: Unexpected token : Can anybody explain why the parser doesn't parse this the way I do? (I think there must be a bug in my implementation of the spec...) It seems to think it's not parsing an object. Surrounding the object in brackets results in syntactically correct

How to remove Left recursive in this ANTLR grammar?

巧了我就是萌 提交于 2019-12-11 05:31:58
问题 I am trying to parse CSP(Communicating Sequential Processes) CSP Reference Manual. I have defined following grammar rules. assignment : IDENT '=' processExpression ; processExpression : ( STOP | SKIP | chaos | prefix | prefixWithValue | seqComposition | interleaving | externalChoice .... seqComposition : processExpression ';' processExpression ; interleaving : processExpression '|||' processExpression ; externalChoice : processExpression '[]' processExpression ; Now ANTLR reports that

ANTLR/Grammar issue: calculator language

旧街凉风 提交于 2019-12-11 05:07:46
问题 I'm attempting to create a boolean expression language/grammar for a personal project. The user will be able to write a string in a Java-like syntax, with provision for variables, which will be evaluated at a later time when the variables have been initialised. Rain For example, a user might enter the string @FOO+7 > 4*(5+@BAR); Later, when the variable FOO is initialised and equal to 6, and BAR is equal to 1, the expression evaluates to 13>24 and thus returns false. I'm using ANTLRworks to

Matching wildcard/dictation in Microsoft Speech Grammar

最后都变了- 提交于 2019-12-11 04:44:33
问题 I'm using Microsoft Speech API to load a grxml grammar: Grammar grammar = new Grammar(file); grammar.Enabled = true; SpeechRecognitionEngine sre = GetEngine(); sre.LoadGrammarAsync(grammar); Based on MSDN I can not find tag to match a wildcard / spoken text like: <item>My message is {dictation}</item> It seems to be availalble with code with a DictationGrammar and appendDictation(). It's also available with WSRMacro XML using * but I do not how to do it in XML ? The skip text but I need to

Using a Prolog DCG to split a string

a 夏天 提交于 2019-12-11 03:49:03
问题 I'm trying to use a DCG to split a string into two parts separated by spaces. E.g. 'abc def' should give me back "abc" & "def". The program & DCG are below. main:- prompt(_, ''), repeat, read_line_to_codes(current_input, Codes), ( Codes = end_of_file -> true ; processData(Codes), fail ). processData(Codes):- ( phrase(data(Part1, Part2), Codes) -> format('~s, ~s\n', [ Part1, Part2 ]) ; format('Didn''t recognize data.\n') ). data([ P1 | Part1 ], [ P2 | Part2 ]) --> [ P1 | Part1 ], spaces(_), [

Simple ambiguous grammar with reduce-reduce conflict

独自空忆成欢 提交于 2019-12-11 03:24:43
问题 The following simple grammar to parse a logical expression results in a reduce/reduce conflict: %token AND OR %token NUMBER VARIABLE %% logical_expr : logical_expr AND logical_term | logical_expr OR logical_term | logical_term ; logical_term : VARIABLE | comparison | '(' logical_expr ')' ; comparison : expr '<' expr | expr '>' expr ; expr : expr '+' term | expr '-' term | term ; term : NUMBER | VARIABLE | '(' expr ')' ; %% The status report from bison has: state 2 4 logical_term: VARIABLE .

Why does ANTLR require all or none alternatives be labeled?

為{幸葍}努か 提交于 2019-12-11 03:05:55
问题 I'm new to ANTLR. I just discovered that it is possible to label each alternative in a production like so: foo : a # aLabel | b # bLabel | // ... ; However, I find it unpleasant that all or none alternatives must be labeled. I needed to label just 2 alternatives of a production with 20+ branches recently, and I ended up labelling each of the others # stubLabel . Is there any reason why all or none have to be labeled? 回答1: As soon as you add a label ANTLR4 will no longer generate a context