antlr

OutOfMemoryError when parsing incorrect input in ANTLR

故事扮演 提交于 2019-12-08 01:54:33
问题 Actually this issue is related with my previous question Catching ANTLR's NoViableAltException in Java and ANTLRWorks Debugger, but I decided to split them because of different symptoms. The issue is about feeding to ANTLR input text, which contains unknown tokens. Consider for example, that our grammar doesn't known anything about tokens which start with @ symbol. If we will try to feed such text to ANTLRWorks interpreter, we will receive NoViableAltException in result graph. But if we will

Antlr4-JS actions in grammar: how to access tokens and define funcs ? (direct in java, not in JS)

痞子三分冷 提交于 2019-12-07 23:08:16
问题 I'm trying to adapt to JS target the Expr.g4 of the book. In this example, actions are directly in the grammar. They include utility functions defined in @parser::members , that are called in the rules. The example works well in Java, but in its JS translation I have 2 problem: - getting the action function visible by the action rule - getting the tokens recognized in the function. I finally manage to get this working formulation: @parser::members { myeval = function(left, op, right) { switch

How to stop ANTLR from suppressing syntax errors?

蹲街弑〆低调 提交于 2019-12-07 20:40:46
问题 So I'm writing a compiler in Java using ANTLR, and I'm a little puzzled by how it deals with errors. The default behavior seems to be to print an error message and then attempt, by means of token insertion and such, to recover from the error and continue parsing. I like this in principle; it means that (in the best case) if the user has committed more than one syntax error, they'll get one message per error, but it'll mention all the errors instead of forcing them to recompile to discover the

Hints regarding the use of ANTLR v3 generated files in Flash Builder 4.5.1

霸气de小男生 提交于 2019-12-07 18:31:11
问题 According to these instructions, I'm trying to use ANTLR generated *.as files in a current Flash Builder 4.5.1 project. Therefore, I added this ANTLR's Actionscript runtime to my project - without problems. I compiled lexer/parser specs using ANTLRWorks without problems too. I added the language option to the source *.g file to make ANTLR generate Actionscript sources: options { backtrack = true; memoize = true; k=2; output = AST; language=ActionScript; // Added this ASTLabelType = CommonTree

Antlr Array Help

╄→尐↘猪︶ㄣ 提交于 2019-12-07 17:58:32
问题 Hey ive started to use Antlr with java and i wanted to know how i can store some values directly into a 2d array and return this array? i cant find any tutorials on this at all, all help is apperciated. 回答1: Let's say you want to parse a flat text file containing numbers separated by spaces. You'd like to parse this into a 2d array of int 's where each line is a "row" in your array. The ANTLR grammar for such a "language" could look like: grammar Number; parse : line* EOF ; line : Number+

Solving ANTLR Mutually left-recursive rules

£可爱£侵袭症+ 提交于 2019-12-07 17:52:14
问题 the 'expr' rule in the ANTLR grammar below obviously mutually left-recursive. As a ANTLR newbie it's difficult to get my head around solving this. I've read "Resolving Non-LL(*) Conflicts" in the ANTLR reference book, but I still don't see the solution. Any pointers? LPAREN : ( '(' ) ; RPAREN : ( ')' ); AND : ( 'AND' | '&' | 'EN' ) ; OR : ( 'OR' | '|' | 'OF' ); NOT : ('-' | 'NOT' | 'NIET' ); WS : ( ' ' | '\t' | '\r' | '\n' ) {$channel=HIDDEN;} ; WORD : (~( ' ' | '\t' | '\r' | '\n' | '(' | ')'

Antrl3 conditional tree rewrites

痴心易碎 提交于 2019-12-07 17:31:52
问题 Stackoverflow. Continuing on my journey into Antlr (Previous questions may provide additional clues on what I'm trying to achieve! Q1 - How do I make a tree parser and Q2 - Solving LL recursion problem) I've hit yet another roadblock I cannot flathom. Basically (I believe) the expression rule in my grammar needs to either create a new root node depending on the number of datatype s it has matched. I have put together an example to try best describe what I mean: Given the following input:

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

风格不统一 提交于 2019-12-07 16:59:19
问题 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

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

南笙酒味 提交于 2019-12-07 15:38:12
问题 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.

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

三世轮回 提交于 2019-12-07 15:27:03
问题 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