vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame^] | 1 | options { |
| 2 | |
| 3 | |
| 4 | STATIC = false; |
| 5 | |
| 6 | } |
| 7 | |
| 8 | PARSER_BEGIN(AdmLexer) |
| 9 | |
| 10 | package edu.uci.ics.asterix.adm.parser; |
| 11 | |
| 12 | import java.io.*; |
| 13 | |
| 14 | public class AdmLexer { |
| 15 | |
| 16 | public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException { |
| 17 | File file = new File(args[0]); |
| 18 | Reader freader = new BufferedReader(new InputStreamReader |
| 19 | (new FileInputStream(file), "UTF-8")); |
| 20 | AdmLexer flexer = new AdmLexer(freader); |
| 21 | Token t = null; |
| 22 | do { |
| 23 | t = flexer.next(); |
| 24 | System.out.println(AdmLexerConstants.tokenImage[t.kind]); |
| 25 | } while (t.kind != EOF); |
| 26 | freader.close(); |
| 27 | } |
| 28 | |
| 29 | public Token next() throws ParseException { |
| 30 | return getNextToken(); |
| 31 | } |
| 32 | |
| 33 | public String tokenKindToString(int tokenKind) { |
| 34 | return AdmLexerConstants.tokenImage[tokenKind]; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | PARSER_END(AdmLexer) |
| 39 | |
| 40 | <DEFAULT> |
| 41 | TOKEN : |
| 42 | { |
| 43 | <NULL_LITERAL : "null"> |
| 44 | } |
| 45 | |
| 46 | <DEFAULT> |
| 47 | TOKEN : |
| 48 | { |
| 49 | <TRUE_LITERAL : "true"> |
| 50 | } |
| 51 | |
| 52 | <DEFAULT> |
| 53 | TOKEN : |
| 54 | { |
| 55 | <FALSE_LITERAL : "false"> |
| 56 | } |
| 57 | |
| 58 | |
| 59 | <DEFAULT> |
| 60 | TOKEN : |
| 61 | { |
| 62 | <INTEGER_LITERAL : ("-")? (<DIGIT>)+ > |
| 63 | } |
| 64 | |
| 65 | |
| 66 | <DEFAULT> |
| 67 | TOKEN : |
| 68 | { |
| 69 | <#DIGIT : ["0" - "9"]> |
| 70 | } |
| 71 | |
| 72 | |
| 73 | TOKEN: |
| 74 | { |
| 75 | < DOUBLE_LITERAL: |
| 76 | ("-")? <INTEGER> ( "." <INTEGER> )? (<EXPONENT>)? |
| 77 | | ("-")? "." <INTEGER> |
| 78 | > |
| 79 | | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > |
| 80 | | <INTEGER : (<DIGIT>)+ > |
| 81 | | <FLOAT_LITERAL: <DOUBLE_LITERAL>("f"|"F")> |
| 82 | } |
| 83 | |
| 84 | <DEFAULT> |
| 85 | TOKEN : |
| 86 | { |
| 87 | <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") > |
| 88 | | |
| 89 | < #EscapeQuot: "\\\"" > |
| 90 | } |
| 91 | |
| 92 | <DEFAULT> |
| 93 | TOKEN : |
| 94 | { |
| 95 | <START_RECORD : "{"> |
| 96 | } |
| 97 | |
| 98 | <DEFAULT> |
| 99 | TOKEN : |
| 100 | { |
| 101 | <END_RECORD : "}"> |
| 102 | } |
| 103 | |
| 104 | <DEFAULT> |
| 105 | TOKEN : |
| 106 | { |
| 107 | <COMMA : ","> |
| 108 | } |
| 109 | |
| 110 | <DEFAULT> |
| 111 | TOKEN : |
| 112 | { |
| 113 | <COLON : ":"> |
| 114 | } |
| 115 | |
| 116 | |
| 117 | <DEFAULT> |
| 118 | TOKEN : |
| 119 | { |
| 120 | <START_ORDERED_LIST : "["> |
| 121 | } |
| 122 | |
| 123 | <DEFAULT> |
| 124 | TOKEN : |
| 125 | { |
| 126 | <END_ORDERED_LIST : "]"> |
| 127 | } |
| 128 | |
| 129 | <DEFAULT> |
| 130 | TOKEN : |
| 131 | { |
| 132 | <START_UNORDERED_LIST : "{{"> |
| 133 | } |
| 134 | |
| 135 | <DEFAULT> |
| 136 | TOKEN : |
| 137 | { |
| 138 | <END_UNORDERED_LIST : "}}"> |
| 139 | } |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | SKIP: |
| 145 | { |
| 146 | " " |
| 147 | | "\t" |
| 148 | | "\r" |
| 149 | | "\n" |
| 150 | } |