This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = readLn >>= putStrLn . leapYear | |
where | |
leapYear :: Int -> String | |
leapYear year | year `mod` 400 == 0 = "YES" | |
| year `mod` 100 == 0 = "NO" | |
| year `mod` 4 == 0 = "YES" | |
| otherwise = "NO" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = do | |
cs <- getContents | |
putStrLn $ leapYear $ read cs | |
where | |
leapYear :: Int -> String | |
leapYear year | year `mod` 400 == 0 = "YES" | |
| year `mod` 100 == 0 = "NO" | |
| year `mod` 4 == 0 = "YES" | |
| otherwise = "NO" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Scheme 手習い 5章 p.83 | |
-- The Little Schemer Section 5 | |
rember_star :: (Eq a, Eq b) => a -> [b] -> [b] | |
rember_star _ [] = [] | |
rember_star e (x:xs) = | |
case x of | |
ys@(_:_) -> (rember_star e ys) : (rember_star e xs) | |
z | e == z -> rember_star e xs | |
_ -> x : rember_star e xs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PARSER_BEGIN (Parser) | |
public class Parser { | |
} | |
PARSER_END (Parser) | |
SKIP: { | |
" " | |
} | |
TOKEN: { | |
<INTEGER: (["0"-"9"])+> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PARSER_BEGIN (Parser) | |
public class Parser { | |
} | |
PARSER_END (Parser) | |
SKIP: { | |
" " | |
} | |
TOKEN: { | |
<INTEGER: (["0"-"9"])+> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PARSER_BEGIN (Parser) | |
public class Parser { | |
} | |
PARSER_END (Parser) | |
SKIP: { | |
" " | |
} | |
TOKEN: { | |
<INTEGER: (["0"-"9"])+> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PARSER_BEGIN (Parser) | |
public class Parser { | |
} | |
PARSER_END (Parser) | |
SKIP: { | |
" " | |
} | |
TOKEN: { | |
<INTEGER: (["0"-"9"])+> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PARSER_BEGIN (Parser) | |
public class Parser { | |
} | |
PARSER_END (Parser) | |
SKIP: { | |
" " | |
} | |
TOKEN: { | |
<INTEGER: (["0"-"9"])+> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PARSER_BEGIN (Parser) | |
public class Parser { | |
} | |
PARSER_END (Parser) | |
SKIP: { | |
" " | |
} | |
TOKEN: { | |
<HELLO: "Hello World."> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main (String[] args) { | |
try { | |
Parser parser = new Parser(System.in); | |
parser.List(); | |
} catch (TokenMgrError ex) { | |
System.out.println("字句解析エラー:" + ex.getMessage()); | |
} catch (ParseException ex) { | |
System.out.println("構文解析エラー:" + ex.getMessage()); | |
} |