private SignatureAST Signature() { Eat(TokenType.SIGN); StringToken typeNameToken = Eat(TokenType.ID) as StringToken; WordAST typeName = new WordAST(typeNameToken); Eat(TokenType.LPAR); RoutePortAST inPortAST; if (currentToken.Type != TokenType.SEMIC) { inPortAST = RoutePorts(); } else { inPortAST = new RoutePortAST(new List <WordAST>()); } Eat(TokenType.SEMIC); RoutePortAST outPortAST; if (currentToken.Type != TokenType.RPAR) { outPortAST = RoutePorts(); } else { outPortAST = new RoutePortAST(new List <WordAST>()); } Eat(TokenType.RPAR); Eat(TokenType.SEMIC); return(new SignatureAST(typeName, inPortAST, outPortAST)); }
private KeyValuePairAST BlockParameter() { StringToken keyToken = Eat(TokenType.ID) as StringToken; WordAST keyAST = new WordAST(keyToken); Eat(TokenType.COLON); AST valueAST = Block(); return(new KeyValuePairAST(keyAST, valueAST)); }
private ImportAST Import() { Eat(TokenType.IMPORT); List <WordAST> fileName = new List <WordAST>(); List <WordAST> symbols = new List <WordAST>(); bool relative = false; if (currentToken.Type == TokenType.DOT) { relative = true; Eat(TokenType.DOT); while (currentToken.Type == TokenType.DOT) { StringToken token = new StringToken(TokenType.ID, "..", currentToken.Line, currentToken.Column, file); Eat(TokenType.DOT); fileName.Add(new WordAST(token)); } } while (true) { StringToken moduleToken = Eat(TokenType.ID) as StringToken; WordAST moduleName = new WordAST(moduleToken); fileName.Add(moduleName); if (currentToken.Type != TokenType.DOT) { break; } else { Eat(TokenType.DOT); } } if (currentToken.Type == TokenType.COLON) { Eat(TokenType.COLON); while (true) { StringToken moduleToken = Eat(TokenType.ID) as StringToken; WordAST symbol = new WordAST(moduleToken); symbols.Add(symbol); if (currentToken.Type != TokenType.COMMA) { break; } else { Eat(TokenType.COMMA); } } } Eat(TokenType.SEMIC); return(new ImportAST(fileName, relative, symbols)); }
private FromOpAST Define() { Eat(TokenType.ASSIGN); StringToken idToken = Eat(TokenType.ID) as StringToken; WordAST wordAST = new WordAST(idToken); Eat(TokenType.FROM); AST valueExprAST = ValueExpr(); Eat(TokenType.SEMIC); return(new FromOpAST(wordAST, valueExprAST)); }
private AST Inherit() { StringToken nameToken = Eat(TokenType.ID) as StringToken; AST definitionAST = new WordAST(nameToken); if (currentToken.Type == TokenType.COLON) { Eat(TokenType.COLON); StringToken typeToken = Eat(TokenType.ID) as StringToken; WordAST typeAST = new WordAST(typeToken); definitionAST = new InheritAST(definitionAST as WordAST, typeAST); } return(definitionAST); }
private PortAST Port() { StringToken portIdToken = Eat(TokenType.ID) as StringToken; WordAST portIdAST = new WordAST(portIdToken); WordAST portNameAST = null; if (currentToken.Type == TokenType.LBRK) { Eat(TokenType.LBRK); StringToken portNameToken = Eat(TokenType.ID) as StringToken; portNameAST = new WordAST(portNameToken); Eat(TokenType.RBRK); } return(new PortAST(portIdAST, portNameAST)); }
private AST Declare() { AST pointerAST = Pointer(); if (currentToken.Type == TokenType.LBRK) { Eat(TokenType.LBRK); StringToken idToken = Eat(TokenType.ID) as StringToken; WordAST wordAST = new WordAST(idToken); Eat(TokenType.RBRK); return(new DeclareAST(pointerAST, wordAST)); } else { return(pointerAST); } }
private KeyValuePairAST Parameter() { StringToken keyToken = Eat(TokenType.ID) as StringToken; WordAST keyAST = new WordAST(keyToken); Eat(TokenType.COLON); if (currentToken.Type == TokenType.STRING) { StringToken valueToken = Eat(TokenType.STRING) as StringToken; StringAST valueAST = new StringAST(valueToken); return(new KeyValuePairAST(keyAST, valueAST)); } else { AST valueAST = ValueExpr(); return(new KeyValuePairAST(keyAST, valueAST)); } }
private ConfAST ProgramConfig(bool nested = false) { if (!nested) { Eat(TokenType.CONF); } StringToken idToken = Eat(TokenType.ID) as StringToken; WordAST wordAST = new WordAST(idToken); AST valueAST; if (currentToken.Type == TokenType.FROM) { Eat(TokenType.FROM); if (currentToken.Type == TokenType.TRUE || currentToken.Type == TokenType.FALSE) { BoolToken valueToken = Eat(currentToken.Type) as BoolToken; valueAST = new BoolAST(valueToken); } else if (currentToken.Type == TokenType.STRING) { StringToken valueToken = Eat(TokenType.STRING) as StringToken; valueAST = new StringAST(valueToken); } else { valueAST = ValueExpr(); } Eat(TokenType.SEMIC); } else if (currentToken.Type == TokenType.DOT) { Eat(TokenType.DOT); valueAST = ProgramConfig(true); } else { Eat(TokenType.COLON); valueAST = ConfList(); Eat(TokenType.END); } return(new ConfAST(wordAST, valueAST, nested)); }
private UsingAST Using() { Eat(TokenType.USING); List <WordAST> fileName = new List <WordAST>(); WordAST moduleName = null; bool relative = false; if (currentToken.Type == TokenType.DOT) { relative = true; Eat(TokenType.DOT); while (currentToken.Type == TokenType.DOT) { StringToken token = new StringToken(TokenType.ID, "..", currentToken.Line, currentToken.Column, file); Eat(TokenType.DOT); fileName.Add(new WordAST(token)); } } while (true) { StringToken moduleToken = Eat(TokenType.ID) as StringToken; fileName.Add(new WordAST(moduleToken)); if (currentToken.Type != TokenType.DOT) { break; } else { Eat(TokenType.DOT); } } if (currentToken.Type == TokenType.COLON) { Eat(TokenType.COLON); StringToken moduleToken = Eat(TokenType.ID) as StringToken; moduleName = new WordAST(moduleToken); } Eat(TokenType.SEMIC); return(new UsingAST(fileName, moduleName, relative)); }
private RouteParamAST RouteParameter() { StringToken nameToken = Eat(TokenType.ID) as StringToken; StringToken typeToken = null; if (currentToken.Type == TokenType.COLON) { Eat(TokenType.COLON); typeToken = Eat(TokenType.ID) as StringToken; } WordAST nameAST = new WordAST(nameToken); WordAST typeAST = new WordAST(typeToken); if (currentToken.Type == TokenType.FROM) { Eat(TokenType.FROM); return(new RouteParamAST(nameAST, typeAST, ValueExpr())); } else { return(new RouteParamAST(nameAST, typeAST)); } }
private RouteInPortAST RouteInPorts() { List <AST> ports = new List <AST>(); while (true) { StringToken portNameToken = Eat(TokenType.ID) as StringToken; var name = new WordAST(portNameToken); if (currentToken.Type == TokenType.QUE) { Eat(TokenType.QUE); if (currentToken.Type != TokenType.COMMA && currentToken.Type != TokenType.SEMIC) { var value = ValueExpr(); ports.Add(new RouteNullablePortAST(name, value)); } else { ports.Add(new RouteNullablePortAST(name, null)); } } else { ports.Add(name); } if (currentToken.Type != TokenType.COMMA) { break; } else { Eat(TokenType.COMMA); } } return(new RouteInPortAST(ports)); }
public PortAST(WordAST portID, WordAST portName) { PortId = portID; PortName = portName; }
private string Visit(WordAST wordAST) { return(wordAST.Word); }