public YuToken RBrace() { YuToken ret = this.CurrToken; this.Match(ETokenType.RBrace); return(ret); }
public YuToken Def() { YuToken ret = this.CurrToken; this.Match(ETokenType.Def); return(ret); }
public YuToken Call() { YuToken ret = this.CurrToken; this.Match(ETokenType.Call); return(ret); }
public YuToken Symbol() { YuToken ret = this.CurrToken; this.Match(ETokenType.Symbol); return(ret); }
public YuToken Equal() { YuToken ret = this.CurrToken; this.Match(ETokenType.Equal); return(ret); }
public YuToken Var() { YuToken ret = this.CurrToken; this.Match(ETokenType.Var); return(ret); }
public YuToken ExpAdd() { YuToken ret = this.CurrToken; this.Match(ETokenType.ExpAdd); return(ret); }
public YuToken SemiColon() { YuToken ret = this.CurrToken; this.Match(ETokenType.SemiColon); return(ret); }
public YuSymbolTableRow(ESymbolType stype, YuToken token) { this.SymbolType = stype; this.SymbolToken = token; this.ProcTree = null; this.AbsoluteAddr = -1; }
public YuToken Number() { YuToken ret = this.CurrToken; this.Match(ETokenType.Number); return(ret); }
public YuSymbolTableRow(ESymbolType stype, YuToken token, YuTreeNode tree) { this.SymbolType = stype; this.SymbolToken = token; this.ProcTree = tree; this.AbsoluteAddr = -1; }
public YuTreeNode ExpStat() { YuToken a = this.Term(); YuToken exp = null; YuToken b = null; YuTreeNode ret = null; while (this.CurrToken.Type != ETokenType.SemiColon && this.CurrToken.Type != ETokenType.Eof) { exp = this.ExpAdd(); b = this.Term(); if (ret == null) { ret = new YuTreeNode(exp); ret.Children.Add(new YuTreeNode(a)); ret.Children.Add(new YuTreeNode(b)); } else { YuTreeNode tmp = new YuTreeNode(exp); tmp.Children.Add(ret); tmp.Children.Add(new YuTreeNode(b)); ret = tmp; } } this.SemiColon(); if (exp == null) { ret = new YuTreeNode(a); } return(ret); }
public YuToken RParen() { YuToken ret = this.CurrToken; this.Match(ETokenType.RParen); return(ret); }
public YuToken Let() { YuToken ret = this.CurrToken; this.Match(ETokenType.Let); return(ret); }
/* * public YuTreeNode CalcStat() * { * YuToken a = this.Number(); * YuToken b = this.ExpAdd(); * YuToken c = this.Number(); * this.SemiColon(); * * YuTreeNode ret = new YuTreeNode(b); * ret.Children.Add(new YuTreeNode(a)); * ret.Children.Add(new YuTreeNode(c)); * * return ret; * } * * public YuTreeNode VCalcStat() * { * YuToken a = this.Symbol(); * YuToken b = this.ExpAdd(); * YuToken c = this.Number(); * this.SemiColon(); * * YuTreeNode ret = new YuTreeNode(b); * ret.Children.Add(new YuTreeNode(a)); * ret.Children.Add(new YuTreeNode(c)); * * return ret; * } */ public YuTreeNode VarDefStat() { YuToken a = this.Var(); YuToken b = this.Symbol(); this.SemiColon(); YuTreeNode ret = new YuTreeNode(a); ret.Children.Add(new YuTreeNode(b)); return(ret); }
public YuToken Term() { YuToken ret = this.CurrToken; if (ret.Type == ETokenType.Number) { this.Match(ETokenType.Number); } else { this.Match(ETokenType.Symbol); } return(ret); }
public YuTreeNode CallStat() { YuToken a = this.Call(); YuToken b = this.Symbol(); this.LParen(); this.RParen(); this.SemiColon(); YuTreeNode ret = new YuTreeNode(a); ret.Children.Add(new YuTreeNode(b)); return(ret); }
public YuTreeNode ProcDefStat() { YuToken a = this.Def(); YuToken b = this.Symbol(); YuTreeNode ret = new YuTreeNode(a); ret.Children.Add(new YuTreeNode(b)); this.LBrace(); while (this.CurrToken.Type != ETokenType.RBrace && this.CurrToken.Type != ETokenType.Eof) { ret.Children.Add(this.Statement()); } this.RBrace(); return(ret); }
public YuTreeNode AssignStat() { this.Let(); YuToken a = this.Symbol(); YuToken b = this.Equal(); YuTreeNode n = this.ExpStat(); /* * if (this.CurrToken.Type == ETokenType.Number) * n = this.CalcStat(); * else * n = this.VCalcStat(); */ YuTreeNode ret = new YuTreeNode(b); ret.Children.Add(new YuTreeNode(a)); ret.Children.Add(n); return(ret); }
public YuTreeNode(YuToken t) : base(t) { this.Children = new List <YuTreeNode>(); }
public YuTreeLeaf(YuToken t) { this.Token = t; }
public override YuToken NextToken() { while (this.Idx < this.Src.Length) { switch (this.Src[this.Idx]) { case ' ': case '\t': case '\r': case '\n': WhiteSpace(); continue; case '+': this.Consume(); return(new YuToken(ETokenType.ExpAdd, "+")); case ';': this.Consume(); return(new YuToken(ETokenType.SemiColon, ";")); case '=': this.Consume(); return(new YuToken(ETokenType.Equal, "=")); case '{': this.Consume(); return(new YuToken(ETokenType.LBrace, "{")); case '}': this.Consume(); return(new YuToken(ETokenType.RBrace, "}")); case '(': this.Consume(); return(new YuToken(ETokenType.LParen, "(")); case ')': this.Consume(); return(new YuToken(ETokenType.RParen, ")")); default: if (this.IsNumeric()) { return(this.Number()); } if (this.IsLetter()) { YuToken token = this.Symbol(); if (token.Text.ToUpper().Equals("VAR")) { token = new YuToken(ETokenType.Var, token.Text); } else if (token.Text.ToUpper().Equals("LET")) { token = new YuToken(ETokenType.Let, token.Text); } else if (token.Text.ToUpper().Equals("DEF")) { token = new YuToken(ETokenType.Def, token.Text); } else if (token.Text.ToUpper().Equals("CALL")) { token = new YuToken(ETokenType.Call, token.Text); } return(token); } throw new YuUnKnownTokenException(); } } return(new YuToken(ETokenType.Eof, "<EOF>")); }
public Parser(Lexer lex) { this.Lex = lex; this.CurrToken = this.Lex.NextToken(); }
/// <summary> /// トークンを消費する /// </summary> public void Consume() { this.CurrToken = this.Lex.NextToken(); }