示例#1
0
 /** Constructor with generated Token Manager. */
 public SimpleParser(SimpleParserTokenManager tm)
 {
     tokenSource = tm;
     token = new Token();
     cc_ntKind = -1;
     cc_gen = 0;
     for (int i = 0; i < 0; i++) cc_la1[i] = -1;
 }
示例#2
0
 /// Constructor.
 public SimpleParser(System.IO.TextReader reader)
 {
     cc_inputStream = new SimpleCharStream(reader, 1, 1);
     tokenSource = new SimpleParserTokenManager(cc_inputStream);
     token = new Token();
     cc_ntKind = -1;
     cc_gen = 0;
     for (int i = 0; i < 0; i++) cc_la1[i] = -1;
 }
示例#3
0
 /// Constructor with Stream and supplied encoding
 public SimpleParser(System.IO.Stream stream, System.Text.Encoding encoding)
 {
     cc_inputStream = new SimpleCharStream(stream, encoding, 1, 1);
     tokenSource = new SimpleParserTokenManager(cc_inputStream);
     token = new Token();
     cc_ntKind = -1;
     cc_gen = 0;
     for (int i = 0; i < 0; i++) cc_la1[i] = -1;
 }
 public static void add_token_manager_decls(Token t, IList<Token> decls)
 {
     if (CSharpCCGlobals.token_mgr_decls != null) {
         CSharpCCErrors.ParseError(t, "Multiple occurrence of \"TOKEN_MGR_DECLS\".");
     } else {
         CSharpCCGlobals.token_mgr_decls = decls;
         if (Options.getUserTokenManager()) {
             CSharpCCErrors.Warning(t, "Ignoring declarations in \"TOKEN_MGR_DECLS\" since option " +
                                       "USER_TOKEN_MANAGER has been set to true.");
         }
     }
 }
示例#5
0
		public ZeroOrOne(Token token, Expansion expansion) {
			Line = token.beginLine;
			Column = token.beginColumn;
			Expansion = expansion;
		}
示例#6
0
		public ROneOrMore(Token token, RegularExpression expression) {
			Column = token.beginColumn;
			Line = token.beginLine;
			RegularExpression = expression;
		}
 public static void setinsertionpoint(Token t, int no)
 {
     do {
         add_cu_token_here.Add(first_cu_token);
         first_cu_token = first_cu_token.next;
     } while (first_cu_token != t);
     if (no == 1) {
         if (insertionpoint1set) {
             CSharpCCErrors.ParseError(t, "Multiple declaration of parser class.");
         } else {
             insertionpoint1set = true;
             add_cu_token_here = CSharpCCGlobals.cu_to_insertion_point_2;
         }
     } else {
         add_cu_token_here = CSharpCCGlobals.cu_from_insertion_point_2;
         insertionpoint2set = true;
     }
     first_cu_token = t;
 }
 public static void reInit()
 {
     add_cu_token_here = CSharpCCGlobals.cu_to_insertion_point_1;
     first_cu_token = null;
     insertionpoint1set = false;
     insertionpoint2set = false;
     nextFreeLexState = 1;
 }
 public static void insertionpointerrors(Token t)
 {
     while (first_cu_token != t) {
         add_cu_token_here.Add(first_cu_token);
         first_cu_token = first_cu_token.next;
     }
     if (!insertionpoint1set || !insertionpoint2set) {
         CSharpCCErrors.ParseError(t, "Parser class has not been defined between PARSER_BEGIN and PARSER_END.");
     }
 }
示例#10
0
 internal static void PrintTokenOnly(Token t, TextWriter ostr)
 {
     for (; cline < t.beginLine; cline++) {
         ostr.WriteLine("");
         ccol = 1;
     }
     for (; ccol < t.beginColumn; ccol++) {
         ostr.Write(" ");
     }
     if (t.kind == CSharpCCParserConstants.STRING_LITERAL ||
         t.kind == CSharpCCParserConstants.CHARACTER_LITERAL)
         ostr.Write(AddUnicodeEscapes(t.image));
     else
         ostr.Write(t.image);
     cline = t.endLine;
     ccol = t.endColumn + 1;
     char last = t.image[t.image.Length - 1];
     if (last == '\n' || last == '\r') {
         cline++;
         ccol = 1;
     }
 }
示例#11
0
 internal static String PrintToken(Token t)
 {
     String retval = "";
     Token tt = t.specialToken;
     if (tt != null) {
         while (tt.specialToken != null)
             tt = tt.specialToken;
         while (tt != null) {
             retval += PrintTokenOnly(tt);
             tt = tt.next;
         }
     }
     retval += PrintTokenOnly(t);
     return retval;
 }
示例#12
0
 internal static void PrintToken(Token t, TextWriter ostr)
 {
     Token tt = t.specialToken;
     if (tt != null) {
         while (tt.specialToken != null)
             tt = tt.specialToken;
         while (tt != null) {
             PrintTokenOnly(tt, ostr);
             tt = tt.next;
         }
     }
     PrintTokenOnly(t, ostr);
 }
示例#13
0
 internal static String PrintLeadingComments(Token t)
 {
     String retval = "";
     if (t.specialToken == null)
         return retval;
     Token tt = t.specialToken;
     while (tt.specialToken != null)
         tt = tt.specialToken;
     while (tt != null) {
         retval += PrintTokenOnly(tt);
         tt = tt.next;
     }
     if (ccol != 1 && cline != t.beginLine) {
         retval += "\n";
         cline++;
         ccol = 1;
     }
     return retval;
 }
示例#14
0
 internal static void PrintLeadingComments(Token t, TextWriter ostr)
 {
     if (t.specialToken == null)
         return;
     Token tt = t.specialToken;
     while (tt.specialToken != null)
         tt = tt.specialToken;
     while (tt != null) {
         PrintTokenOnly(tt, ostr);
         tt = tt.next;
     }
     if (ccol != 1 && cline != t.beginLine) {
         ostr.WriteLine("");
         cline++;
         ccol = 1;
     }
 }
示例#15
0
		public Choice(Token token) {
			Line = token.beginLine;
			Column = token.beginColumn;
		}
 public static char character_descriptor_assign(Token t, String s, String left)
 {
     if (s.Length != 1) {
         CSharpCCErrors.ParseError(t, "String in character list may contain only one character.");
         return ' ';
     } else if ((int) (left[0]) > (int) (s[0])) {
         CSharpCCErrors.ParseError(t, "Right end of character range \'" + s +
                                      "\' has a lower ordinal value than the left end of character range \'" + left + "\'.");
         return left[0];
     } else {
         return s[0];
     }
 }
 public static void compare(Token t, String id1, String id2)
 {
     if (!id2.Equals(id1)) {
         CSharpCCErrors.ParseError(t, "Name " + id2 + " must be the same as that used at PARSER_BEGIN (" + id1 + ")");
     }
 }
示例#18
0
 internal static string PrintTokenOnly(Token t)
 {
     String retval = "";
     for (; cline < t.beginLine; cline++) {
         retval += "\n";
         ccol = 1;
     }
     for (; ccol < t.beginColumn; ccol++) {
         retval += " ";
     }
     if (t.kind == CSharpCCParserConstants.STRING_LITERAL ||
         t.kind == CSharpCCParserConstants.CHARACTER_LITERAL)
         retval += AddUnicodeEscapes(t.image);
     else
         retval += t.image;
     cline = t.endLine;
     ccol = t.endColumn + 1;
     char last = t.image[t.image.Length - 1];
     if (last == '\n' || last == '\r') {
         cline++;
         ccol = 1;
     }
     return retval;
 }
        public static void makeTryBlock(
			Token tryLoc,
			Container result,
			Container nestedExp,
			IList<IList<Token>> types,
			IList<Token> ids,
			IList<IList<Token>> catchblks,
			IList<Token> finallyblk
			)
        {
            if (catchblks.Count == 0 && finallyblk == null) {
                CSharpCCErrors.ParseError(tryLoc, "Try block must contain at least one catch or finally block.");
                return;
            }
            TryBlock tblk = new TryBlock();
            tblk.Line = tryLoc.beginLine;
            tblk.Column = tryLoc.beginColumn;
            tblk.Expansion = (Expansion) (nestedExp.member);
            tblk.Expansion.Parent = tblk;
            tblk.Expansion.Ordinal = 0;
            tblk.Types = types;
            tblk.Ids = ids;
            tblk.CatchBlocks = catchblks;
            tblk.FinallyBlocks = finallyblk;
            result.member = tblk;
        }
示例#20
0
 internal static void PrintTokenSetup(Token t)
 {
     Token tt = t;
     while (tt.specialToken != null)
         tt = tt.specialToken;
     cline = tt.beginLine;
     ccol = tt.beginColumn;
 }
 public static String remove_escapes_and_quotes(Token t, String str)
 {
     String retval = "";
     int index = 1;
     char ch, ch1;
     int ordinal;
     while (index < str.Length - 1) {
         if (str[index] != '\\') {
             retval += str[index];
             index++;
             continue;
         }
         index++;
         ch = str[index];
         if (ch == 'b') {
             retval += '\b';
             index++;
             continue;
         }
         if (ch == 't') {
             retval += '\t';
             index++;
             continue;
         }
         if (ch == 'n') {
             retval += '\n';
             index++;
             continue;
         }
         if (ch == 'f') {
             retval += '\f';
             index++;
             continue;
         }
         if (ch == 'r') {
             retval += '\r';
             index++;
             continue;
         }
         if (ch == '"') {
             retval += '\"';
             index++;
             continue;
         }
         if (ch == '\'') {
             retval += '\'';
             index++;
             continue;
         }
         if (ch == '\\') {
             retval += '\\';
             index++;
             continue;
         }
         if (ch >= '0' && ch <= '7') {
             ordinal = ((int) ch) - ((int) '0');
             index++;
             ch1 = str[index];
             if (ch1 >= '0' && ch1 <= '7') {
                 ordinal = ordinal*8 + ((int) ch1) - ((int) '0');
                 index++;
                 ch1 = str[index];
                 if (ch <= '3' && ch1 >= '0' && ch1 <= '7') {
                     ordinal = ordinal*8 + ((int) ch1) - ((int) '0');
                     index++;
                 }
             }
             retval += (char) ordinal;
             continue;
         }
         if (ch == 'u') {
             index++;
             ch = str[index];
             if (hexchar(ch)) {
                 ordinal = hexval(ch);
                 index++;
                 ch = str[index];
                 if (hexchar(ch)) {
                     ordinal = ordinal*16 + hexval(ch);
                     index++;
                     ch = str[index];
                     if (hexchar(ch)) {
                         ordinal = ordinal*16 + hexval(ch);
                         index++;
                         ch = str[index];
                         if (hexchar(ch)) {
                             ordinal = ordinal*16 + hexval(ch);
                             index++;
                             continue;
                         }
                     }
                 }
             }
             CSharpCCErrors.ParseError(t, "Encountered non-hex character '" + ch +
                                          "' at position " + index + " of string " +
                                          "- Unicode escape must have 4 hex digits after it.");
             return retval;
         }
         CSharpCCErrors.ParseError(t, "Illegal escape sequence '\\" + ch +
                                      "' at position " + index + " of string.");
         return retval;
     }
     return retval;
 }
示例#22
0
 internal static void PrintTrailingComments(Token t, TextWriter ostr)
 {
     if (t.next == null)
         return;
     PrintLeadingComments(t.next);
 }
 public static void set_initial_cu_token(Token t)
 {
     first_cu_token = t;
 }
示例#24
0
 internal static String PrintTrailingComments(Token t)
 {
     if (t.next == null)
         return "";
     return PrintLeadingComments(t.next);
 }
 public static char character_descriptor_assign(Token t, String s)
 {
     if (s.Length != 1) {
         CSharpCCErrors.ParseError(t, "String in character list may contain only one character.");
         return ' ';
     } else {
         return s[0];
     }
 }
示例#26
0
		public RZeroOrMore(Token t, RegularExpression r) {
			Column = t.beginColumn;
			Line = t.beginLine;
			RegularExpression = r;
		}
示例#27
0
 public RStringLiteral(Token token, string image)
 {
     Line = token.beginLine;
     Column = token.beginColumn;
     Image = image;
 }
示例#28
0
		public OneOrMore(Token token, Expansion expansion) {
			Column = token.beginColumn;
			Line = token.beginLine;
			Expansion = expansion;
			Expansion.Parent = this;
		}
示例#29
0
		public ZeroOrMore(Token token, Expansion expansion) {
			Line = token.beginLine;
			Column = token.beginColumn;
			Expansion = expansion;
			Expansion.Parent = this;
		}
示例#30
0
		public Sequence(Token token, Lookahead la) {
			Line = token.beginLine;
			Column = token.beginColumn;
			Units.Add(la);
		}