| Copyright | Copyright (C) 2021 Yoo Chung |
|---|---|
| License | GPL-3.0-or-later |
| Maintainer | dev@chungyc.org |
| Safe Haskell | Safe-Inferred |
| Language | GHC2021 |
Problems.P96
Description
Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P96.
Synopsis
- isIdentifier :: String -> Bool
Documentation
isIdentifier :: String -> Bool Source #
Identifiers in the Ada programming language have the syntax described by the diagram below.
Write a function which checks whether a given string is a legal identifier.
Examples
>>>isIdentifier "this_is_a_long_identifier"True
>>>isIdentifier "This_ends_in_an_underscore_"False
>>>isIdentifier "This__has__two__consecutive__underscores"False
>>>isIdentifier "1234"False
>>>isIdentifier "_legal_in_many_other_languages"False
>>>isIdentifier "Fibonacci_sequence_is_1_1_2_3_5_8_13_21_ad_infinitum"True
Hint
Translate the syntax diagram into a recursive grammar.