grammar

Regexp parse type-3 grammar

两盒软妹~` 提交于 2019-12-11 14:39:33
问题 Reading Chomsky hierarchy ... ... I know regexp can't parse type-2 grammars (context-free grammars), and also type-1 and type-0. Can regular expressions parse/catch ALL type-3 grammars (regular grammars)? 回答1: Yes, provided they support alternation, concatenation, and the Kleene star. This is the case for regexes of the PCRE (Perl/Java/JavaScript/PHP/...) type: alternation is implemented by ((...)|(...)) , concatenation by (...)(...) , and the Kleene star by (...)* . (There are a few other

Issues of Error handling with ANTLR3

独自空忆成欢 提交于 2019-12-11 12:04:34
问题 I tried error reporting in following manner. @members{ public String getErrorMessage(RecognitionException e,String[] tokenNames) { List stack=getRuleInvocationStack(e,this.getClass().getName()); String msg=null; if(e instanceof NoViableAltException){ <some code> } else{ msg=super.getErrorMessage(e,tokenNames); } String[] inputLines = e.input.toString().split("\r\n"); String line = ""; if(e.token.getCharPositionInLine()==0) line = "at \"" + inputLines[e.token.getLine() - 2]; else if(e.token

Removing left recursion grammar using DCG

夙愿已清 提交于 2019-12-11 10:48:14
问题 The following Grammar has left-recursion Grammar : Expr ::= E1|E2|E3|E4|E5|E6|E7 E1 ::= "(" Expr ")" E2 ::= "not""(" Expr ")" E3 ::= Expr "=>" Expr E4 ::= Expr "=/=" Expr E5 ::= Expr "*" Expr E6 ::= Func "=>" Func Func ::= Ter (Ters)+"," ... and I'm trying to remove the LR in this manner ; Expr ::= E1|... E1 ::= Expr "*" Expr ==> E1 ::= Expr Expr' Expr'::= *Expr Expr' but the problem still exists, How to fix it to get this program working? example query and test | ?- phrase(e(T),"not((2+3)=/

Converting a context-free grammar into a LL(1) grammar

我的梦境 提交于 2019-12-11 10:33:00
问题 First off, I have checked similar questions and none has quite the information I seek. I want to know if, given a context-free grammar, it is possible to: Know if there exists or not an equivalent LL(1) grammar. Equivalent in the sense that it should generate the same language. Convert the context-free grammar to the equivalent LL(1) grammar, given it exists. The conversion should succeed if an equivalent LL(1) grammar exists. It is OK if it does not terminate if an equivalent does not exists

ANTLR on a noisy data stream Part 2

别说谁变了你拦得住时间么 提交于 2019-12-11 10:18:10
问题 Following a very interesing discussion with Bart Kiers on parsing a noisy datastream with ANTLR, I'm ending up with another problem... The aim is still the same : only extracting useful information with the following grammar, VERB : 'SLEEPING' | 'WALKING'; SUBJECT : 'CAT'|'DOG'|'BIRD'; INDIRECT_OBJECT : 'CAR'| 'SOFA'; ANY : . {skip();}; parse : sentenceParts+ EOF ; sentenceParts : SUBJECT VERB INDIRECT_OBJECT ; a sentence like it's 10PM and the Lazy CAT is currently SLEEPING heavily on the

Antlr Parser operator priority

只愿长相守 提交于 2019-12-11 09:26:00
问题 Consider the following grammar. I have issues with the operator priority, for instance: res=2*a+b has a similar parse tree as res=2*(a+b). I know where the problem is, but no "beautiful" solution without mutual left recursion comes to my mind. Can you please help me out a little. The grammar is used with a custom visitor. grammar Math; expression: expression add=('+'|'-') expression # expressionAddExpression | expression mult='*' expression # expressionMultExpression |'(' expression ')' #

ANTLR v3 grammar for boolean/conditional expression

烂漫一生 提交于 2019-12-11 09:04:58
问题 I'm taking a first stab at creating a grammar for expressions like: (foo = bar or (bar = "bar" and baz = 45.43)) and test = true My grammar so far looks like: grammar filter; tokens { TRUE = 'true'; FALSE = 'false'; AND = 'and'; OR = 'or'; LT = '<'; GT = '>'; EQ = '='; NEQ = '!='; PATHSEP = '/'; LBRACK = '['; RBRACK = ']'; LPAREN = '('; RPAREN = ')'; } expression : or_expression EOF; or_expression : and_expression (OR or_expression)*; and_expression : term (AND term)*; term : atom ( operator

Can not provide for host variables in Antlr3 SQL grammar

余生颓废 提交于 2019-12-11 09:01:58
问题 I have a SQL grammar which do not have support for host variables. I want to provide support for host variables in that but a situation that I have encountered is tricky. There is SQL Identifier lexer rule in grammar, which supports alphanumeric along with some special characters '@', '#', '$ and '_'. Host variable's are dependent on language in which SQL is embedded. e.g. COBOL. COBOL identifiers allow additionally hyphen(-) in variable names (Some other differences in them). So I added LANG

Create a top down parser based on a custom language

心不动则不痛 提交于 2019-12-11 08:20:14
问题 Consider the language ( Σ,R,S ), defined by Σ = { ′(′, ′)′ } R = {S → SS, S → (S), S → ϵ } 1. What is the grammar for this language? Isn't it just the list of production rules, therefore R? If not, what differentiates a grammar from a list of production rules? 2. How do I then go about creating a top down parser based on this grammar? I've seen it mentioned that a stack is involved. I have a tokenizer provided by my professor already, but I honestly have no idea how to go about implementing

rule has non-LL(*) decision due to recursive rule invocations

风流意气都作罢 提交于 2019-12-11 08:14:42
问题 I have an error (like said in the title) with one rule that i dont know how resolve. i have written the following rule : FunctionArguments returns FunctionArgs::IFunctionArguments : FunctionArgumentsNormal | FunctionArgumentsForIter ; FunctionArgumentsNormal returns FunctionArgs::IFunctionArguments : {FunctionArgs::FunctionArguments} args+=Expression (',' args+=Expression)* | {FunctionArgs::FunctionArguments} argNames+=NamedArguments (',' argNames+=NamedArguments)* ; FunctionArgumentsForIter