private Token Symbol() { int startPosition = GetCurrentPositionInInput(); StringBuilder sbuf = new StringBuilder(); // StringBuffer en Java lo hemos modernizado a StringBuilder while (PropositionSymbol.IsPropositionSymbolIdentifierPart(LookAhead(1))) { sbuf.Append(LookAhead(1)); Consume(); } string symbol = sbuf.ToString(); if (PropositionSymbol.IsAlwaysTrueSymbol(symbol)) { return(new Token(LogicTokenTypes.TRUE, PropositionSymbol.TRUE_SYMBOL, startPosition)); } else if (PropositionSymbol.IsAlwaysFalseSymbol(symbol)) { return(new Token(LogicTokenTypes.FALSE, PropositionSymbol.FALSE_SYMBOL, startPosition)); } else if (PropositionSymbol.IsPropositionSymbol(symbol)) { return(new Token(LogicTokenTypes.SYMBOL, sbuf.ToString(), startPosition)); } throw new LexerException("Lexing error on symbol " + symbol + " at position " + GetCurrentPositionInInput(), GetCurrentPositionInInput()); }
// Compara este símbolo de proposición con otro y dice si son iguales public bool Equals(PropositionSymbol sym) { if (sym == null) { return(false); } if (this == sym) { return(true); } return(symbol.Equals(sym.symbol)); // No equivocarse con esto que había: sym.Equals(sym.symbol) }
public void Test_isAlwaysTrueSymbol() { Assert.IsTrue(PropositionSymbol.IsAlwaysTrueSymbol("True")); Assert.IsTrue(PropositionSymbol.IsAlwaysTrueSymbol("tRue")); Assert.IsTrue(PropositionSymbol.IsAlwaysTrueSymbol("trUe")); Assert.IsTrue(PropositionSymbol.IsAlwaysTrueSymbol("truE")); Assert.IsTrue(PropositionSymbol.IsAlwaysTrueSymbol("TRUE")); Assert.IsTrue(PropositionSymbol.IsAlwaysTrueSymbol("true")); // Assert.IsFalse(PropositionSymbol.IsAlwaysTrueSymbol("Tru3")); Assert.IsFalse(PropositionSymbol.IsAlwaysTrueSymbol("True ")); Assert.IsFalse(PropositionSymbol.IsAlwaysTrueSymbol(" True")); }
public void Test_isAlwaysFalseSymbol() { Assert.IsTrue(PropositionSymbol.IsAlwaysFalseSymbol("False")); Assert.IsTrue(PropositionSymbol.IsAlwaysFalseSymbol("fAlse")); Assert.IsTrue(PropositionSymbol.IsAlwaysFalseSymbol("faLse")); Assert.IsTrue(PropositionSymbol.IsAlwaysFalseSymbol("falSe")); Assert.IsTrue(PropositionSymbol.IsAlwaysFalseSymbol("falsE")); Assert.IsTrue(PropositionSymbol.IsAlwaysFalseSymbol("FALSE")); Assert.IsTrue(PropositionSymbol.IsAlwaysFalseSymbol("false")); // Assert.IsFalse(PropositionSymbol.IsAlwaysFalseSymbol("Fals3")); Assert.IsFalse(PropositionSymbol.IsAlwaysFalseSymbol("False ")); Assert.IsFalse(PropositionSymbol.IsAlwaysFalseSymbol(" False")); }
public void Test_isPropositionSymbolDoesNotContainConnectiveChars() { // '~', '&', '|', '=', '<', '>' Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("~")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("&")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("|")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("=")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("<")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol(">")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("A~")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("A&")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("A|")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("A=")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("A<")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("A>")); }
public void Test_isPropositionSymbol() { Assert.IsTrue(PropositionSymbol.IsPropositionSymbol("True")); Assert.IsTrue(PropositionSymbol.IsPropositionSymbol("False")); Assert.IsTrue(PropositionSymbol.IsPropositionSymbol("A")); Assert.IsTrue(PropositionSymbol.IsPropositionSymbol("A1")); Assert.IsTrue(PropositionSymbol.IsPropositionSymbol("A_1")); Assert.IsTrue(PropositionSymbol.IsPropositionSymbol("a")); Assert.IsTrue(PropositionSymbol.IsPropositionSymbol("a1")); Assert.IsTrue(PropositionSymbol.IsPropositionSymbol("A_1")); Assert.IsTrue(PropositionSymbol.IsPropositionSymbol("_")); Assert.IsTrue(PropositionSymbol.IsPropositionSymbol("_1")); Assert.IsTrue(PropositionSymbol.IsPropositionSymbol("_1_2")); // Las comas no se permiten (sólo caracteres que puedan estar en identificadores legales de Java... ahora C#) Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("A1,2")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol(" A")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("A ")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("A B")); // En Java sí se permiten identificadores con el símbolo del dólar... pero en C# no Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("$")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("$1")); Assert.IsFalse(PropositionSymbol.IsPropositionSymbol("$1_1")); }
private bool SymbolDetected(char leadingChar) { return(PropositionSymbol.IsPropositionSymbolIdentifierStart(leadingChar)); }