antlr

Looking for Antlr 3 / C sample main()

I see a few sample main() for C floating about, e.g. http://www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3 and http://www.antlr.org/api/C/index.html The dereference seems to be AST. I don't know what that is , and - please excuse me - don't want to if I can avoid it. I woudl like to just define the lexer & gramm...

String matching problem (can I prioritize?)

I have a (badly specified) requirement that I recognize certain keywords, but there is also provision for 'any string' ... For instance, in the input "let's have a " I have to handle == "beer", == "curry" and == anything else at all (in theory, the keywords beer & curry have priority over all other strings). When I try to define th...

Dynamicall updating rules at run-time

When sending an AT command it is normally terminated by \r\n, but, in fact, these are really two 'register variables' S3 and S4. By default S3=='\r' and S4=='\n', but the user can change these at runtime with the command ATSx= How can I handle this in my Antlr lexer/parser? Each command has the form AT[parameters]S3S4, how can I hand...

AS3 Grammar: Most accurate

I'm looking for an accurate AS3 grammar (format in not an issue, but I presume ANTLR will feature the most) to use for a practice grammar I'm making. What is the most accurate grammar available for AS3? ...

How to match a string, but case-insensitive?

Let's say that I want to match "beer", but don't care about case sensitivity. Currently I am defining a token to be ('b'|'B' 'e'|'E' 'e'|'E' 'r'|'R') but I have a lot of such and don't really want to handle 'verilythisisaverylongtokenindeedomyyesitis'. The antlr wiki seems to suggest that it can't be done (in antlr) ... http://www.an...

Which Antlr book is "best" ?

I am short on funds and can only afford one. I am a total novice. Thanks in advance for any help. ...

ANTLR “Cannot launch the debugger. Time-out waiting to connect to the remote parser.”

One of my ANTLR grammars running in AntlrWorks throws: “Cannot launch the debugger. Time-out waiting to connect to the remote parser.” In the past this message usxually goes away but this one is persistent. On searching the ANTLR lists (e.g. http://www.antlr.org/pipermail/antlr-interest/2009-June/034659.html) there are hints that the ...

Parsing string interpolation in ANTLR

I'm working on a simple string manipulation DSL for internal purposes, and I would like the language to support string interpolation as it is used in Ruby. For example: name = "Bob" msg = "Hello ${name}!" print(msg) # prints "Hello Bob!" I'm attempting to implement my parser in ANTLRv3, but I'm pretty inexperienced with using ANTLR...

antlr : C++ target with visual studio 2008

the Antlr site is not clear on the subject of compiling a grammar for C++, it says that the tool will generate C code compatible with C++, what dose it mean? will I be able to compile this code with VS 2008 ? ...

How to lex 0 .. 255 ?

I want to accept a decimal number between 0 and 255. This is the best I can come up with: fragment my_token : ('0'..'9') | // 0 -> 9 ('1'..'9' '0'..'9') | // 0 -> 99 ('1' '0'..'9' '0'..'9') | // 100 -> 199 ('2' '0'..'4' '0'..'9') | // 200 -> 249 ('25' '0'..'5'); // 250 -...

Check sql script valid

As part of a release we run a load of PL/SQL scripts against a database. Recently someone left the ; off the end of a line in one script that was called another script so this meant that script did not get run. Because this did not cause an error, it just didn't get run, it took quite a while to track down what had happened. I want to c...

ANTLR named function arguments / parameters in any order

I'm been looking for a way to have named function arguments / parameters appear in any order in ANTLR. Does anyone know if there is syntax to ignore order in an ANTLR parser expression? Say there is a function foo in the language that can take two named parameters: x and y. Since they are named parameters, I'd like them to be able to be...

trying to find a zip file for ANTLR

I'm trying to follow the steps in this tutorial and the files listed in step 5 (part 1) don't make sense as ther referenced zip file (DOT-NET-runtime-3.1.3.zip) is not in the listed folder (or it's equivalent in 3.2). Where did it go? ...

Take input from function parameters, not a file

All of the examples which I see read in a file the lex & parse it. I need to have a function which takes a string (char *, I'm generating C code) as parameter, and acts upon that. How can I do that best? I thought of writing the string to a stream, then feeding that to the lexer, but it doesn't feel right. Is there any better way? Th...

ANTLRWorks error compiling grammar: "syntax error: invalid char literal: INVALID"

I wrote a stub for a grammar (only matches comments so far), and it's giving me the error "syntax error: invalid char literal: <INVALID>". Moreover, i've tracked down the error to being in the following command: ... ~LINE_ENDING* ... LINE_ENDING : ( '\n' | '\r' | '\r\n'); Can someone help me fix this? ...

Character Consumption Question

If i have a subrule like the following: .. (~']' ~']')* ... will it only match an even number of characters? ...

Remove whitespace, but do so last?

I am attempting to parse Lua, which depends on whitespace in some cases due to the fact that it doesn't use braces for scope. I figure that by throwing out whitespace only if another rule doesn't match is the best way, but i have no clue how to do that. Can someone help me? ...

How do i add parens to this rule?

I have a left-recursive rule like the following: EXPRESSION : EXPRESSION BINARYOP EXPRESSION | UNARYOP EXPRESSION | NUMBER; I need to add parens to it but i'm not sure how to make a left parens depend on a matching right parens yet still optional. Can someone show me how? (or am i trying to do entirely too much in lexing, and shoul...

Handling invalid input in the Lexer / Parser

so, I am parsing Hayes modem AT commands. Not read from a file, but passed as char * (I am using C). 1) what happens if I get something that I totally don't recognize? How do I handle that? 2) what if I have something like my_token: "cmd param=" ("value_1" | "value_2"); and receive an invalid value for "param"? I see some advice to ...

How to exclude more than one character in rule?

I'm trying to write a string matching rule in ANTLRWorks, and i need to match either escaped quotes or any non quote character. I can match escaped quotes but I'm having trouble with the other part: ~'\'' | ~'\"' will end up matching everything and ~'\'\"' seems to be ignored by the grammar generator (at least the visual display). What s...