public stmt ParseWord() { string word = CurrentToken.Value as string; if (typeTable.IsType (word)) { type Type = typeTable.get (word); Next (); if (CurrentToken.Type == TokenType.star) { Next (); string name = CurrentToken.Value as string; symbol sym = new symbol () { Name = name, Type = Type, isPointer = true }; Next (); Next (); assign_pointer a = new assign_pointer (); a.Name = sym; a.Value = ParseExpr (); symbolTable.Add (sym); return a; } else if (CurrentToken.Type == TokenType.word) { string Name = CurrentToken.Value as string; symbol sym = new symbol () { Type = Type, Name = Name }; Next (); if (CurrentToken.Type == TokenType.openparan) { function_definition fdef = new function_definition (); fdef.Symbol = sym; Next (); fdef.Args = ParseArgs (); Next (); fdef.Body = ParseBlock (); sym.isFunc = true; symbolTable.Add (sym); return fdef; } else if (CurrentToken.Type == TokenType.symbol && ((char)CurrentToken.Value).Equals ('=')) { Next (); assign a = new assign (); a.Name = sym; a.Value = ParseExpr (); symbolTable.Add (sym); return a; } } } else if (symbolTable.IsSymbol (word)) { symbol sym = symbolTable.get (word); Next (); if (CurrentToken.Type == TokenType.symbol && ((char)CurrentToken.Value).Equals('=')) { Next (); assign a = new assign (); a.Name = sym; a.Value = ParseExpr (); return a; } } else if (word.Equals ("ret")) { Next (); ret r = new ret (); r.Value = ParseExpr (); return r; } throw new ParseException ("Unknown word: " + CurrentToken.ToString()); }
public void Add(symbol Symbol) { symbolTable.Add (Symbol); }
public args ParseArgs() { List<symbol> symbols = new List<symbol>(); while (CurrentToken.Type != TokenType.closeparan) { if (CurrentToken.Type == TokenType.comma) Next (); symbol s = new symbol (); string typename = CurrentToken.Value as string; if (typeTable.IsType (typename)) s.Type = typeTable.get (typename); else throw new Exception (typename + " is not a type"); Next (); s.Name = CurrentToken.Value as string; Next (); symbols.Add (s); } args Args = new args () { symbols = symbols.ToArray() }; return Args; }