javacc

JavaCC lexical error on any type of whitespace

你。 提交于 2019-12-05 12:01:39
I cleary have the unicode whitespace characters defined in my SKIP token like so: SKIP { " " | "\r" | "\n" | "\t" } However, when I run Java CC it parses all the tokens fine until I hit any of the above mentioning white space characters and it throws the following error: Exception in thread "main" prjct1.TokenMgrError: Lexical error at line 1, column 25. Encountered: "\r" (13), after : "Random:Word:Here" So as you can see it runs fine until it hits the "\r". I get the same error with " ", "\n", and "\t". Any thoughts? thanks Make sure you have a colon between the SKIP and your bracket. SKIP: {

Javacc Unreachable Statement

▼魔方 西西 提交于 2019-12-04 15:18:19
In my grammar there are production rules for expressions and fragments which originally contained indirect left recursion. This is the rules after I removed the recursion from them. String expression() #Expression : {String number; Token t;} { number = fragment() ( (t = <Mult_Sign> number = fragment()) ) {return number;} } String fragment() #void : {String t;} { t = identifier() {return t;} | t = number() {return t;} | (<PLUS> | <MINUS> ) fragment() | <LBR> expression() <RBR> } These production rules are used when trying to parse a condition in the grammar. However the ordering of the

Getting started with JavaCC

拟墨画扇 提交于 2019-12-04 05:54:48
I am new to JavaCC and cannot figure out how to get it running. I am using Mac OS X and I installed javacc-6.0.zip and unzipped it. I am unable to make the javacc script accessible from my path as on typing javacc on the terminal I get the following message: -bash: javacc: command not found How do I make the javacc script accessible from my path? My unzipped folder javacc-6.0 is in the following directory: /Users/Rishabh/Desktop/javacc So I do the following on the terminal: PATH=$PATH\:/Users/Rishabh/Desktop/javacc/javacc-6.0/ Typing javacc next gives me the same message. The version of JavaCC

Anybody has some links to javacc tutorials? [closed]

匆匆过客 提交于 2019-12-03 23:03:43
It's very difficult to find this kind of document online. I found one in JAVAWORLD, but this one does not cover the jjTree and visitor one. Does anybody happen to have some links to the tutorials? zimbu668 Its been a while, but I found this tutorial very helpful on a previous project. I was able to create a query language for our application in a few days with basically no previous experience with javacc. I've not read it but while looking for the other tutorial I also found this one . You can find a bunch of blog posts I've made regarding various JavaCC/JJTree topics on my JavaCC book's web

JavaCC dump method to print AST

倾然丶 夕夏残阳落幕 提交于 2019-12-02 18:52:28
问题 I am using JavaCC to print an AST in a particular format. I need it to be like this : LetNode( Identier(X), ExprNode( PlusNode( IntegerLiteral(8), IntegerLiteral(2) ))) but I am getting: Start(LetNode(Identifier(x)(ExprNode(IntegerLiteral(5)(PlusNode(IntegerLiteral(5)())) I am using the dump method to print this: public void dump(String prefix) { System.out.print(toString(prefix)); System.out.print("("); if (children != null) { for (int i = 0; i < children.length; ++i) { SimpleNode n =

How to implement JavaScript automatic semicolon insertion in JavaCC?

折月煮酒 提交于 2019-12-02 15:34:27
问题 I am finishing my ECMAScript 5.1/JavaScript grammar for JavaCC. I've done all the tokens and productions according to the specification. Now I'm facing a big question which I don't know how to solve. JavaScript has this nice feature of the automatic semicolon insertion: What are the rules for JavaScript's automatic semicolon insertion (ASI)? To quote the specifications, the rules are: There are three basic rules of semicolon insertion: When, as the program is parsed from left to right, a

Make a calculator's grammar that make a binary tree with javacc

半腔热情 提交于 2019-12-02 10:23:05
I need to make a simple calculator (with infix operator) parser that handle the operators +,-,*,/ and float and variable. To make this I used javacc, and I have made this grammar with jjtree. It works but it doesn't ensure that the final tree will be a binary tree, which I need. I want something like 5*3+x-y to generate the following tree : * / \ 5 + / \ 3 - / \ x y What would be a proper grammar to do that, that would not be left-recursive ? Something like the following will give you the tree you asked for. void sum(): {} { term() [ plus() sum() | minus() sum() | times() sum() | divide() sum(

How to implement JavaScript automatic semicolon insertion in JavaCC?

佐手、 提交于 2019-12-02 08:28:25
I am finishing my ECMAScript 5.1/JavaScript grammar for JavaCC . I've done all the tokens and productions according to the specification. Now I'm facing a big question which I don't know how to solve. JavaScript has this nice feature of the automatic semicolon insertion: What are the rules for JavaScript's automatic semicolon insertion (ASI)? To quote the specifications , the rules are: There are three basic rules of semicolon insertion: When, as the program is parsed from left to right, a token (called the offending token) is encountered that is not allowed by any production of the grammar,

How to use backslash escape char for new line in JavaCC?

邮差的信 提交于 2019-12-01 23:30:55
I have an assignment to create a lexical analyser and I've got everything working except for one bit. I need to create a string that will accept a new line, and the string is delimited by double quotes. The string accepts any number, letter, some specified punctuation, backslashes and double quotes within the delimiters. I can't seem to figure out how to escape a new line character. Is there a certain way of escaping characters like new line and tab? Here's some of my code that might help < STRING : ( < QUOTE> (< QUOTE > | < BACKSLASH > | < ID > | < NUM > | " " )* <QUOTE>) > < #QUOTE : "\"" >

Can JavaCC distinguish token by its context?

情到浓时终转凉″ 提交于 2019-12-01 17:21:22
Basic requirement is use keyword as identifier, so I want to distinguish the token from it's context.(e.g. class is a keyword, but we allowed a variable named class ). In java, this is possible, but it's so hard, here is how I do it TOKEN : { <I_CAL: "CAL"> : DO_CAL | <I_CALL: "CALL"> | <I_CMP: "CMP"> | <I_EXIT: "EXIT"> | <I_IN: "IN"> | <I_JMP: "JMP"> | <I_JPC: "JPC"> : NEED_CMP_OP | <I_LD: "LD"> : NEED_DATA_TYPE | <I_NOP: "NOP"> | <I_OUT: "OUT"> | <I_POP: "POP"> | <I_PUSH: "PUSH"> | <I_RET: "RET"> | <I_DATA: "DATA"> : DO_DATA | <I_BLOCK: ".BLOCK"> } // T prefix for Token TOKEN : { <T_REGISTER