grammar

Stack Overflow when Pyparsing Ada 2005 Scoped Identifiers using Reference Manual Grammar

依然范特西╮ 提交于 2019-12-11 02:37:20
问题 I'm currently implementing an Ada 2005 parser using Pyparsing and the reference manual grammar rules. We need this in order to analyze and transform parts of our aging Ada-codebase to C/C++. Most things work. However, one little annoying problem remains: The grammar rule name when parsing scoped identifiers (rule selected_component ) such as the expression "Global_Types.Integer2" fails because it is part of a left-associative grammar rule cycle. I believe this rule is incorrectly written: the

ANTLR4 Mutual left recursion

痞子三分冷 提交于 2019-12-11 01:08:49
问题 I just ran into a strange problem with ANTLR 4.2.2: Consider a (simplified) java grammar. This does not compile: classOrInterfaceType : (classOrInterfaceType) '.' Identifier | Identifier ; ANTLR outputs the following error: error(119): Java.g4::: The following sets of rules are mutually left-recursive [classOrInterfaceType] Yes, I also see a left recursion. But I do not see a mutual left recursion, only a usual one. When I remove the parenthesis around (classOrInterfaceType) , then it

Verify LL(1) grammar with ANTLR

不想你离开。 提交于 2019-12-10 22:13:56
问题 I understand that ANTLR can accept an LL(*) grammar. But, is there any way to check a grammar whether it is an LL(1) or not using ANTLR? 回答1: options { k = 1; } It will give a warning if your grammer is not in LL(1). 回答2: For a grammer/language to be LL(1) we know that at any given position in the input there is only one production we can take to consume token(s) of the input. So, in order to determine if a grammar is LL(1), we need to: 1) check the FIRST set of all nonterminals and if there

parsing nested structures with pyparsing

我的未来我决定 提交于 2019-12-10 20:46:13
问题 I'm trying to parse a particular syntax for positions in biological sequences. The positions can have forms like: 12 -- a simple position in the sequence 12+34 -- a complex position as a base (12) and offset(+34) 12_56 -- a range, from 12 to 56 12+34_56-78 -- a range as a start to end, where either or both may be simple or complex I'd like to have these parsed as dicts, roughly like this: 12 -> { 'start': { 'base': 12, 'offset': 0 }, 'end': None } 12+34 -> { 'start': { 'base': 12, 'offset':

What is the best way to define grammars for a text editor?

心已入冬 提交于 2019-12-10 20:13:42
问题 I'm masochistically writing an open-source text editor for Mac and have finally reached the point at which I want to add syntax highlighting. I've been going back and forth on various solutions for the past few days, and I've finally decided to open the question to a wider audience. Here are the options I see: Define languages basically with a series of regex pattern matching (similar to how TextMate defines its languages) Define languages with a formal grammar like BNF or PEG Using regex

Is there any trick about translating BNF to Parsec program?

戏子无情 提交于 2019-12-10 20:01:58
问题 The BNF that match function call chain (like x(y)(z)... ): expr = term T T = (expr) T | EMPTY term = (expr) | VAR Translate it to Parsec program that looks so tricky. term :: Parser Term term = parens expr <|> var expr :: Parser Term expr = do whiteSpace e <- term maybeAddSuffix e where addSuffix e0 = do e1 <- parens expr maybeAddSuffix $ TermApp e0 e1 maybeAddSuffix e = addSuffix e <|> return e Could you list all the design patterns about translating BNF to Parsec program? 回答1: The simplest

ANTLR 3, what does LT!* mean?

南笙酒味 提交于 2019-12-10 19:29:50
问题 I was looking at the code for a Javascript grammar written in ANTLR 3, http://www.antlr3.org/grammar/1206736738015/JavaScript.g In many instances I found program : LT!* sourceElements LT!* EOF! ; what does LT!* mean ? EDIT: From http://ftp.camk.edu.pl/camk/chris/antlrman/antlrman.pdf I found that LT stands for LOOKAHEAD TOKEN but it is the N th look ahead token, where is the N part in the above ? 回答1: No, LT does not mean LOOKAHEAD TOKEN in this context. It is a token defined nearly at the

Where can I find an official grammar for the PL/SQL programming language?

扶醉桌前 提交于 2019-12-10 18:45:10
问题 Where can I find an official grammar for the PL/SQL programming language? I see that the Antlr project has a user-contributed grammar, but I was hoping to find a more authoritative source. 回答1: You mean the documentation? It'd help to know what version of Oracle -- this link covers 9i (v9.2 technically). 回答2: The official grammar for the PL/SQL can be found at the Chapter 13 of the PL/SQL Language Reference. 回答3: Also, you can take a look at a community PL/SQL ANTLR grammar in ANTLR grammars

Representing statement-terminating newlines in a grammar?

让人想犯罪 __ 提交于 2019-12-10 18:36:19
问题 A lot of programming languages have statements terminated by line-endings. Usually, though, line endings are allowed in the middle of a statement if the parser can't make sense of the line; for example, a = 3 + 4 ...will be parsed in Ruby and Python* as the statement a = 3+4 , since a = 3+ doesn't make any sense. In other words, the newline is ignored since it leads to a parsing error. My question is: how can I simply/elegantly accomplish that same behavior with a tokenizer and parser? I'm

Error while building an xtext project with ant: Generation of the Grammar classes fails

强颜欢笑 提交于 2019-12-10 17:33:28
问题 I am developing an xtext plug-in project for an eclipse application for my Bachelor thesis. I want to do the 'Generate Xtext Artifacts' at runtime with an ant script executing the Mwe2Launcher class and do the generation in an temp folder. I wrote an Activator to create in the temp folder a project folder and copy the mwe2 file, my grammar file and the ant script. Executing the Ant script leads to this error: osgi> start 360 gen: [java] 0 INFO StandaloneSetup - Registering platform uri 'C: