antlr

Antlr Handling Exceptions

狂风中的少年 提交于 2019-12-05 22:55:21
问题 I have developed a complex grammar using Antlr 3 using AST tree. ANTLR generates the Lexer and Parser. The problem is that when the user enters a syntax that is not valid for example, the grammar is expecting ';'. The user does not enter this, then in my Eclipse IDE I get the following Exception: line 1:24 mismatched input '<EOF>' expecting ';' How can this Exception be handled because I try to catch this Exception, but the Exception is not catched. Is this an Exception at all? I don't seem

How to get line number in ANTLR3 tree-parser @init action

僤鯓⒐⒋嵵緔 提交于 2019-12-05 21:08:16
In ANTLR, version 3, how can the line number be obtained in the @init action of a high-level tree-parser rule? For example, in the @init action below, I'd like to push the line number along with the sentence text. sentence @init { myNodeVisitor.pushScriptContext( new MyScriptContext( $sentence.text )); } : assignCommand | actionCommand; finally { m_nodeVisitor.popScriptContext(); } I need to push the context before the execution of the actions associated with symbols in the rules. Some things that don't work: Using $sentence.line -- it's not defined, even though $sentence.text is. Moving the

Translate ANTLR grammar into XText grammar: how to remove syntactic predicates

本秂侑毒 提交于 2019-12-05 20:25:13
I'm new to both Xtext and ANTLR. I need to translate an ANTLR (.g) grammar into an XTEXT (.xtext) grammar. In the ANTLR grammar there are syntactic predicates which are not supported by Xtext. Is there a way to remove/translate these predicates? Thanks EDIT The ANTLR grammar which I'm trying to translate can be found here: /* * Copyright 2009, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright

Writing a custom Xtext/ANTLR lexer without a grammar file

那年仲夏 提交于 2019-12-05 18:34:42
问题 I'm writing an Eclipse/Xtext plugin for CoffeeScript, and I realized I'll probably need to write a lexer for it by hand. CoffeeScript parser also uses a hand-written lexer to handle indentation and other tricks in the grammar. Xtext generates a class that extends org.eclipse.xtext.parser.antlr.Lexer which in turn extends org.antlr.runtime.Lexer . So I suppose I'll have extend it. I can see two ways to do that Override mTokens() . This is done by the generated code, changing the internal state

How do I install ANTLR IDE with Eclipse Juno and PDT (PHP)

[亡魂溺海] 提交于 2019-12-05 18:24:26
I develop in both PHP and Java. Eclipse PDT appears to require DLTK 4.0, which it has no problem getting. ANTLR IDE appears to require DLTK3. I've tried copying the plugins 3.0 into my Eclipse plugins / features directory: http://download.eclipse.org/technology/dltk/downloads/drops/R3.0/S-3.0.1-201108261011/ This worked on a machine without PDT, but I can't get it to work when I have PDT. I have also tried using the marketplace, but I get the same dependency errors. Note I'm on 64bit Linux. Try to add the DLTK 3.0 repository and then install ANTLR again, so maybe Eclipse can fetch the plugin

ANTLR Implicit Multiplication

纵饮孤独 提交于 2019-12-05 18:12:55
I'm new to ANTLR, and I'm trying to expand upon the example of a simple calculator presented here . Specifically, I've tried adding some simple functions, negative numbers and so on, to familiarize myself with ANTLR. However, I've run into a bit of a problem trying to implement "implicit" multiplication (for example, 3cos(2)sin(2) would be interpreted as 3*cos(2)*sin(2)). I've found a question on Stack Overflow with the same kind of problem ( here ). The general form of the solution to that problem looks like what I'd found on my own, so I'm not sure where my problem lies. My grammar is below.

Is there a working C++ grammar file for ANTLR?

自作多情 提交于 2019-12-05 17:22:28
问题 Are there any existing C++ grammar files for ANTLR? I'm looking to lex, not parse some C++ source code files. I've looked on the ANTLR grammar page and it looks like there is one listed created by Sun Microsystems here. However, it seems to be a generated Parser. Can anyone point me to a C++ ANTLR lexer or grammar file? 回答1: C++ parsers are tough to build. I can't speak with experience about using ANTLR's C++ grammars. Here I discuss what I learned by reading the notes attached to the the one

ANTLR parser hanging at proxy.handshake call

久未见 提交于 2019-12-05 17:17:21
I am attempting to get a basic ECMAScript parser working, and found a complete ANTLR grammar for ECMAScript 3 , which appears to compile ok and produces the appropriate Lexer/Parser/Walker Java files. (Running inside ANTLR IDE plugin for Eclipse 3.5) However, when actually trying to use it with some simple test code (following guide on ANTLR wiki ), it just hangs when trying to create the parser: CharStream MyChars = new ANTLRFileStream(FileName); // FileName is valid ES3Lexer MyLexer = new ES3Lexer(MyChars); CommonTokenStream MyTokens = new CommonTokenStream(MyLexer); MyTokens.setTokenSource

Convert simple Antlr grammar to Xtext

元气小坏坏 提交于 2019-12-05 16:56:15
问题 I want to convert a very simple Antlr grammar to Xtext, so no syntactic predicates, no fancy features of Antlr not provided by Xtext. Consider this grammar grammar simple; // Antlr3 foo: number+; number: NUMBER; NUMBER: '0'..'9'+; and its Xtext counterpart grammar Simple; // Xtext import "http://www.eclipse.org/emf/2002/Ecore" as ecore generate Simple "http://www.example.org/Simple" Foo: dummy=Number+; Number: NUMBER_TOKEN; terminal NUMBER_TOKEN: '0'..'9'+; Xtext uses Antlr behind the scenes,

Antlr Error Strategy to skip tokens until rule matches again

不羁岁月 提交于 2019-12-05 16:12:31
I tried this solution but it didn't seem to work for me Here's an excerpt from my grammer: module : BEGIN MODULE IDENT STRING module_element* END MODULE ; module_element : element_1 | element_2 | element_3 | ... ; There is a bigger tree below each element. Now when a RecognitionException occurs I want to consume tokens until either the next module_element matches or the parent END MODULE matches. Any hints on how to do this inside a class inheriting from DefaultErrorStrategy? edit: Here is a MCVE: Program.cs namespace AntlrExample { class Program { static void Main(string[] args) { var