• R/O
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

N88BASICが簡単に動くインタープリタを目指します。


Commit MetaInfo

Revision16 (tree)
Time2018-09-24 21:23:26
Authorbellyoshi

Log Message

Change Summary

Incremental Difference

--- trunk/csmock/WindowsFormsApp1/getToken/Token.cs (revision 15)
+++ trunk/csmock/WindowsFormsApp1/getToken/Token.cs (revision 16)
@@ -8,13 +8,15 @@
88 {
99 enum TokenType {
1010 int_value,double_value, str_value
11- ,ab_if,ab_else,ab_end_if,ab_then,
12- ab_for,ab_to,ab_step,ab_next,
11+ ,ab_if,ab_else,ab_end,ab_then,
12+ ab_for,ab_to,ab_step,ab_next, ab_exit,
13+ abn88_print, abn88_line,
1314 identifier,
1415 Plus, Minus, Mult, Div,Equal,// +-*/=
1516 Lparen, Rparen,//()
1617 LBrace, RBrace,//{}
1718 Comma, Period,//,.
19+ DoubleQuote,//"
1820 Lss, Gtr,// < >
1921 Letter, Digit, Colon, Others,
2022 EndOfFile
@@ -22,7 +24,6 @@
2224 class Token
2325 {
2426 TokenType tokenType;
25- string value_cs_str;
2627 int src_line;
2728 int src_col;
2829 string src_str;
--- trunk/csmock/WindowsFormsApp1/getToken/TokenGetter.cs (revision 15)
+++ trunk/csmock/WindowsFormsApp1/getToken/TokenGetter.cs (revision 16)
@@ -11,9 +11,39 @@
1111 {
1212 private int src_line;
1313 private int src_col;
14+ private string src_str;
1415
15- TokenType getCharType(char chr)
16+ private Dictionary<string, TokenType> keywordDic;
17+
18+ public TokenGetter()
1619 {
20+ keywordDic = new Dictionary<string, TokenType>();
21+ //予約語
22+ rKWD("if", ab_if);
23+ rKWD("then", ab_then);
24+ rKWD("end",ab_end);
25+ rKWD("next", ab_next);
26+ rKWD("for", ab_for);
27+ rKWD("to", ab_to);
28+ rKWD("step", ab_step);
29+ rKWD("print", abn88_print);
30+ rKWD("line", abn88_line);
31+ curChar = Console.Read();
32+ }
33+ /// <summary>
34+ /// Regist Key Word Dictionary
35+ /// </summary>
36+ void rKWD(string str, TokenType t)
37+ {
38+ keywordDic.Add(str, t);
39+ }
40+ TokenType getCurCharType()
41+ {
42+ return getCharType(curChar);
43+ }
44+ TokenType getCharType(int c)
45+ {
46+ char chr = (char)c;
1747 if (chr >= '0' && chr <= '9')
1848 return Digit;
1949 if ((chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z'))
@@ -34,7 +64,8 @@
3464 case '>': return Gtr;
3565 case ',': return Comma;
3666 case '.': return Period;
37-// case ';': return Semicolon;
67+ case '"': return DoubleQuote;
68+ case ';': return EndOfFile;//test用 Semicolon;
3869 case ':': return Colon;
3970 default:
4071 break;
@@ -44,11 +75,15 @@
4475
4576
4677 }
47- int NextChar()
78+ int curChar = 0;
79+ void NextChar()
4880 {
49- var c = Console.Read();
50- if (c == '\n')
81+
82+ add_char_to_src_str(curChar);
83+ curChar = Console.Read();
84+ if (curChar == '\n')
5185 {
86+
5287 src_line++;
5388 src_col = 0;
5489 }
@@ -56,26 +91,83 @@
5691 {
5792 src_col++;
5893 }
59- return c;
6094 }
61- public Token NextToken()
95+
96+
97+ public TokenType NextTokenType()
6298 {
63- int c = NextChar();
64- while (true)
99+ while (curChar == ' ' || curChar == '\t')
65100 {
66- if (c == ' ' || c == '\t')
67- {
68- ;
69- }
70- else
71- {
72- break;
73- }
74- c = NextChar();
101+ NextChar();
102+ }
103+ src_str = String.Empty;
104+ if (curChar == '\n')
105+ {
106+ src_str = "\\n";
107+ }
108+ if (curChar == '\r')
109+ {
110+ src_str = "\\r";
111+ }
112+ var t = getCurCharType();
113+ NextChar();
114+ switch (t)
115+ {
116+ case Letter:
117+ while (getCurCharType() == Letter || getCurCharType() == Digit)
118+ {
119+ NextChar();
120+ }
121+ foreach (var p in keywordDic)//予約語検索
122+ {
123+ if(string.Compare(p.Key, src_str, true) == 0)
124+ {
125+ return p.Value;
126+ }
127+ }
128+ return identifier;
129+ case Digit:
130+ while(getCurCharType() == Digit)
131+ {
132+ NextChar();
133+ }
134+ if (getCurCharType() != Period)
135+ {
136+ return int_value;
137+ }
138+ else
139+ {
140+ NextChar();
141+ while(getCurCharType() == Digit)
142+ {
143+ NextChar();
144+ }
145+ return double_value;
146+ }
147+ case DoubleQuote:
148+ while(!(
149+ getCurCharType() == DoubleQuote ||
150+ getCurCharType() == EndOfFile))
151+ {
152+ NextChar();
153+ }
154+ if (getCurCharType() == DoubleQuote)
155+ {
156+ NextChar();
157+ }
158+ return str_value;
75159
76160 }
77- var t = getCharType((char)c);
78- return new Token(c.ToString(),src_line,src_col, t);
161+ return t;
79162 }
163+ public Token NextToken()
164+ {
165+ var t = NextTokenType();
166+ return new Token(src_str, src_line, src_col, t);
167+ }
168+ private void add_char_to_src_str(int c)
169+ {
170+ src_str += ((char)c).ToString();
171+ }
80172 }
81173 }
--- trunk/csmock/WindowsFormsApp1/getToken/Utils.cs (nonexistent)
+++ trunk/csmock/WindowsFormsApp1/getToken/Utils.cs (revision 16)
@@ -0,0 +1,12 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using System.Threading.Tasks;
6+
7+namespace getToken
8+{
9+ class Utils
10+ {
11+ }
12+}