コード例 #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;
 }
コード例 #4
0
 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
ファイル: ZeroOrOne.cs プロジェクト: ArsenShnurkov/csharpcc
		public ZeroOrOne(Token token, Expansion expansion) {
			Line = token.beginLine;
			Column = token.beginColumn;
			Expansion = expansion;
		}
コード例 #6
0
ファイル: ROneOrMore.cs プロジェクト: ArsenShnurkov/csharpcc
		public ROneOrMore(Token token, RegularExpression expression) {
			Column = token.beginColumn;
			Line = token.beginLine;
			RegularExpression = expression;
		}
コード例 #7
0
 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;
 }
コード例 #8
0
 public static void reInit()
 {
     add_cu_token_here = CSharpCCGlobals.cu_to_insertion_point_1;
     first_cu_token = null;
     insertionpoint1set = false;
     insertionpoint2set = false;
     nextFreeLexState = 1;
 }
コード例 #9
0
 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
ファイル: Choice.cs プロジェクト: ArsenShnurkov/csharpcc
		public Choice(Token token) {
			Line = token.beginLine;
			Column = token.beginColumn;
		}
コード例 #16
0
 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];
     }
 }
コード例 #17
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;
 }
コード例 #19
0
        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;
 }
コード例 #21
0
 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);
 }
コード例 #23
0
 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);
 }
コード例 #25
0
 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
ファイル: RZeroOrMore.cs プロジェクト: ArsenShnurkov/csharpcc
		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
ファイル: OneOrMore.cs プロジェクト: ArsenShnurkov/csharpcc
		public OneOrMore(Token token, Expansion expansion) {
			Column = token.beginColumn;
			Line = token.beginLine;
			Expansion = expansion;
			Expansion.Parent = this;
		}
コード例 #29
0
ファイル: ZeroOrMore.cs プロジェクト: ArsenShnurkov/csharpcc
		public ZeroOrMore(Token token, Expansion expansion) {
			Line = token.beginLine;
			Column = token.beginColumn;
			Expansion = expansion;
			Expansion.Parent = this;
		}
コード例 #30
0
ファイル: Sequence.cs プロジェクト: ArsenShnurkov/csharpcc
		public Sequence(Token token, Lookahead la) {
			Line = token.beginLine;
			Column = token.beginColumn;
			Units.Add(la);
		}