I want to generate C code. I will not be reading from an input file, one line at a time *as, for instance, a compiler might). Rather, I will be parsing user input as it arrives, one line at a time.
I would prefer to detect and handle bad input in the lexer/parser, e.g
/* lexer tokens */
foo : "FOO";
bar : "BAR";
baz : "BAZ";
/* grammar...
I'm still on my quest for a really simple language and I know now that there are none. So I'm writing one myself using ANTLR3.
I found a really great example in this answer:
Exp.g:
grammar Exp;
eval returns [double value]
: exp=additionExp {$value = $exp.value;}
;
additionExp returns [double value]
: m1=multiplyE...
I'm attemping to learn language parsing for fun...
I've created a ANTLR grammar which I believe will match a simple language I am hoping to implement. It will have the following syntax:
<FunctionName> ( <OptionalArguments>+) {
<OptionalChildFunctions>+
}
Actual Example:
ForEach(in:[1,2,3,4,5] as:"nextNumber") {
Print(messa...
Hello,
I am trying to pick out all tokens in a text and need to match all Ascii and Unicode characters, so here is how I have laid them out.
fragment CHAR : ('A'..'Z') | ('a'..'z');
fragment DIGIT : ('0'..'9');
fragment UNICODE : '\u0000'..'\u00FF';
Now if I write my token rule as:
TOKEN : (CHAR|DIGIT|UNICODE)+;
I get ...
I'm a enthusiast AntlrWorks user. I built a very nice little DSL with it (and antlr of course) that lets me specify interesting data structures using a very simple english-like syntax. The next step is for me to help the user while they type and to do that I would like to have access to the parsing information in exactly the same way as ...
Is it possible to do what I'm attempting here? Or, perhaps I'm approaching it wrong?
arrayDef
: { int c = 0; }
('['']' {c++;})+
-> ARRAY /* somehow inject c here */
;
...
Hi,
im currently trying to generate LLVM IR with ANTLR3.
But the problem ist, that i need the C target (C++ would be better but is not working yet, or is it?) but from C i can't call the LLVM C++ API for Building the IR.
The Tutorial from Terence Parr uses Java and the StringTemplate lib. But as i know the StringTemplate lib ist not a...
Hi,
Is the ANTLR3 C Target Thread Safe?
Thx
...
I'm trying to write an ANTLR3 grammar that generates HTML output using StringTemplate. To avoid having to escape all the HTML tags in the template rules (e.g. \<p\><variable>\</p\>), I'd prefer to use dollar as the delimiter for StringTemplate (e.g. <p>$variable$</p>).
While the latter seems to be the default when StringTemplate is used...
I've got a really simple ANTLR grammar that I'm trying to get working, but failing miserably at the moment. Would really appreciate some pointers on this...
root : (keyword|ignore)*;
keyword : KEYWORD;
ignore : IGNORE;
KEYWORD : ABBRV|WORD;
fragment WORD : ALPHA+;
fragment ALPHA : 'a'..'z'|'A'..'Z';
fragment ABBRV : WOR...
I'm trying to learn ANTLR and at the same time use it for a current project.
I've gotten to the point where I can run the lexer on a chunk of code and output it to a CommonTokenStream. This is working fine, and I've verified that the source text is being broken up into the appropriate tokens.
Now, I would like to be able to modify the...
I am trying to write a comment matching rule in ANTLR, which is currently the following:
LINE_COMMENT
: '--' (options{greedy=false;}: .)* NEWLINE {Skip();}
;
NEWLINE : '\r'|'\n'|'\r\n' {Skip();};
This code works fine except in the case that a comment is the last characters of a file, in which case it throws a NoViableAlt exce...
I am reorganizing my grammar into two files in order to accomodate a tree grammar; Lua.g and LuaGrammar.g. Lua.g will have all of my lexer rules, and LuaGrammar.g will have all of my tree grammar and parser rules. However, when i try and compile LuaGrammar.g i get the following error:
[00:28:37] error(10): internal error: C:\Users\RCIX...
I'm trying to use an ANTLR v3.2-generated parser in a C++ project using C as the output language. The generated parser can, in theory, be compiled as C++, but I'm having trouble dealing with C++ types inside parser actions. Here's a C++ header file defining a few types I'd like to use in the parser:
/* expr.h */
enum Kind {
PLUS,
MI...
I have an AST generated via ANTLR, and I need to convert it to a DLR-compatible one (Expression Trees). However, it would seem that i can't use tree pattern matchers for this as expression trees need their subtrees at instantiation (which i can't get). What solution would be best for me to use?
...
EDITED according to WayneH's grammar
Here's what i have in my grammar file.
grammar pfinder;
options {
language = Java;
}
sentence
: ((words | pronoun) SPACE)* ((words | pronoun) ('.' | '?'))
;
words
: WORDS {System.out.println($text);};
pronoun returns [String value]
: sfirst {$value = $sfirst.value; System.o...
I'm finding myself challenged on how to properly format rewrite rules when certain conditions occur in the original rule.
What is the appropriate way to rewrite this:
unaryExpression: op=('!' | '-') t=term
-> ^(UNARY_EXPR $op $t)
Antlr doesn't seem to like me branding anything in parenthesis with a label and "op=" fails. Also, I've...
How can I know during parsing which rule is currently matched?
I'd like to automatically build an XML (or other objectal hierarchy) representing the parsed input, using rule names, without the need of using grammar actions or trees.
Is this possible?
Many thanks,
Yaakov
...
I'm just playing with ANTLR and decided to try parsing JavaScript with it. But I hit the wall in dealing with optional ';' in it, where statement end is marked by newline instead. Can it be done in some straightforward way?
Just a simple grammar example that doesn't work
grammar optional_newline;
def : statements ;
statements ...
In Antlrworks I get this error:
[18:21:03] Checking Grammar Grammar.g...
[18:21:26] Grammar.java:12: code too large
[18:21:26] public static final String[] tokenNames = new String[] {
[18:21:26] ^
[18:21:26] 1 error
Using instead the generated code in a Java project works normally. What can be...