grammar

ANTLR - Distinguish 'IS NOT NULL' from 'IS NULL'

走远了吗. 提交于 2019-12-08 11:14:45
问题 How can I differentiate ' IS NOT NULL ' from ' IS NULL '? 'IS' and 'IS NOT' are defined in a parser rule, and 'NULL' in another rule, and the second follows the first. What happens is that when I write 'IS NULL', the Parser is excepting 'IS NOT NULL' because both second words begin with 'N' . How can I distinguish both? Grammar File query : expr EOF -> ^(QUERY expr) ; expr : logical_expr ; logical_expr : equality_expr (logical_op^ equality_expr)* ; equality_expr : ID equality_op atom -> ^

Microsoft Speech Recognition - numbers only

和自甴很熟 提交于 2019-12-08 08:35:29
问题 Is there a way to limit the grammar to numbers only in either dictation mode or in constructing a custom grammar XML file? Obviously I can't enter all the numbers into the XML, but there has to be an easy way. 回答1: I know you asked this a long time ago, but I have a solution in case you still need it. Here is the file I came up with. This requires the user to speak single digits only, such as one five seven (not one fifty-seven, which will not work). You can play around with this to suit your

How to write grammar for an expression when it can have many possible forms

安稳与你 提交于 2019-12-08 05:17:36
问题 I have some sentences that I need to convert to regex code and I was trying to use Pyparsing for it. The sentences are basically search rules, telling us what to search for. Examples of sentences - LINE_CONTAINS this is a phrase -this is an example search rule telling that the line you are searching on should have the phrase this is a phrase LINE_STARTSWITH However we - this is an example search rule telling that the line you are searching on should start with the phrase However we The rules

LOOKAHEADs for the JavaScript/ECMAScript array literal production

左心房为你撑大大i 提交于 2019-12-08 04:11:23
问题 I currently implementing a JavaScript/ECMAScript 5.1 parser with JavaCC and have problems with the ArrayLiteral production. ArrayLiteral : [ Elision_opt ] [ ElementList ] [ ElementList , Elision_opt ] ElementList : Elision_opt AssignmentExpression ElementList , Elision_opt AssignmentExpression Elision : , Elision , I have three questions, I'll ask them one by one. This is the second one. I have simplified this production to the following form: ArrayLiteral: "[" ("," | AssignmentExpression ","

Tolerating malformed statements with ANTLR (e.g., for code-completion)

╄→гoц情女王★ 提交于 2019-12-08 04:05:35
问题 I have an ANTLR grammar for a simple DSL, and everything works swimmingly when there are no syntax errors. Now, however, I need to support an auto-completion mechanism, where I need to get possible completions from my tree grammars that perform basic type-checking on attributes, functions, etc. The problem is, ANTLR isn't reporting syntax errors at the local statement level, but farther up the parse tree, e.g., at the program or function level. Hence, instead of an AST that looks like program

ANTLR syntax error unexpected token: +

心不动则不痛 提交于 2019-12-08 03:43:53
问题 Hi I have a small problem in my ANTLR tree grammar. I am using ANTLRWorks 1.4. In parser grammar I have the rule like this: declaration : 'variable' IDENTIFIER ( ',' IDENTIFIER)* ':' TYPE ';' -> ^('variable' IDENTIFIER TYPE)+ So I wanted one tree per each IDENTIFIER. And in the tree grammar I left only rewrite rules: declaration : ^('variable' IDENTIFIER TYPE)+ But when I check grammar I got syntax error unexpected token +. And it is this + sign at the end of the declaration rule in the tree

How can i implement const in Boost Spirit?

雨燕双飞 提交于 2019-12-08 02:03:35
问题 I am interested in Boost Spirit nowadays and trying to build something. Can we implement something like a const in C++ using Spirit? For instance, user will define an item like; constant var PROG_LANG="Java"; "constant var" seems weird, I accept but you got the idea. I searched the internet but can't found anything about it. 回答1: What the BigBoss said :) Only I'd do without the semantic actions - making it far less... verbose (See also Boost Spirit: "Semantic actions are evil"?): vdef = (

How does Swift disambiguate Type Arguments in Expression Contexts?

浪尽此生 提交于 2019-12-08 00:59:40
问题 Take a look at the following two expressions: baz(Foo<Bar, Bar>(0)) baz(Foo < Bar, Bar > (0)) Without knowing what, baz , Foo and Bar are ( baz can be a type or a method, Foo and Bar can be types or variables), there is no way of disambiguating whether the < represents a type argument list or a less-than operator. // two different outcomes, difference shown with parentheses baz((Foo<Bar,Bar>(0))) // generics baz((Foo < Bar), (Bar > 0)) // less-than Any sane programming language should not

How to write grammar for an expression when it can have many possible forms

北城以北 提交于 2019-12-07 20:34:30
I have some sentences that I need to convert to regex code and I was trying to use Pyparsing for it. The sentences are basically search rules, telling us what to search for. Examples of sentences - LINE_CONTAINS this is a phrase -this is an example search rule telling that the line you are searching on should have the phrase this is a phrase LINE_STARTSWITH However we - this is an example search rule telling that the line you are searching on should start with the phrase However we The rules can be combined too, like- LINE_CONTAINS phrase one BEFORE {phrase2 AND phrase3} AND LINE_STARTSWITH

Unintentional concatenation in Bison/Yacc grammar

人走茶凉 提交于 2019-12-07 17:50:20
问题 I am experimenting with lex and yacc and have run into a strange issue, but I think it would be best to show you my code before detailing the issue. This is my lexer: %{ #include <stdlib.h> #include <string.h> #include "y.tab.h" void yyerror(char *); %} %% [a-zA-Z]+ { yylval.strV = yytext; return ID; } [0-9]+ { yylval.intV = atoi(yytext); return INTEGER; } [\n] { return *yytext; } [ \t] ; . yyerror("invalid character"); %% int yywrap(void) { return 1; } This is my parser: %{ #include <stdio.h