Search Results

Search found 174 results on 7 pages for 'antlr'.

Page 1/7 | 1 2 3 4 5 6 7  | Next Page >

  • Antlr question: cannot get Antlr tool to compile simple file from ANTLRWorks

    - by Don Henton
    Here is the grammar file: grammar fred; test : 'fred'; Here is the batch file to launch the tool: SET JAVA_HOME=C:\Program Files\Java\jdk1.6.0_24 SET PATH=%PATH%;%JAVA_HOME%\bin SET ANTLR_HOME=c:/users/don/workspace/antlrAssign/lib/ java -cp %ANTLR_HOME%/antlr-3.3-complete.jar antlr.Tool fred.g Here's the result: ANTLR Parser Generator Version 2.7.7 (20060906) 1989-2005 fred.g:1:1: unexpected token: grammar error: Token stream error reading grammar(s): fred.g:3:19: expecting ''', found 'r' fred.g:1:1: rule grammar trapped: fred.g:1:1: unexpected token: grammar TokenStreamException: expecting ''', found 'r' Prior postings refer to "org.antlr.Tool" but the 3.3 jar has it located as above. The idea was to create a debug version of a tree parser, and according to the documentation, you have to use the command line tool. Has anyone seen this before? Am I nuts? It's two lines long and its dying on the first word in the file. Of course this compiles in antlrworks. Any help appreciated, I can't afford any more adjustments to my medications.

    Read the article

  • Removing Left Recursion in ANTLR

    - by prosseek
    As is explained in http://stackoverflow.com/questions/2652060/removing-left-recursion , there are two ways to remove the left recursion. Modify the original grammar to remove the left recursion using some procedure Write the grammar originally not to have the left recursion What people normally use for removing (not having) the left recursion with ANTLR? I've used flex/bison for parser, but I need to use ANTLR. The only thing I'm concerned about using ANTLR (or LL parser in genearal) is left recursion removal. In practical sense, how serious of removing left recursion in ANTLR? Is this a showstopper in using ANTLR? Or, nobody cares about it in ANTLR community? I like the idea of AST generation of ANTLR. In terms of getting AST quick and easy way, which method (out of the 2 removing left recursion methods) is preferable?

    Read the article

  • antlr: is there a simple example ?

    - by Eli
    I'd like to get started with antlr, but after spending a few hours reviewing the examples at the antlr.org site, I still cant get a clear understanding of the grammar to java process. is there some simple example? something like a four operations calculator implemented with antlr going through the parser definition and all the way to the java source code?

    Read the article

  • What are the disadvantages of using Antlr?

    - by ajay
    I've worked on Flex, Bison few years ago during my undergraduate studies. However, I don't remember much about it now. Recently, I have come to hear about Antlr. Would you recommend that I learn Antlr or better to brush up Flex/Bison. Does Antlr have more/less features than Flex/Bison ? Thanks,

    Read the article

  • ANTLR parser hanging at proxy.handshake call

    - by Peter Boughton
    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(MyLexer); ES3Parser MyParser = new ES3Parser( MyTokens ); // hangs here ES3Parser.program_return MyReturn = MyParser.program(); I've tracked down the problem to inside the ES3Parser constructor, where it's calling the function proxy.handshake() - before this line I can successfully do System.out.println("text") but after it I get nothing. So, how do I go about finding out why it's hanging, and stopping it - or even just bypassing this section (can/should I disable debugging?) - so long as that lets it work and allows me to get on with doing useful stuff.

    Read the article

  • ANTLR JavaScript Target

    - by kunalsawlani
    Hello, I have been using ANTLR to generate a parser + tree grammar for a mark up language with Java target which works fine. Now I am trying to get the target in JavaScript to use it in my web browser. However, I have not been able to locate any good documentation on how to go about doing this. I am using eclipse with ANTLR IDE, and when i specify the language as JavaScript, I get the following errors. Multiple markers at this line (10): internal error: group JavaScript does not satisfy interface ANTLRCore: mismatched arguments on these templates [treeParser(grammar, name, scopes, tokens, tokenNames, globalAction, rules, numRules, bitsets, labelType, ASTLabelType, superClass, members, filterMode)] (10): internal error: java.util.NoSuchElementException: no such attribute: filterMode in template context [treeParser] If anyone could help me out with this or point me to some material which I could read about the JavaScript target with ANTLR, it would be great. Thanks

    Read the article

  • Exception declared on ANTLR grammar rule ignored

    - by Kaleb Pederson
    I have a tree parser that's doing semantic analysis on the AST generated by my parser. It has a rule declared as follows: transitionDefinition throws WorkflowStateNotFoundException: /* ... */ This compiles just fine and matches the rule syntax at the ANTLR Wiki but my exception is never declared so the Java compiler complains about undeclared exceptions. ./tool/src/main/antlr3/org/antlr/grammar/v3/ANTLRv3.g shows that it's building a tree (but I'm not actually positive if it's the v2 or v3 grammar that ANTLR 3.2 is using): throwsSpec : 'throws' id ( ',' id )* -> ^('throws' id+) ; I know I can make it a runtime exception, but I'd like to use my exception hierarchy. Am I doing something wrong or should that syntax work?

    Read the article

  • An interesting project to implement to learn Antlr

    - by ajay
    Hi, I am learning Antlr from the book 'The Definitive Antlr reference'. I am still in the beginning stages. I like to do hands on stuff, so I was thinking it would be a great learning experience to do a good sample project. I am looking for a decently sized project, not too big. But just big and complicated enough to help me learn Antlr well. Your inputs will be greatly appreciated! Thanks!

    Read the article

  • antlr: Best practice to integrate generated parser into the system

    - by green
    Here is the background, I am trying to create a DSL to allow customer write simple scripts to query into our mongodb based database. I choose antlr to implement the DSL. From my understanding (and pls let me know if it's not correct) there are 2 approaches to integrate antlr generated parser into the system: Embed code into the grammar file so that the generated parser could be used directly to make query to the database and return result in a certain format (e.g. json encoded) Keep the parser purely a parser, after feed the DSL file to it, and construct the query in another class by retrieving the AST from generated parser class So antlrers, which one do you think is the way I as an antlr newbie should go? Can you list the pros and cos of each approach, or you have other way to recommend?

    Read the article

  • ANTLR and c# - where to start?

    - by mehanicar
    I want to integrate ANTLR with my c# desktop application. I could not find many articles that talk about integration of ANTLR wirh C#. Can you recommend a book that explains it step by step through real world examples?

    Read the article

  • ANTLR, Dynamic variables

    - by JTS
    Hello, I have an ANTLR grammar that can parse and evaluate simple expressions like 1+2*4, etc. What I would like to do is to evaluate expressions like 2+$a-$b/4 where the $ variables are dynamic variables, that come from an external source and are continuously updated. Is there any design pattern on how to do this using ANTLR, best practices, etc? Shall I "substring" the $a with the updated value ($a - 4.34) A nicer way to do this? Thx

    Read the article

  • Why does ANTLR not parse the entire input?

    - by Martin Wiboe
    Hello, I am quite new to ANTLR, so this is likely a simple question. I have defined a simple grammar which is supposed to include arithmetic expressions with numbers and identifiers (strings that start with a letter and continue with one or more letters or numbers.) The grammar looks as follows: grammar while; @lexer::header { package ConFreeG; } @header { package ConFreeG; import ConFreeG.IR.*; } @parser::members { } arith: term | '(' arith ( '-' | '+' | '*' ) arith ')' ; term returns [AExpr a]: NUM { int n = Integer.parseInt($NUM.text); a = new Num(n); } | IDENT { a = new Var($IDENT.text); } ; fragment LOWER : ('a'..'z'); fragment UPPER : ('A'..'Z'); fragment NONNULL : ('1'..'9'); fragment NUMBER : ('0' | NONNULL); IDENT : ( LOWER | UPPER ) ( LOWER | UPPER | NUMBER )*; NUM : '0' | NONNULL NUMBER*; fragment NEWLINE:'\r'? '\n'; WHITESPACE : ( ' ' | '\t' | NEWLINE )+ { $channel=HIDDEN; }; I am using ANTLR v3 with the ANTLR IDE Eclipse plugin. When I parse the expression (8 + a45) using the interpreter, only part of the parse tree is generated: http://imgur.com/iBaEC.png Why does the second term (a45) not get parsed? The same happens if both terms are numbers. Thank you, Martin Wiboe

    Read the article

  • Antlr MismatchedSetException During Interpretation

    - by user1646481
    I am new to Antlr and I have defined a basic grammar using Antlr 3. The grammar compiles and ANTLRWorks generates the Parser and Lexer code without any problems. The grammar can be seen below: grammar i; @header { package i; } module : 'Module1'| 'Module2'; object : 'I'; objectType : 'Name'; filters : EMPTY | 'WHERE' module; table : module object objectType; STRING : ('a'..'z'|'A'..'Z')+; EMPTY : ' '; The problem is that when I interpret the table Parser I get a MismatchedSetException. This is due to having the EMPTY. As soon as I remove EMPTY from the grammar, the interpretation works. I have looked on the Antlr website and some other examples and the Empty space is ' '. I am not sure what to do. I need this EMPTY. As soon as I change the EMPTY to be the following: EMPTY : ''; instead of: EMPTY : ' '; It actually interprets it. However, I am getting the following Exception: Interpreting... [10:57:23] problem matching token at 1:4 NoViableAltException(' '@[1:1: Tokens : ( T__4 | T__5 | T__6 | T__7 | T__8 | T__9 | T__10 | T__11 | T__12 | T__13 | T__14 | T__15 | T__16 );]) [10:57:23] problem matching token at 1:9 NoViableAltException(' '@[1:1: Tokens : ( T__4 | T__5 | T__6 | T__7 | T__8 | T__9 | T__10 | T__11 | T__12 | T__13 | T__14 | T__15 | T__16 );]) When I take out the EMPTY, there are no problems at all. I hope you can help.

    Read the article

  • How to create an AST with ANTLR from a hierarchical key-value syntax

    - by Brabster
    I've been looking at parsing a key-value data format with ANTLR. Pretty straightforward, but the keys represent a hierarchy. A simplified example of my input syntax: /a/b/c=2 /a/b/d/e=3 /a/b/d/f=4 In my mind, this represents a tree structured as follows: (a (b (= c 2) (d (= e 3) (= f 4)))) The nearest I can get is to use the following grammar: /* Parser Rules */ start: (component NEWLINE?)* EOF -> (component)*; component: FORWARD_SLASH ALPHA_STRING component -> ^(ALPHA_STRING component) | FORWARD_SLASH ALPHA_STRING EQUALS value -> ^(EQUALS ALPHA_STRING value); value: ALPHA_STRING; /* Lexer Rules */ NEWLINE : '\r'? '\n'; ALPHA_STRING : ('a'..'z'|'A'..'Z'|'0'..'9')+; EQUALS : '='; FORWARD_SLASH : '/'; Which produces: (a (b (= c 2))) (a (b (d (= e 3)))) (a (b (d (= f 4)))) I'm not sure whether I'm asking too much from a generic tool such as ANTLR here, and this is as close I can get with this approach. That is, from here I consume the parts of the tree and create the data structure I want by hand. So - can I produce the tree structure I want directly from a grammar? If so, how? If not, why not - is it a technical limitation in ANTLR or is it something more CS-y to do with the type of language involved?

    Read the article

  • Coco/R vs. ANTLR

    - by Eamon Nerbonne
    I'm evaluating using Coco/R vs. ANTLR for use in a C# project as part of what's essentially a scriptable mail-merge functionality. To parse the (simple) scripts, I'll need a parser. I've focussed on Coco/R and ANTLR because both seem fairly mature and well-maintained and capable of generating decent C# parsers. Neither seem to be trivial to use either, however, and simplicity is something I'd appreciate - particularly maintainability by others. Does anyone have any recommendations to make? What are the pros/cons of either for a parsing a small language - or am I looking into the wrong things entirely? How well do these integrate into a typical continuous integration setup? What are the pitfalls? Related: Well, many questions, such as 1, 2, 3, 4, 5.

    Read the article

  • Improving ANTLR DSL parse-error messages

    - by Dan Fabulich
    I'm working on a domain-specific language (DSL) for non-programmers. Non-programmers make a lot of grammar mistakes: they misspell keywords, they don't close parentheses, they don't terminate blocks, etc. I'm using ANTLR to generate my parser; it provides a nifty mechanism for handling RecognitionExceptions to improve error handling. But I'm finding it pretty hard to develop good error-handling code for my DSL. At this point, I'm considering ways to simplify the language to make it easier for me to provide users with high-quality error messages, but I'm not really sure how to go about this. I think I want to reduce the ambiguity of errors somehow, but I'm not sure how to implement that idea in a grammar. In what ways can I simplify my language to improve parse-error messages for my users? EDIT: Updated to clarify that I'm interested in ways to simplify my language, not just ANTLR error-handling tips in general. (Though, thanks for those!)

    Read the article

  • ANTLR: using stringTemplate

    - by Kevin Won
    (I'm a Noob with Antlr)... I'm having difficulties getting my grammar with StringTemplates. Basically I'm trying to write a little DSL. I can get my grammar the way I want (it parses correctly), but I can't get the generation of the target code to work with templates. So here's a snippet of my grammar: grammar Pfig; options { output=template; language=CSharp2; } conf : globalName ; globalName : 'GlobalName:' ID -> localConf(name ={$ID.text}) ; I simplified it quite a bit just to get the essence across. Basically, when the lex/parse comes across `GlobalName: Foo' I want it to spit out text based on the StringTemplate called 'localConf'. Super straightforward. So now, let's fire up the parser in a test app and have it process an input file. // C# processing a file with the lex/parser. // the 'app.pfig' file just has one line that reads 'GlobalName: Bla' using (FileStream fs = File.OpenRead("c:\\app.pfig")) { PfigParser parser = new PfigParser(new CommonTokenStream( new PfigLexer(new ANTLRInputStream(fs)))); using (TextReader tr = File.OpenText("./Pfig.stg")) { parser.TemplateLib = new StringTemplateGroup(tr); } var parseResult = parser.conf(); string code = parseResult.Template.ToString(); // Fail: template is null } I can step through the parser code and see that it correctly identifies my text and applies the stringTemplate correctly. The problem is that since this 'globalName' rule is a subrule of 'conf' it doesn't get executed directly--the method just finds it and returns. But the calling 'Conf' method does not keep the return value from the subrule--it goes to thin air. This means that my resultant template on the last line is null. If I get rid of the 'conf' rule in my grammar and call 'globalName' directly, it will work (since it's the only rule on the stack). But I obviously want more than one rule. I've generated the parser in Java and it does the same thing: // antlr generated parser code public PfigParser.conf_return conf() // throws RecognitionException [1] { PfigParser.conf_return retval = new PfigParser.conf_return(); try { { PushFollow(FOLLOW_globalName_in_conf30); globalName(); // <- it calls globalName() but doesn't keep the return. state.followingStackPointer--; } retval.Stop = input.LT(-1); } // snip It's simple to see I don't get some basic concept with how the Template approach is supposed to work with Antlr. I'm quite sure this is my problem but I'm a loggerheads to know what I'm doing wrong... the examples I've seen don't really show real-world template emission of code.

    Read the article

  • ANTLR lexer mismatches tokens

    - by Barry Brown
    I have a simple ANTLR grammar, which I have stripped down to its bare essentials to demonstrate this problem I'm having. I am using ANTLRworks 1.3.1. grammar sample; assignment : IDENT ':=' NUM ';' ; IDENT : ('a'..'z')+ ; NUM : ('0'..'9')+ ; WS : (' '|'\n'|'\t'|'\r')+ {$channel=HIDDEN;} ; Obviously, this statement is accepted by the grammar: x := 99; But this one also is: x := @!$()()%99***; Output from the ANTLRworks Interpreter: What am I doing wrong? Even other sample grammars that come with ANTLR (such as the CMinus grammar) exhibit this behavior.

    Read the article

  • Conditionals in Antlr String Templates

    - by Pat Long - Munkii Yebee
    We are using Antlr StringTemplates to give control over how a Entity's Name is output. The basic Stringtemplate is $FirstName$ $Initial$ $LastName$, $Suffix$, $Degree$ I want to add some smarts to that template so that the commas are only output when necessary i.e. The first comma is only output when there is a Suffix or Degree and the second commas is only output if there is a suffix. I tried the following template string bit it does not work. I guess I have misunderstood $FirstName$ $Initial$ $LastName$ <if(Suffix|Degree)>,<endif>, $Suffix$ <if(Suffix)>,<endif> $Degree$ If it helps we process the templates using this C# StringTemplate stringtemplate = new Antlr.StringTemplate.StringTemplate(template.Data); foreach (Pair<string, string> pair in dictionary) { if (pair.First != null && pair.Second != null) { stringtemplate.SetAttribute(pair.First, pair.Second); } } return stringtemplate.ToString();

    Read the article

  • Looking for Antlr Grammar syntaxt highlight in VS2010

    - by David Mårtensson
    I am looking for some way to edit antlr grammar files directly within VS2010 with syntax highlight. I have used antlrworks a lot but it has the drawback that I have to start antlrworks separately and then browse to the file I want to edit, do the changed and save. For minor fixes I do not need all the tools in Antlrworks but I still would like the syntax highlight. But I have not been able to get VS2010 to open antlrworks with the right file and I have found no other way to get syntax highlight directly within VS2010 editor, it just opens as plain text. I can get visual studio to open antlrworks but it will open with only the last set of files it had open, not the one I clicked on. So my question(s) are: Is there a way to get antlrworks to open with the right file when I double click in it in visual studio project explorer? Is there any other way to get correct syntax highlight for antlr grammar files within visual studio (or with another editor, preferably not one that costs money, but if there are no free ones a commercial one might be an option).

    Read the article

  • AST with fixed nodes instead of error nodes in antlr

    - by ahe
    I have an antlr generated Java parser that uses the C target and it works quite well. The problem is I also want it to parse erroneous code and produce a meaningful AST. If I feed it a minimal Java class with one import after which a semicolon is missing it produces two "Tree Error Node" objects where the "import" token and the tokens for the imported class should be. But since it parses the following code correctly and produces the correct nodes for this code it must recover from the error by adding the semicolon or by resyncing. Is there a way to make antlr reflect this fixed input it produces internally in the AST? Or can I at least get the tokens/text that produced the "Tree Node Errors" somehow? In the C targets antlr3commontreeadaptor.c around line 200 the following fragment indicates that the C target only creates dummy error nodes so far: static pANTLR3_BASE_TREE errorNode (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_TOKEN_STREAM ctnstream, pANTLR3_COMMON_TOKEN startToken, pANTLR3_COMMON_TOKEN stopToken, pANTLR3_EXCEPTION e) { // Use the supplied common tree node stream to get another tree from the factory // TODO: Look at creating the erronode as in Java, but this is complicated by the // need to track and free the memory allocated to it, so for now, we just // want something in the tree that isn't a NULL pointer. // return adaptor->createTypeText(adaptor, ANTLR3_TOKEN_INVALID, (pANTLR3_UINT8)"Tree Error Node"); } Am I out of luck here and only the error nodes the Java target produces would allow me to retrieve the text of the erroneous nodes?

    Read the article

  • ANTLR Tree Grammar and StringTemplate Code Translation

    - by Behrooz Nobakht
    I am working on a code translation project with a sample ANTLR tree grammar as: start: ^(PROGRAM declaration+) -> program_decl_tmpl(); declaration: class_decl | interface_decl; class_decl: ^(CLASS ^(ID CLASS_IDENTIFIER)) -> class_decl_tmpl(cid={$CLASS_IDENTIFIER.text}); The group template file for it looks like: group My; program_decl_tmpl() ::= << *WHAT?* >> class_decl_tmpl(cid) ::= << public class <cid> {} >> Based on this, I have these questions: Everything works fine apart from that what I should express in WHAT? to say that a program is simply a list of class declarations to get the final generated output? Is this approach averagely suitable for not so a high-level language? I have also studied ANTLR Code Translation with String Templates, but it seems that this approach takes much advantage of interleaving code in tree grammar. Is it also possible to do it as much as possible just in String Templates?

    Read the article

  • ANTLR grammar from bison

    - by Iulian Serbanoiu
    Hello, I'm trying to translate a grammar from bison to ANTLR. The grammar itself is pretty simple in bison but I cannot find a simple way for doing this. Grammar in bison: expr = expr or expr | expr and expr | (expr) Any hints/links/pointers are welcome. Thanks, Iulian

    Read the article

1 2 3 4 5 6 7  | Next Page >